Skip to content

Commit 2039de2

Browse files
lobsterkatieAbhiPrasad
authored andcommitted
ref(node): Improve Node manual test logging (#5088)
This makes some small changes to the logs emitted by the manual tests in the node package, to make it a little cleaner and easier to see what's what. Included changes: - Use `colorize` function from release health tests in all test suites. - Capture and display console logs in express test. - Standardize success message across test suites. - Use whitespace to separate each suite's logs from the next.
1 parent 89f4ecb commit 2039de2

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

packages/node/test/manual/colorize.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const COLOR_RESET = '\x1b[0m';
2+
const COLORS = {
3+
green: '\x1b[32m',
4+
red: '\x1b[31m',
5+
yellow: '\x1b[33m',
6+
};
7+
8+
function colorize(str, color) {
9+
if (!(color in COLORS)) {
10+
throw new Error(`Unknown color. Available colors: ${Object.keys(COLORS).join(', ')}`);
11+
}
12+
13+
return `${COLORS[color]}${str}${COLOR_RESET}`;
14+
}
15+
16+
module.exports = { colorize };

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ const http = require('http');
22
const express = require('express');
33
const app = express();
44
const Sentry = require('../../../build/cjs');
5+
const { colorize } = require('../colorize');
56

67
// 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
78
global.console.error = () => null;
89

910
function assertTags(actual, expected) {
1011
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
11-
console.error('FAILED: Scope contains incorrect tags');
12+
console.log(colorize('FAILED: Scope contains incorrect tags\n', 'red'));
1213
process.exit(1);
1314
}
1415
}
@@ -20,7 +21,7 @@ function makeDummyTransport() {
2021
--remaining;
2122

2223
if (!remaining) {
23-
console.error('SUCCESS: All scopes contain correct tags');
24+
console.log(colorize('PASSED: All scopes contain correct tags\n', 'green'));
2425
server.close();
2526
process.exit(0);
2627
}

packages/node/test/manual/release-health/runner.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
const fs = require('fs');
22
const path = require('path');
33
const { spawn } = require('child_process');
4-
5-
const COLOR_RESET = '\x1b[0m';
6-
const COLORS = {
7-
green: '\x1b[32m',
8-
red: '\x1b[31m',
9-
yellow: '\x1b[33m',
10-
};
11-
12-
const colorize = (str, color) => {
13-
if (!(color in COLORS)) {
14-
throw new Error(`Unknown color. Available colors: ${Object.keys(COLORS).join(', ')}`);
15-
}
16-
17-
return `${COLORS[color]}${str}${COLOR_RESET}`;
18-
};
4+
const { colorize } = require('../colorize');
195

206
const scenariosDirs = ['session-aggregates', 'single-session'];
217
const scenarios = [];

packages/node/test/manual/webpack-domain/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Sentry = require('../../../build/cjs');
2+
const { colorize } = require('../colorize');
23

34
let remaining = 2;
45

@@ -7,7 +8,7 @@ function makeDummyTransport() {
78
--remaining;
89

910
if (!remaining) {
10-
console.error('SUCCESS: Webpack Node Domain test OK!');
11+
console.log(colorize('PASSED: Webpack Node Domain test OK!\n', 'green'));
1112
process.exit(0);
1213
}
1314

@@ -23,13 +24,13 @@ Sentry.init({
2324
beforeSend(event) {
2425
if (event.message === 'inside') {
2526
if (event.tags.a !== 'x' && event.tags.b !== 'c') {
26-
console.error('FAILED: Scope contains incorrect tags');
27+
console.log(colorize('FAILED: Scope contains incorrect tags\n', 'red'));
2728
process.exit(1);
2829
}
2930
}
3031
if (event.message === 'outside') {
3132
if (event.tags.a !== 'b') {
32-
console.error('FAILED: Scope contains incorrect tags');
33+
console.log(colorize('FAILED: Scope contains incorrect tags\n', 'red'));
3334
process.exit(1);
3435
}
3536
}

packages/node/test/manual/webpack-domain/npm-build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ webpack(
3939

4040
function runTests() {
4141
try {
42-
execSync('node ' + path.resolve(__dirname, 'dist', 'bundle.js'));
42+
execSync('node ' + path.resolve(__dirname, 'dist', 'bundle.js'), { stdio: 'inherit' });
4343
} catch (_) {
4444
process.exit(1);
4545
}

0 commit comments

Comments
 (0)