Skip to content

test: Fix node integration tests sharing SDK initializations #5715

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

Merged
merged 3 commits into from
Sep 12, 2022
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
1 change: 1 addition & 0 deletions packages/node-integration-tests/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ module.exports = {
globalSetup: '<rootDir>/utils/setup-tests.ts',
...baseConfig,
testMatch: ['**/test.ts'],
setupFilesAfterEnv: ['./jest.setup.js'],
};
2 changes: 2 additions & 0 deletions packages/node-integration-tests/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Increases test timeout from 5s to 45s
jest.setTimeout(45000);
2 changes: 1 addition & 1 deletion packages/node-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"fix:prettier": "prettier --write \"{suites,utils}/**/*.ts\"",
"type-check": "tsc",
"pretest": "run-s --silent prisma:init",
"test": "jest --runInBand --forceExit",
"test": "jest --forceExit",
"test:watch": "yarn test --watch"
},
"dependencies": {
Expand Down
11 changes: 6 additions & 5 deletions packages/node-integration-tests/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,9 @@ export class TestEnv {
* @return {*} {Promise<string>}
*/
public static async init(testDir: string, serverPath?: string, scenarioPath?: string): Promise<TestEnv> {
const port = await getPortPromise();
const url = `http://localhost:${port}/test`;
const defaultServerPath = path.resolve(process.cwd(), 'utils', 'defaults', 'server');

const server = await new Promise<http.Server>(resolve => {
const [server, url] = await new Promise<[http.Server, string]>(resolve => {
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-member-access
const app = require(serverPath || defaultServerPath).default as Express;

Expand All @@ -153,8 +151,11 @@ export class TestEnv {
}
});

const server = app.listen(port, () => {
resolve(server);
void getPortPromise().then(port => {
const url = `http://localhost:${port}/test`;
const server = app.listen(port, () => {
resolve([server, url]);
});
});
});

Expand Down