Skip to content

Commit 8af205e

Browse files
authored
test: Improve node integration test running (#10673)
This improves the output and formatting of the node integration tests, making it a bit easier to work with them: 1. Removed the coverage output, making the general output much clearer 2. Ensure we have color in the jest output, making it easier to scan it 3. Remove logging around started tests & workers, streamlining the output and aligning it more with the usual jest output. 4. Move skipped output to the end of the test, clearing up the output for actually run tests 5. Update summary at the bottom to show success/failed/skipped test numbers 6. Add color to summary output (error/success/skipped) to make it clearer. 7. Show relative path names instead of full path names Skipped tests: <img width="528" alt="Screenshot 2024-02-15 at 12 04 29" src="https://github.com/getsentry/sentry-javascript/assets/2411343/02d849c8-b8f4-4775-bd5c-ce4e8e18cfc2"> Failed test: <img width="1138" alt="Screenshot 2024-02-15 at 11 46 42" src="https://github.com/getsentry/sentry-javascript/assets/2411343/72ee1d31-6c49-4108-b891-ed5492d183ac"> Successful test: <img width="1002" alt="Screenshot 2024-02-15 at 11 48 28" src="https://github.com/getsentry/sentry-javascript/assets/2411343/1ee3b2a2-ecd0-4eaf-b68b-2d534f1c4622"> Failed test summary: <img width="491" alt="Screenshot 2024-02-15 at 11 52 19" src="https://github.com/getsentry/sentry-javascript/assets/2411343/b19d051d-189b-4459-8a28-9b9c6dcc2bb5"> Successful test summary: <img width="296" alt="Screenshot 2024-02-15 at 11 55 28" src="https://github.com/getsentry/sentry-javascript/assets/2411343/bc369482-08ab-4b50-8cf8-3c7c2e9cf51c">
1 parent afa5304 commit 8af205e

File tree

12 files changed

+60
-33
lines changed

12 files changed

+60
-33
lines changed

dev-packages/node-integration-tests/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ module.exports = {
55
...baseConfig,
66
testMatch: ['**/test.ts'],
77
setupFilesAfterEnv: ['./jest.setup.js'],
8+
coverageReporters: ['json', 'lcov', 'clover'],
89
};

dev-packages/node-integration-tests/suites/anr/basic-session.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Sentry.init({
1717
function longWork() {
1818
for (let i = 0; i < 20; i++) {
1919
const salt = crypto.randomBytes(128).toString('base64');
20-
// eslint-disable-next-line no-unused-vars
2120
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
2221
assert.ok(hash);
2322
}

dev-packages/node-integration-tests/suites/anr/basic.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Sentry.init({
1818
function longWork() {
1919
for (let i = 0; i < 20; i++) {
2020
const salt = crypto.randomBytes(128).toString('base64');
21-
// eslint-disable-next-line no-unused-vars
2221
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
2322
assert.ok(hash);
2423
}

dev-packages/node-integration-tests/suites/anr/basic.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Sentry.init({
1818
function longWork() {
1919
for (let i = 0; i < 20; i++) {
2020
const salt = crypto.randomBytes(128).toString('base64');
21-
// eslint-disable-next-line no-unused-vars
2221
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
2322
assert.ok(hash);
2423
}

dev-packages/node-integration-tests/suites/anr/forked.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ setTimeout(() => {
1010
Sentry.init({
1111
dsn: 'https://[email protected]/1337',
1212
release: '1.0',
13-
debug: true,
1413
autoSessionTracking: false,
14+
debug: true,
1515
integrations: [Sentry.anrIntegration({ captureStackTrace: true, anrThreshold: 100 })],
1616
});
1717

1818
function longWork() {
1919
for (let i = 0; i < 20; i++) {
2020
const salt = crypto.randomBytes(128).toString('base64');
21-
// eslint-disable-next-line no-unused-vars
2221
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
2322
assert.ok(hash);
2423
}

dev-packages/node-integration-tests/suites/anr/should-exit-forced.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ function configureSentry() {
44
Sentry.init({
55
dsn: 'https://[email protected]/1337',
66
release: '1.0',
7-
debug: true,
87
autoSessionTracking: false,
8+
debug: true,
99
integrations: [Sentry.anrIntegration({ captureStackTrace: true })],
1010
});
1111
}

dev-packages/node-integration-tests/suites/anr/should-exit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ function configureSentry() {
44
Sentry.init({
55
dsn: 'https://[email protected]/1337',
66
release: '1.0',
7-
debug: true,
87
autoSessionTracking: false,
8+
debug: true,
99
integrations: [Sentry.anrIntegration({ captureStackTrace: true })],
1010
});
1111
}

dev-packages/node-integration-tests/suites/proxy/basic.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ proxy.listen(0, () => {
88

99
Sentry.init({
1010
dsn: process.env.SENTRY_DSN,
11-
debug: true,
1211
transportOptions: {
1312
proxy: `http://localhost:${proxyPort}`,
1413
},

dev-packages/node-integration-tests/suites/tracing-experimental/hapi/scenario.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const Sentry = require('@sentry/node-experimental');
44
Sentry.init({
55
dsn: 'https://[email protected]/1337',
66
release: '1.0',
7-
debug: true,
87
tracesSampleRate: 1.0,
98
transport: loggingTransport,
109
});

dev-packages/node-integration-tests/suites/tracing-experimental/mongoose/scenario.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const Sentry = require('@sentry/node-experimental');
44
Sentry.init({
55
dsn: 'https://[email protected]/1337',
66
release: '1.0',
7-
debug: true,
87
tracesSampleRate: 1.0,
98
transport: loggingTransport,
109
});

dev-packages/node-integration-tests/suites/tracing-new/httpIntegration/spans/scenario.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Sentry.init({
88
release: '1.0',
99
tracesSampleRate: 1.0,
1010
integrations: [Sentry.httpIntegration({})],
11-
debug: true,
1211
});
1312

1413
// eslint-disable-next-line @typescript-eslint/no-floating-promises

dev-packages/node-integration-tests/utils/run-tests.ts

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-console */
22
import childProcess from 'child_process';
33
import os from 'os';
4+
import path from 'path';
45
import yargs from 'yargs';
56

67
const args = yargs
@@ -19,14 +20,19 @@ const testPaths = childProcess.execSync('jest --listTests', { encoding: 'utf8' }
1920

2021
const numTests = testPaths.length;
2122
const fails: string[] = [];
23+
const skips: string[] = [];
24+
25+
function getTestPath(testPath: string): string {
26+
const cwd = process.cwd();
27+
return path.relative(cwd, testPath);
28+
}
2229

2330
// We're creating a worker for each CPU core.
24-
const workers = os.cpus().map(async (_, i) => {
31+
const workers = os.cpus().map(async () => {
2532
while (testPaths.length > 0) {
26-
const testPath = testPaths.pop();
27-
console.log(`(Worker ${i}) Running test "${testPath}"`);
33+
const testPath = testPaths.pop() as string;
2834
await new Promise<void>(resolve => {
29-
const jestArgs = ['--runTestsByPath', testPath as string, '--forceExit'];
35+
const jestArgs = ['--runTestsByPath', testPath as string, '--forceExit', '--colors'];
3036

3137
if (args.t) {
3238
jestArgs.push('-t', args.t);
@@ -51,18 +57,24 @@ const workers = os.cpus().map(async (_, i) => {
5157
});
5258

5359
jestProcess.on('error', error => {
60+
console.log(`"${getTestPath(testPath)}" finished with error`, error);
5461
console.log(output);
55-
console.log(`(Worker ${i}) Error in test "${testPath}"`, error);
56-
fails.push(`FAILED: "${testPath}"`);
62+
fails.push(`FAILED: ${getTestPath(testPath)}`);
5763
resolve();
5864
});
5965

6066
jestProcess.on('exit', exitcode => {
61-
output = checkSkippedAllTests(output, i, testPath);
62-
console.log(`(Worker ${i}) Finished test "${testPath}"`);
63-
console.log(output);
64-
if (exitcode !== 0) {
65-
fails.push(`FAILED: "${testPath}"`);
67+
const hasError = exitcode !== 0;
68+
const skippedOutput = checkSkippedAllTests(output);
69+
70+
if (skippedOutput && !hasError) {
71+
skips.push(`SKIPPED: ${getTestPath(testPath)}`);
72+
} else {
73+
console.log(output);
74+
}
75+
76+
if (hasError) {
77+
fails.push(`FAILED: ${getTestPath(testPath)}`);
6678
}
6779
resolve();
6880
});
@@ -73,15 +85,35 @@ const workers = os.cpus().map(async (_, i) => {
7385
// eslint-disable-next-line @typescript-eslint/no-floating-promises
7486
Promise.all(workers).then(() => {
7587
console.log('-------------------');
76-
console.log(`Successfully ran ${numTests} tests.`);
77-
if (fails.length > 0) {
78-
console.log('Not all tests succeeded:\n');
88+
89+
const failCount = fails.length;
90+
const skipCount = skips.length;
91+
const totalCount = numTests;
92+
const successCount = numTests - failCount - skipCount;
93+
const nonSkippedCount = totalCount - skipCount;
94+
95+
if (skips.length) {
96+
console.log('\x1b[2m%s\x1b[0m', '\nSkipped tests:');
97+
skips.forEach(skip => {
98+
console.log('\x1b[2m%s\x1b[0m', `● ${skip}`);
99+
});
100+
}
101+
102+
if (failCount > 0) {
103+
console.log(
104+
'\x1b[31m%s\x1b[0m',
105+
`\n${failCount} of ${nonSkippedCount} tests failed${skipCount ? ` (${skipCount} skipped)` : ''}:\n`,
106+
);
79107
fails.forEach(fail => {
80-
console.log(`● ${fail}`);
108+
console.log('\x1b[31m%s\x1b[0m', `● ${fail}`);
81109
});
82110
process.exit(1);
83111
} else {
84-
console.log('All tests succeeded.');
112+
console.log(
113+
'\x1b[32m%s\x1b[0m',
114+
`\nSuccessfully ran ${successCount} tests${skipCount ? ` (${skipCount} skipped)` : ''}.`,
115+
);
116+
console.log('\x1b[32m%s\x1b[0m', 'All tests succeeded.');
85117
process.exit(0);
86118
}
87119
});
@@ -90,15 +122,17 @@ Promise.all(workers).then(() => {
90122
* Suppress jest output for test suites where all tests were skipped.
91123
* This only clutters the logs and we can safely print a one-liner instead.
92124
*/
93-
function checkSkippedAllTests(output: string, workerNumber: number, testPath: string | undefined): string {
94-
const regex = /Tests:\s+(\d+) skipped, (\d+) total/gm;
125+
function checkSkippedAllTests(output: string): boolean {
126+
const regex = /(.+)Tests:(.+)\s+(.+?)(\d+) skipped(.+), (\d+) total/gm;
95127
const matches = regex.exec(output);
128+
96129
if (matches) {
97-
const skipped = Number(matches[1]);
98-
const total = Number(matches[2]);
130+
const skipped = Number(matches[4]);
131+
const total = Number(matches[6]);
99132
if (!isNaN(skipped) && !isNaN(total) && total === skipped) {
100-
return `(Worker ${workerNumber}) > Skipped all (${total} tests) in ${testPath}`;
133+
return true;
101134
}
102135
}
103-
return output;
136+
137+
return false;
104138
}

0 commit comments

Comments
 (0)