mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
Parallelize Jest in CI (#19552)
Uses CircleCI's `parallelism` key to split our test jobs across multiple processes, like we do for the build job.
This commit is contained in:
parent
2d9ec9199c
commit
0cd9a6de55
|
|
@ -19,6 +19,8 @@ aliases:
|
||||||
name: Install Packages
|
name: Install Packages
|
||||||
command: yarn --frozen-lockfile
|
command: yarn --frozen-lockfile
|
||||||
|
|
||||||
|
- &TEST_PARALLELISM 20
|
||||||
|
|
||||||
- &attach_workspace
|
- &attach_workspace
|
||||||
at: build
|
at: build
|
||||||
|
|
||||||
|
|
@ -92,6 +94,7 @@ jobs:
|
||||||
RELEASE_CHANNEL_stable_yarn_test:
|
RELEASE_CHANNEL_stable_yarn_test:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
|
|
@ -102,6 +105,7 @@ jobs:
|
||||||
yarn_test:
|
yarn_test:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- *restore_yarn_cache
|
- *restore_yarn_cache
|
||||||
|
|
@ -111,6 +115,7 @@ jobs:
|
||||||
RELEASE_CHANNEL_stable_yarn_test_www:
|
RELEASE_CHANNEL_stable_yarn_test_www:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- *restore_yarn_cache
|
- *restore_yarn_cache
|
||||||
|
|
@ -120,6 +125,7 @@ jobs:
|
||||||
RELEASE_CHANNEL_stable_yarn_test_www_variant:
|
RELEASE_CHANNEL_stable_yarn_test_www_variant:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- *restore_yarn_cache
|
- *restore_yarn_cache
|
||||||
|
|
@ -129,6 +135,7 @@ jobs:
|
||||||
RELEASE_CHANNEL_stable_yarn_test_prod_www:
|
RELEASE_CHANNEL_stable_yarn_test_prod_www:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- *restore_yarn_cache
|
- *restore_yarn_cache
|
||||||
|
|
@ -138,6 +145,7 @@ jobs:
|
||||||
RELEASE_CHANNEL_stable_yarn_test_prod_www_variant:
|
RELEASE_CHANNEL_stable_yarn_test_prod_www_variant:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- *restore_yarn_cache
|
- *restore_yarn_cache
|
||||||
|
|
@ -147,6 +155,7 @@ jobs:
|
||||||
yarn_test_www:
|
yarn_test_www:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- *restore_yarn_cache
|
- *restore_yarn_cache
|
||||||
|
|
@ -156,6 +165,7 @@ jobs:
|
||||||
yarn_test_www_variant:
|
yarn_test_www_variant:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- *restore_yarn_cache
|
- *restore_yarn_cache
|
||||||
|
|
@ -165,6 +175,7 @@ jobs:
|
||||||
yarn_test_prod_www:
|
yarn_test_prod_www:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- *restore_yarn_cache
|
- *restore_yarn_cache
|
||||||
|
|
@ -174,6 +185,7 @@ jobs:
|
||||||
yarn_test_prod_www_variant:
|
yarn_test_prod_www_variant:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- *restore_yarn_cache
|
- *restore_yarn_cache
|
||||||
|
|
@ -183,6 +195,7 @@ jobs:
|
||||||
RELEASE_CHANNEL_stable_yarn_test_persistent:
|
RELEASE_CHANNEL_stable_yarn_test_persistent:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
|
|
@ -193,6 +206,7 @@ jobs:
|
||||||
RELEASE_CHANNEL_stable_yarn_test_prod:
|
RELEASE_CHANNEL_stable_yarn_test_prod:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
|
|
@ -203,6 +217,7 @@ jobs:
|
||||||
yarn_test_prod:
|
yarn_test_prod:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- *restore_yarn_cache
|
- *restore_yarn_cache
|
||||||
|
|
@ -212,7 +227,7 @@ jobs:
|
||||||
RELEASE_CHANNEL_stable_yarn_build:
|
RELEASE_CHANNEL_stable_yarn_build:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
parallelism: 20
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- *restore_yarn_cache
|
- *restore_yarn_cache
|
||||||
|
|
@ -344,6 +359,7 @@ jobs:
|
||||||
RELEASE_CHANNEL_stable_yarn_test_build:
|
RELEASE_CHANNEL_stable_yarn_test_build:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- attach_workspace: *attach_workspace
|
- attach_workspace: *attach_workspace
|
||||||
|
|
@ -354,6 +370,7 @@ jobs:
|
||||||
yarn_test_build:
|
yarn_test_build:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- attach_workspace: *attach_workspace
|
- attach_workspace: *attach_workspace
|
||||||
|
|
@ -404,6 +421,7 @@ jobs:
|
||||||
RELEASE_CHANNEL_stable_yarn_test_build_prod:
|
RELEASE_CHANNEL_stable_yarn_test_build_prod:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- attach_workspace: *attach_workspace
|
- attach_workspace: *attach_workspace
|
||||||
|
|
@ -414,6 +432,7 @@ jobs:
|
||||||
yarn_test_build_prod:
|
yarn_test_build_prod:
|
||||||
docker: *docker
|
docker: *docker
|
||||||
environment: *environment
|
environment: *environment
|
||||||
|
parallelism: *TEST_PARALLELISM
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- attach_workspace: *attach_workspace
|
- attach_workspace: *attach_workspace
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,10 @@ function runJest(testFile) {
|
||||||
cwd,
|
cwd,
|
||||||
env: Object.assign({}, process.env, {
|
env: Object.assign({}, process.env, {
|
||||||
REACT_CLASS_EQUIVALENCE_TEST: 'true',
|
REACT_CLASS_EQUIVALENCE_TEST: 'true',
|
||||||
|
// Remove these so that the test file is not filtered out by the mechanism
|
||||||
|
// we use to parallelize tests in CI
|
||||||
|
CIRCLE_NODE_TOTAL: '',
|
||||||
|
CIRCLE_NODE_INDEX: '',
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ module.exports = {
|
||||||
timers: 'fake',
|
timers: 'fake',
|
||||||
snapshotSerializers: [require.resolve('jest-snapshot-serializer-raw')],
|
snapshotSerializers: [require.resolve('jest-snapshot-serializer-raw')],
|
||||||
|
|
||||||
|
testSequencer: require.resolve('./jestSequencer'),
|
||||||
|
|
||||||
// TODO: Upgrade to Jest 26 which uses jsdom 16 by default.
|
// TODO: Upgrade to Jest 26 which uses jsdom 16 by default.
|
||||||
testEnvironment: require.resolve('jest-environment-jsdom-sixteen'),
|
testEnvironment: require.resolve('jest-environment-jsdom-sixteen'),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
19
scripts/jest/jestSequencer.js
Normal file
19
scripts/jest/jestSequencer.js
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Sequencer = require('@jest/test-sequencer').default;
|
||||||
|
|
||||||
|
class CustomSequencer extends Sequencer {
|
||||||
|
sort(tests) {
|
||||||
|
if (process.env.CIRCLE_NODE_TOTAL) {
|
||||||
|
// In CI, parallelize tests across multiple tasks.
|
||||||
|
const nodeTotal = parseInt(process.env.CIRCLE_NODE_TOTAL, 10);
|
||||||
|
const nodeIndex = parseInt(process.env.CIRCLE_NODE_INDEX, 10);
|
||||||
|
tests = tests
|
||||||
|
.sort((a, b) => (a.path < b.path ? -1 : 1))
|
||||||
|
.filter((_, i) => i % nodeTotal === nodeIndex);
|
||||||
|
}
|
||||||
|
return tests;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = CustomSequencer;
|
||||||
Loading…
Reference in New Issue
Block a user