Skip to content

Commit 1b6e6ba

Browse files
committed
test updates for node 20
1 parent 5dd6f2d commit 1b6e6ba

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

packages/server/src/__tests__/express4/expressSpecific.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ it('supporting doubly-encoded variables example from migration guide', async ()
193193
query: 'query Hello($s: String!){hello(s: $s)}',
194194
variables: '{malformed JSON}',
195195
})
196-
.expect(400, 'Unexpected token m in JSON at position 1');
196+
.expect(400, /in JSON at position 1/);
197197

198198
await server.stop();
199199
});

packages/server/src/__tests__/plugin/drainHttpServer/stoppable.test.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const a: any = require('awaiting');
3232
const request: any = require('requisition');
3333
import fs from 'fs';
3434
import { Stopper } from '../../../plugin/drainHttpServer/stoppable';
35-
import child from 'child_process';
3635
import path from 'path';
3736
import type { AddressInfo } from 'net';
3837
import { describe, it, expect, afterEach, beforeEach } from '@jest/globals';
@@ -136,7 +135,9 @@ Object.keys(schemes).forEach((schemeName) => {
136135
),
137136
);
138137
expect(err.code).toMatch(/ECONNREFUSED/);
139-
expect(closed).toBe(0);
138+
139+
const isNode20 = !!process.version.match(/^v20\./);
140+
expect(closed).toBe(isNode20 ? 1 : 0);
140141
});
141142
});
142143

@@ -301,12 +302,21 @@ Object.keys(schemes).forEach((schemeName) => {
301302

302303
if (schemeName === 'http') {
303304
it('with in-flights finishing before grace period ends', async () => {
304-
const file = path.join(__dirname, 'stoppable', 'server.js');
305-
const server = child.spawn('node', [file]);
306-
const [data] = await a.event(server.stdout, 'data');
307-
const port = +data.toString();
308-
expect(typeof port).toBe('number');
309-
const res = await request(`${schemeName}://localhost:${port}/`).agent(
305+
let stopper: Stopper;
306+
const killServerBarrier = resolvable();
307+
const server = http.createServer(async (_, res) => {
308+
res.writeHead(200);
309+
res.write('hello');
310+
311+
await killServerBarrier;
312+
res.end('world');
313+
await stopper.stop();
314+
});
315+
stopper = new Stopper(server);
316+
server.listen(0);
317+
const p = port(server);
318+
319+
const res = await request(`${schemeName}://localhost:${p}/`).agent(
310320
scheme.agent({ keepAlive: true }),
311321
);
312322
let gotBody = false;
@@ -320,13 +330,13 @@ Object.keys(schemes).forEach((schemeName) => {
320330
expect(gotBody).toBe(false);
321331

322332
// Tell the server that its request should finish.
323-
server.kill('SIGUSR1');
333+
killServerBarrier.resolve();
324334

325335
const body = await bodyPromise;
326336
expect(gotBody).toBe(true);
327337
expect(body).toBe('helloworld');
328338

329-
// Wait for subprocess to go away.
339+
// Wait for server to close.
330340
await a.event(server, 'close');
331341
});
332342
}

packages/server/src/__tests__/plugin/drainHttpServer/stoppable/server.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)