Skip to content

Commit

Permalink
test updates for node 20
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-scheer committed Jul 21, 2023
1 parent 5dd6f2d commit 1b6e6ba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ it('supporting doubly-encoded variables example from migration guide', async ()
query: 'query Hello($s: String!){hello(s: $s)}',
variables: '{malformed JSON}',
})
.expect(400, 'Unexpected token m in JSON at position 1');
.expect(400, /in JSON at position 1/);

await server.stop();
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const a: any = require('awaiting');
const request: any = require('requisition');
import fs from 'fs';
import { Stopper } from '../../../plugin/drainHttpServer/stoppable';
import child from 'child_process';
import path from 'path';
import type { AddressInfo } from 'net';
import { describe, it, expect, afterEach, beforeEach } from '@jest/globals';
Expand Down Expand Up @@ -136,7 +135,9 @@ Object.keys(schemes).forEach((schemeName) => {
),
);
expect(err.code).toMatch(/ECONNREFUSED/);
expect(closed).toBe(0);

const isNode20 = !!process.version.match(/^v20\./);
expect(closed).toBe(isNode20 ? 1 : 0);
});
});

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

if (schemeName === 'http') {
it('with in-flights finishing before grace period ends', async () => {
const file = path.join(__dirname, 'stoppable', 'server.js');
const server = child.spawn('node', [file]);
const [data] = await a.event(server.stdout, 'data');
const port = +data.toString();
expect(typeof port).toBe('number');
const res = await request(`${schemeName}://localhost:${port}/`).agent(
let stopper: Stopper;
const killServerBarrier = resolvable();
const server = http.createServer(async (_, res) => {
res.writeHead(200);
res.write('hello');

await killServerBarrier;
res.end('world');
await stopper.stop();
});
stopper = new Stopper(server);
server.listen(0);
const p = port(server);

const res = await request(`${schemeName}://localhost:${p}/`).agent(
scheme.agent({ keepAlive: true }),
);
let gotBody = false;
Expand All @@ -320,13 +330,13 @@ Object.keys(schemes).forEach((schemeName) => {
expect(gotBody).toBe(false);

// Tell the server that its request should finish.
server.kill('SIGUSR1');
killServerBarrier.resolve();

const body = await bodyPromise;
expect(gotBody).toBe(true);
expect(body).toBe('helloworld');

// Wait for subprocess to go away.
// Wait for server to close.
await a.event(server, 'close');
});
}
Expand Down

This file was deleted.

0 comments on commit 1b6e6ba

Please sign in to comment.