Skip to content

Commit c04f1a5

Browse files
committed
ref: Run node integration tests via runner & skip fastify on node <14
1 parent 47f0eba commit c04f1a5

File tree

4 files changed

+65
-7
lines changed

4 files changed

+65
-7
lines changed

packages/node/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@
6262
"lint": "run-s lint:prettier lint:eslint",
6363
"lint:eslint": "eslint . --format stylish",
6464
"lint:prettier": "prettier --check \"{src,test,scripts}/**/**.ts\"",
65-
"test": "run-s test:jest test:express test:fastify test:webpack test:release-health",
66-
"test:express": "node test/manual/express-scope-separation/start.js",
67-
"test:fastify": "node test/manual/fastify-scope-separation/start.js",
65+
"test": "run-s test:jest test:integration test:webpack test:release-health",
66+
"test:integration": "node test/manual/integration/runner.js",
6867
"test:jest": "jest",
6968
"test:release-health": "node test/manual/release-health/runner.js",
7069
"test:webpack": "cd test/manual/webpack-async-context/ && yarn --silent && node npm-build.js",

packages/node/test/manual/express-scope-separation/start.js renamed to packages/node/test/manual/integration/express/express-scope-separation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const http = require('http');
22
const express = require('express');
33
const app = express();
4-
const Sentry = require('../../../build/cjs');
5-
const { colorize } = require('../colorize');
4+
const Sentry = require('../../../../build/cjs');
5+
const { colorize } = require('../../colorize');
66
const { TextEncoder } = require('util');
77

88
// don't log the test errors we're going to throw, so at a quick glance it doesn't look like the test itself has failed

packages/node/test/manual/fastify-scope-separation/start.js renamed to packages/node/test/manual/integration/fastify/fastify-scope-separation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const http = require('http');
22
const fastify = require('fastify');
33
const app = fastify();
4-
const Sentry = require('../../../build/cjs');
5-
const { colorize } = require('../colorize');
4+
const Sentry = require('../../../../build/cjs');
5+
const { colorize } = require('../../colorize');
66
const { TextEncoder } = require('util');
77

88
// don't log the test errors we're going to throw, so at a quick glance it doesn't look like the test itself has failed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const { spawn } = require('child_process');
4+
const { colorize } = require('../colorize');
5+
6+
const nodeVersion = parseInt(process.version.match(/^v(\d+)\./)[1]);
7+
const scenariosDirs = ['express'];
8+
const scenarios = [];
9+
10+
// Fastify is only supported on Node 14+
11+
if (nodeVersion >= 14) {
12+
scenariosDirs.push('fastify');
13+
}
14+
15+
for (const dir of scenariosDirs) {
16+
const scenarioDir = path.resolve(__dirname, dir);
17+
const filenames = fs.readdirSync(scenarioDir);
18+
const paths = filenames.map(filename => [filename, path.resolve(scenarioDir, filename)]);
19+
scenarios.push(...paths);
20+
}
21+
22+
const processes = scenarios.map(([filename, filepath]) => {
23+
return new Promise(resolve => {
24+
const scenarioProcess = spawn('node', [filepath], { timeout: 10000 });
25+
const output = [];
26+
const errors = [];
27+
28+
scenarioProcess.stdout.on('data', data => {
29+
output.push(data.toString());
30+
});
31+
32+
scenarioProcess.stderr.on('data', data => {
33+
errors.push(data.toString());
34+
});
35+
36+
scenarioProcess.on('exit', code => {
37+
if (code === 0) {
38+
console.log(colorize(`PASSED: ${filename}`, 'green'));
39+
} else {
40+
console.log(colorize(`FAILED: ${filename}`, 'red'));
41+
42+
if (output.length) {
43+
console.log(colorize(output.join('\n'), 'yellow'));
44+
}
45+
if (errors.length) {
46+
console.log(colorize(errors.join('\n'), 'yellow'));
47+
}
48+
}
49+
50+
resolve(code);
51+
});
52+
});
53+
});
54+
55+
Promise.all(processes).then(codes => {
56+
if (codes.some(code => code !== 0)) {
57+
process.exit(1);
58+
}
59+
});

0 commit comments

Comments
 (0)