Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test): Test Remix and NextJS SDKs on Node 20. #8577

Merged
merged 15 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [10, 12, 14, 16, 18]
node: [10, 12, 14, 16, 18, 20]
steps:
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
uses: actions/checkout@v3
Expand Down Expand Up @@ -706,7 +706,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [14, 16, 18]
node: [14, 16, 18, 20]
remix: [1, 2]
steps:
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
Expand Down
14 changes: 7 additions & 7 deletions packages/nextjs/test/integration/test/server/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getPortPromise } from 'portfinder';
import { TestEnv } from '../../../../../../node-integration-tests/utils';
import * as http from 'http';
import * as path from 'path';
import { createServer, Server } from 'http';
import { parse } from 'url';
import next from 'next';
import { AddressInfo } from 'net';

// Type not exported from NextJS
// @ts-ignore
Expand All @@ -24,9 +24,10 @@ export const createNextServer = async config => {
});
};

export const startServer = async (server: Server, port: string | number) => {
return new Promise(resolve => {
server.listen(port || 0, () => {
export const startServer = async (server: Server) => {
return new Promise<{ server: http.Server; url: string }>(resolve => {
server.listen(0, () => {
const port = (server.address() as AddressInfo).port;
const url = `http://localhost:${port}`;
resolve({ server, url });
});
Expand All @@ -39,7 +40,6 @@ export class NextTestEnv extends TestEnv {
}

public static async init(): Promise<NextTestEnv> {
const port = await getPortPromise();
const server = await createNextServer({
dev: false,
dir: path.resolve(__dirname, '../../..'),
Expand All @@ -50,8 +50,8 @@ export class NextTestEnv extends TestEnv {
conf: path.resolve(__dirname, '../../next.config.js'),
});

await startServer(server, port);
const { url } = await startServer(server);

return new NextTestEnv(server, `http://localhost:${port}`);
return new NextTestEnv(server, url);
}
}
1 change: 1 addition & 0 deletions packages/node-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"cors": "^2.8.5",
"express": "^4.17.3",
"graphql": "^16.3.0",
"http-terminator": "^3.2.0",
"mongodb": "^3.7.3",
"mongodb-memory-server-global": "^7.6.3",
"mysql": "^2.18.1",
Expand Down
33 changes: 24 additions & 9 deletions packages/node-integration-tests/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import type { AxiosRequestConfig } from 'axios';
import axios from 'axios';
import type { Express } from 'express';
import type * as http from 'http';
import type { HttpTerminator } from 'http-terminator';
import { createHttpTerminator } from 'http-terminator';
import type { AddressInfo } from 'net';
import nock from 'nock';
import * as path from 'path';

const NODE_VERSION = parseSemver(process.versions.node).major;

export type TestServerConfig = {
url: string;
server: http.Server;
Expand Down Expand Up @@ -40,7 +44,6 @@ export type DataCollectorOptions = {
* @return {*} {jest.Describe}
*/
export const conditionalTest = (allowedVersion: { min?: number; max?: number }): jest.Describe => {
const NODE_VERSION = parseSemver(process.versions.node).major;
if (!NODE_VERSION) {
return describe.skip;
}
Expand Down Expand Up @@ -123,10 +126,12 @@ async function makeRequest(

export class TestEnv {
private _axiosConfig: AxiosRequestConfig | undefined = undefined;
private _terminator: HttpTerminator;

public constructor(public readonly server: http.Server, public readonly url: string) {
this.server = server;
this.url = url;
this._terminator = createHttpTerminator({ server: this.server, gracefulTerminationTimeout: 0 });
}

/**
Expand Down Expand Up @@ -244,12 +249,20 @@ export class TestEnv {
// Ex: Remix scope bleed tests.
nock.cleanAll();

this.server.close(() => {
resolve(envelopes);
});
// Abort all pending requests to nock to prevent hanging / flakes.
// See: https://github.com/nock/nock/issues/1118#issuecomment-544126948
nock.abortPendingRequests();

this._closeServer()
.catch(e => {
logger.warn(e);
})
.finally(() => {
resolve(envelopes);
});
} else {
resolve(envelopes);
}

resolve(envelopes);
}

return true;
Expand Down Expand Up @@ -291,12 +304,14 @@ export class TestEnv {

nock.cleanAll();

this.server.close(() => {
void this._closeServer().then(() => {
resolve(reqCount);
});

resolve(reqCount);
}, options.timeout || 1000);
});
}

private _closeServer(): Promise<void> {
return this._terminator.terminate();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to be clear, do we not need to call this.server.close() anymore, is that handled by the terminator?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
}
3 changes: 1 addition & 2 deletions packages/remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
"devDependencies": {
"@remix-run/node": "^1.4.3",
"@remix-run/react": "^1.4.3",
"@types/express": "^4.17.14",
"portfinder": "^1.0.28"
"@types/express": "^4.17.14"
},
"peerDependencies": {
"@remix-run/node": "1.x",
Expand Down
6 changes: 3 additions & 3 deletions packages/remix/test/integration/test/server/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
cookies: expect.any(Object),
headers: {
'user-agent': expect.any(String),
host: 'localhost:8000',
host: expect.stringContaining('localhost:'),
},
},
});
Expand Down Expand Up @@ -114,7 +114,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
cookies: expect.any(Object),
headers: {
'user-agent': expect.any(String),
host: 'localhost:8000',
host: expect.stringContaining('localhost:'),
},
},
});
Expand All @@ -134,7 +134,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
cookies: expect.any(Object),
headers: {
'user-agent': expect.any(String),
host: 'localhost:8000',
host: expect.stringContaining('localhost:'),
},
},
});
Expand Down
10 changes: 5 additions & 5 deletions packages/remix/test/integration/test/server/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import express from 'express';
import { createRequestHandler } from '@remix-run/express';
import { getPortPromise } from 'portfinder';
import { wrapExpressCreateRequestHandler } from '@sentry/remix';
import { TestEnv } from '../../../../../../node-integration-tests/utils';
import * as http from 'http';
import { AddressInfo } from 'net';

export * from '../../../../../../node-integration-tests/utils';

Expand All @@ -16,18 +16,18 @@ export class RemixTestEnv extends TestEnv {
const requestHandlerFactory =
adapter === 'express' ? wrapExpressCreateRequestHandler(createRequestHandler) : createRequestHandler;

const port = await getPortPromise();

let serverPort;
const server = await new Promise<http.Server>(resolve => {
const app = express();

app.all('*', requestHandlerFactory({ build: require('../../../build') }));

const server = app.listen(port, () => {
const server = app.listen(0, () => {
serverPort = (server.address() as AddressInfo).port;
resolve(server);
});
});

return new RemixTestEnv(server, `http://localhost:${port}`);
return new RemixTestEnv(server, `http://localhost:${serverPort}`);
}
}
Loading