aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2024-02-08 23:52:19 +0100
committerGitHub <noreply@github.com>2024-02-08 23:52:19 +0100
commitd478a1c0226b7825a99718bf605ef9727ee4beca (patch)
tree342ef57ec1cd649b7d7d9a8e0d88f98a01d20585
parentb507c8648f701acd1c48b3c38054ad38d76fd1ca (diff)
downloadjquery-d478a1c0226b7825a99718bf605ef9727ee4beca.tar.gz
jquery-d478a1c0226b7825a99718bf605ef9727ee4beca.zip
Tests: Fix Karma tests on Node.js 20
Node.js 20 started throwing errors when `writeHead` is called twice on a response. This might have already been invalid before but it wasn't throwing on Node.js 18. Compute the headers object and call `writeHead` once to avoid the issue. Closes gh-5397
-rw-r--r--test/middleware-mockserver.cjs14
1 files changed, 5 insertions, 9 deletions
diff --git a/test/middleware-mockserver.cjs b/test/middleware-mockserver.cjs
index a7a7a47b9..5fb067627 100644
--- a/test/middleware-mockserver.cjs
+++ b/test/middleware-mockserver.cjs
@@ -80,13 +80,7 @@ const mocks = {
headers[ "access-control-allow-origin" ] = "*";
}
- if ( resp.set ) {
- resp.set( headers );
- } else {
- for ( const key in headers ) {
- resp.writeHead( 200, { [ key ]: headers[ key ] } );
- }
- }
+ resp.writeHead( 200, headers );
if ( req.query.callback ) {
resp.end( `${ cleanCallback( req.query.callback ) }(${ JSON.stringify( {
@@ -105,12 +99,14 @@ const mocks = {
);
},
json: function( req, resp ) {
+ const headers = {};
if ( req.query.header ) {
- resp.writeHead( 200, { "content-type": "application/json" } );
+ headers[ "content-type" ] = "application/json";
}
if ( req.query.cors ) {
- resp.writeHead( 200, { "access-control-allow-origin": "*" } );
+ headers[ "access-control-allow-origin" ] = "*";
}
+ resp.writeHead( 200, headers );
if ( req.query.array ) {
resp.end( JSON.stringify(
[ { name: "John", age: 21 }, { name: "Peter", age: 25 } ]