Skip to content

Commit 16b7343

Browse files
authored
ci: Split node & browser unit tests (#6535)
1 parent 3ef3918 commit 16b7343

File tree

3 files changed

+99
-40
lines changed

3 files changed

+99
-40
lines changed

.github/workflows/build.yml

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ env:
3232
CACHED_BUILD_PATHS: |
3333
${{ github.workspace }}/packages/*/build
3434
${{ github.workspace }}/packages/ember/*.d.ts
35-
${{ github.workspace }}/packages/ember/instance-initializers
3635
${{ github.workspace }}/packages/gatsby/*.d.ts
3736
${{ github.workspace }}/packages/core/src/version.ts
3837
${{ github.workspace }}/packages/serverless
@@ -352,8 +351,39 @@ jobs:
352351
${{ github.workspace }}/packages/replay/build/bundles/**
353352
${{ github.workspace }}/packages/**/*.tgz
354353
355-
job_unit_test:
356-
name: Test (Node ${{ matrix.node }})
354+
job_browser_unit_tests:
355+
name: Browser Unit Tests
356+
needs: [job_get_metadata, job_build]
357+
timeout-minutes: 10
358+
runs-on: ubuntu-latest
359+
steps:
360+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
361+
uses: actions/checkout@v3
362+
with:
363+
ref: ${{ env.HEAD_COMMIT }}
364+
- name: Set up Node
365+
uses: actions/setup-node@v3
366+
with:
367+
node-version: ${{ env.DEFAULT_NODE_VERSION }}
368+
- name: Check dependency cache
369+
uses: actions/cache@v3
370+
with:
371+
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
372+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
373+
- name: Check build cache
374+
uses: actions/cache@v3
375+
with:
376+
path: ${{ env.CACHED_BUILD_PATHS }}
377+
key: ${{ env.BUILD_CACHE_KEY }}
378+
- name: Run tests
379+
env:
380+
NODE_VERSION: 16
381+
run: yarn test-ci-browser
382+
- name: Compute test coverage
383+
uses: codecov/codecov-action@v3
384+
385+
job_node_unit_tests:
386+
name: Node (${{ matrix.node }}) Unit Tests
357387
needs: [job_get_metadata, job_build]
358388
timeout-minutes: 30
359389
runs-on: ubuntu-20.04
@@ -385,12 +415,12 @@ jobs:
385415
NODE_VERSION: ${{ matrix.node }}
386416
run: |
387417
[[ $NODE_VERSION == 8 ]] && yarn add --dev --ignore-engines --ignore-scripts --ignore-workspace-root-check [email protected]
388-
yarn test-ci
418+
yarn test-ci-node
389419
- name: Compute test coverage
390420
uses: codecov/codecov-action@v3
391421

392422
job_nextjs_integration_test:
393-
name: Test @sentry/nextjs on (Node ${{ matrix.node }})
423+
name: Nextjs (Node ${{ matrix.node }}) Tests
394424
needs: [job_get_metadata, job_build]
395425
if: needs.job_get_metadata.outputs.changed_nextjs == 'true' || github.event_name != 'pull_request'
396426
timeout-minutes: 30
@@ -428,7 +458,7 @@ jobs:
428458
# Ember tests are separate from the rest because they are the slowest part of the test suite, and making them a
429459
# separate job allows them to run in parallel with the other tests.
430460
job_ember_tests:
431-
name: Test @sentry/ember
461+
name: Ember (${{ matrix.scenario }}) Tests
432462
needs: [job_get_metadata, job_build]
433463
if: needs.job_get_metadata.outputs.changed_ember == 'true' || github.event_name != 'pull_request'
434464
timeout-minutes: 10
@@ -470,7 +500,7 @@ jobs:
470500
uses: codecov/codecov-action@v3
471501

472502
job_browser_playwright_tests:
473-
name: Playwright - ${{ (matrix.tracing_only && 'Browser + Tracing') || 'Browser' }} (${{ matrix.bundle }})
503+
name: Playwright (${{ matrix.bundle }})${{ (matrix.tracing_only && ' tracing only') || '' }} Tests
474504
needs: [job_get_metadata, job_build]
475505
if: needs.job_get_metadata.outputs.changed_browser_integration == 'true' || github.event_name != 'pull_request'
476506
runs-on: ubuntu-20.04
@@ -520,7 +550,7 @@ jobs:
520550
yarn test:ci
521551
522552
job_browser_integration_tests:
523-
name: Old Browser Integration Tests (${{ matrix.browser }})
553+
name: Browser (${{ matrix.browser }}) Tests
524554
needs: [job_get_metadata, job_build]
525555
if: needs.job_get_metadata.outputs.changed_browser == 'true' || github.event_name != 'pull_request'
526556
runs-on: ubuntu-20.04
@@ -589,7 +619,7 @@ jobs:
589619
yarn test:package
590620
591621
job_node_integration_tests:
592-
name: Node SDK Integration Tests (${{ matrix.node }})
622+
name: Node (${{ matrix.node }}) Integration Tests
593623
needs: [job_get_metadata, job_build]
594624
if: needs.job_get_metadata.outputs.changed_node == 'true' || github.event_name != 'pull_request'
595625
runs-on: ubuntu-20.04
@@ -625,7 +655,7 @@ jobs:
625655
yarn test
626656
627657
job_remix_integration_tests:
628-
name: Remix SDK Integration Tests (${{ matrix.node }})
658+
name: Remix (Node ${{ matrix.node }}) Tests
629659
needs: [job_get_metadata, job_build]
630660
if: needs.job_get_metadata.outputs.changed_remix == 'true' || github.event_name != 'pull_request'
631661
runs-on: ubuntu-20.04
@@ -708,7 +738,8 @@ jobs:
708738
[
709739
job_build,
710740
job_browser_build_tests,
711-
job_unit_test,
741+
job_browser_unit_tests,
742+
job_node_unit_tests,
712743
job_nextjs_integration_test,
713744
job_node_integration_tests,
714745
job_browser_playwright_tests,

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": "cross-env TESTS_SKIP=node ts-node ./scripts/test.ts",
30+
"test-ci-node": "cross-env TESTS_SKIP=browser ts-node ./scripts/test.ts",
2931
"postinstall": "patch-package"
3032
},
3133
"volta": {

scripts/test.ts

Lines changed: 55 additions & 29 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,27 @@ 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+
'@sentry/wasm',
32+
];
33+
34+
// These can be skipped when running tests independently of the Node version.
35+
const SKIP_NODE_TESTS_PACKAGES = [
36+
'@sentry/node',
37+
'@sentry/opentelemetry-node',
38+
'@sentry/serverless',
39+
'@sentry/nextjs',
40+
'@sentry/remix',
41+
'@sentry/gatsby',
42+
];
43+
2344
// We have to downgrade some of our dependencies in order to run tests in Node 8 and 10.
2445
const NODE_8_LEGACY_DEPENDENCIES = [
2546
@@ -29,10 +50,10 @@ const NODE_8_LEGACY_DEPENDENCIES = [
2950
3051
];
3152

32-
const NODE_10_SKIP_TESTS_PACKAGES = [...DEFAULT_SKIP_TESTS_PACKAGES, '@sentry/remix', '@sentry/replay'];
53+
const NODE_10_SKIP_TESTS_PACKAGES = ['@sentry/remix', '@sentry/replay'];
3354
const NODE_10_LEGACY_DEPENDENCIES = ['[email protected]'];
3455

35-
const NODE_12_SKIP_TESTS_PACKAGES = [...DEFAULT_SKIP_TESTS_PACKAGES, '@sentry/remix'];
56+
const NODE_12_SKIP_TESTS_PACKAGES = ['@sentry/remix'];
3657

3758
type JSONValue = string | number | boolean | null | JSONArray | JSONObject;
3859

@@ -91,13 +112,10 @@ const es6ifyTestTSConfig = (pkg: string): void => {
91112
};
92113

93114
/**
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.
115+
* Skip tests which don't run in Node 8.
116+
* We're forced to skip these tests for compatibility reasons.
99117
*/
100-
function skipNonNodeTests(): void {
118+
function skipNodeV8Tests(): void {
101119
run('rm -rf packages/tracing/test/browser');
102120
}
103121

@@ -113,29 +131,37 @@ function runWithIgnores(skipPackages: string[] = []): void {
113131
* Run the tests, accounting for compatibility problems in older versions of Node.
114132
*/
115133
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);
134+
const ignores = new Set<string>();
135+
136+
DEFAULT_SKIP_TESTS_PACKAGES.forEach(dep => ignores.add(dep));
137+
138+
if (process.env.TESTS_SKIP === 'browser') {
139+
SKIP_BROWSER_TESTS_PACKAGES.forEach(dep => ignores.add(dep));
129140
}
130-
//
131-
else if (CURRENT_NODE_VERSION === '12') {
132-
es6ifyTestTSConfig('utils');
133-
runWithIgnores(NODE_12_SKIP_TESTS_PACKAGES);
141+
142+
if (process.env.TESTS_SKIP === 'node') {
143+
SKIP_NODE_TESTS_PACKAGES.forEach(dep => ignores.add(dep));
134144
}
135-
//
136-
else {
137-
runWithIgnores(DEFAULT_SKIP_TESTS_PACKAGES);
145+
146+
switch (CURRENT_NODE_VERSION) {
147+
case '8':
148+
NODE_8_SKIP_TESTS_PACKAGES.forEach(dep => ignores.add(dep));
149+
installLegacyDeps(NODE_8_LEGACY_DEPENDENCIES);
150+
skipNodeV8Tests();
151+
es6ifyTestTSConfig('utils');
152+
break;
153+
case '10':
154+
NODE_10_SKIP_TESTS_PACKAGES.forEach(dep => ignores.add(dep));
155+
installLegacyDeps(NODE_10_LEGACY_DEPENDENCIES);
156+
es6ifyTestTSConfig('utils');
157+
break;
158+
case '12':
159+
NODE_12_SKIP_TESTS_PACKAGES.forEach(dep => ignores.add(dep));
160+
es6ifyTestTSConfig('utils');
161+
break;
138162
}
163+
164+
runWithIgnores(Array.from(ignores));
139165
}
140166

141167
runTests();

0 commit comments

Comments
 (0)