mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
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
This commit is contained in:
parent
b507c8648f
commit
d478a1c022
@ -80,13 +80,7 @@ const mocks = {
|
|||||||
headers[ "access-control-allow-origin" ] = "*";
|
headers[ "access-control-allow-origin" ] = "*";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( resp.set ) {
|
resp.writeHead( 200, headers );
|
||||||
resp.set( headers );
|
|
||||||
} else {
|
|
||||||
for ( const key in headers ) {
|
|
||||||
resp.writeHead( 200, { [ key ]: headers[ key ] } );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( req.query.callback ) {
|
if ( req.query.callback ) {
|
||||||
resp.end( `${ cleanCallback( req.query.callback ) }(${ JSON.stringify( {
|
resp.end( `${ cleanCallback( req.query.callback ) }(${ JSON.stringify( {
|
||||||
@ -105,12 +99,14 @@ const mocks = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
json: function( req, resp ) {
|
json: function( req, resp ) {
|
||||||
|
const headers = {};
|
||||||
if ( req.query.header ) {
|
if ( req.query.header ) {
|
||||||
resp.writeHead( 200, { "content-type": "application/json" } );
|
headers[ "content-type" ] = "application/json";
|
||||||
}
|
}
|
||||||
if ( req.query.cors ) {
|
if ( req.query.cors ) {
|
||||||
resp.writeHead( 200, { "access-control-allow-origin": "*" } );
|
headers[ "access-control-allow-origin" ] = "*";
|
||||||
}
|
}
|
||||||
|
resp.writeHead( 200, headers );
|
||||||
if ( req.query.array ) {
|
if ( req.query.array ) {
|
||||||
resp.end( JSON.stringify(
|
resp.end( JSON.stringify(
|
||||||
[ { name: "John", age: 21 }, { name: "Peter", age: 25 } ]
|
[ { name: "John", age: 21 }, { name: "Peter", age: 25 } ]
|
||||||
|
Loading…
Reference in New Issue
Block a user