Skip to content

Commit 2a34f7d

Browse files
committed
chore(test): Allow to run node/browser unit tests separately
1 parent d972ded commit 2a34f7d

File tree

2 files changed

+54
-27
lines changed

2 files changed

+54
-27
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"postpublish": "lerna run --stream --concurrency 1 postpublish",
2727
"test": "lerna run --ignore @sentry-internal/browser-integration-tests --ignore @sentry-internal/node-integration-tests --stream --concurrency 1 --sort test",
2828
"test-ci": "ts-node ./scripts/test.ts",
29+
"test-ci-browser": "TESTS_SKIP=node ts-node ./scripts/test.ts",
30+
"test-ci-node": "TESTS_SKIP=browser ts-node ./scripts/test.ts",
2931
"postinstall": "patch-package"
3032
},
3133
"volta": {

scripts/test.ts

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ const CURRENT_NODE_VERSION = process.version.replace('v', '').split('.')[0];
55

66
// We run ember tests in their own job.
77
const DEFAULT_SKIP_TESTS_PACKAGES = ['@sentry/ember'];
8+
89
// These packages don't support Node 8 for syntax or dependency reasons.
910
const NODE_8_SKIP_TESTS_PACKAGES = [
10-
...DEFAULT_SKIP_TESTS_PACKAGES,
1111
'@sentry-internal/eslint-plugin-sdk',
1212
'@sentry/react',
1313
'@sentry/wasm',
@@ -20,6 +20,26 @@ const NODE_8_SKIP_TESTS_PACKAGES = [
2020
'@sentry/replay',
2121
];
2222

23+
// These can be skipped when running tests in different Node environments.
24+
const SKIP_BROWSER_TESTS_PACKAGES = [
25+
'@sentry/browser',
26+
'@sentry/vue',
27+
'@sentry/react',
28+
'@sentry/angular',
29+
'@sentry/svelte',
30+
'@sentry/replay',
31+
];
32+
33+
// These can be skipped when running tests independently of the Node version.
34+
const SKIP_NODE_TESTS_PACKAGES = [
35+
'@sentry/node',
36+
'@sentry/opentelemetry-node',
37+
'@sentry/serverless',
38+
'@sentry/nextjs',
39+
'@sentry/remix',
40+
'@sentry/gatsby',
41+
];
42+
2343
// We have to downgrade some of our dependencies in order to run tests in Node 8 and 10.
2444
const NODE_8_LEGACY_DEPENDENCIES = [
2545
@@ -91,13 +111,10 @@ const es6ifyTestTSConfig = (pkg: string): void => {
91111
};
92112

93113
/**
94-
* Skip tests which don't apply to Node and therefore don't need to run in older Node versions.
95-
*
96-
* TODO We're foreced to skip these tests for compatibility reasons (right now this function only gets called in Node
97-
* 8), but we could be skipping a lot more tests in Node 8-14 - anything where compatibility with different Node
98-
* versions is irrelevant - and only running them in Node 16.
114+
* Skip tests which don't run in Node 8.
115+
* We're forced to skip these tests for compatibility reasons.
99116
*/
100-
function skipNonNodeTests(): void {
117+
function skipNodeV8Tests(): void {
101118
run('rm -rf packages/tracing/test/browser');
102119
}
103120

@@ -113,29 +130,37 @@ function runWithIgnores(skipPackages: string[] = []): void {
113130
* Run the tests, accounting for compatibility problems in older versions of Node.
114131
*/
115132
function runTests(): void {
116-
if (CURRENT_NODE_VERSION === '8') {
117-
installLegacyDeps(NODE_8_LEGACY_DEPENDENCIES);
118-
// TODO Right now, this just skips incompatible tests, but it could be skipping more (hence the aspirational name),
119-
// and not just in Node 8. See `skipNonNodeTests`'s docstring.
120-
skipNonNodeTests();
121-
es6ifyTestTSConfig('utils');
122-
runWithIgnores(NODE_8_SKIP_TESTS_PACKAGES);
123-
}
124-
//
125-
else if (CURRENT_NODE_VERSION === '10') {
126-
installLegacyDeps(NODE_10_LEGACY_DEPENDENCIES);
127-
es6ifyTestTSConfig('utils');
128-
runWithIgnores(NODE_10_SKIP_TESTS_PACKAGES);
133+
const ignores = new Set<string>();
134+
135+
DEFAULT_SKIP_TESTS_PACKAGES.forEach(dep => ignores.add(dep));
136+
137+
if (process.env.TESTS_SKIP === 'browser') {
138+
SKIP_BROWSER_TESTS_PACKAGES.forEach(dep => ignores.add(dep));
129139
}
130-
//
131-
else if (CURRENT_NODE_VERSION === '12') {
132-
es6ifyTestTSConfig('utils');
133-
runWithIgnores(NODE_12_SKIP_TESTS_PACKAGES);
140+
141+
if (process.env.TESTS_SKIP === 'node') {
142+
SKIP_NODE_TESTS_PACKAGES.forEach(dep => ignores.add(dep));
134143
}
135-
//
136-
else {
137-
runWithIgnores(DEFAULT_SKIP_TESTS_PACKAGES);
144+
145+
switch (CURRENT_NODE_VERSION) {
146+
case '8':
147+
NODE_8_SKIP_TESTS_PACKAGES.forEach(dep => ignores.add(dep));
148+
installLegacyDeps(NODE_8_LEGACY_DEPENDENCIES);
149+
skipNodeV8Tests();
150+
es6ifyTestTSConfig('utils');
151+
break;
152+
case '10':
153+
NODE_10_SKIP_TESTS_PACKAGES.forEach(dep => ignores.add(dep));
154+
installLegacyDeps(NODE_10_LEGACY_DEPENDENCIES);
155+
es6ifyTestTSConfig('utils');
156+
break;
157+
case '12':
158+
NODE_12_SKIP_TESTS_PACKAGES.forEach(dep => ignores.add(dep));
159+
es6ifyTestTSConfig('utils');
160+
break;
138161
}
162+
163+
runWithIgnores(Array.from(ignores));
139164
}
140165

141166
runTests();

0 commit comments

Comments
 (0)