Skip to content

Commit

Permalink
Parallelize Jest in CI (#19552)
Browse files Browse the repository at this point in the history
Uses CircleCI's `parallelism` key to split our test jobs across multiple
processes, like we do for the build job.
  • Loading branch information
acdlite authored Aug 7, 2020
1 parent 2d9ec91 commit 0cd9a6d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
21 changes: 20 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ aliases:
name: Install Packages
command: yarn --frozen-lockfile

- &TEST_PARALLELISM 20

- &attach_workspace
at: build

Expand Down Expand Up @@ -92,6 +94,7 @@ jobs:
RELEASE_CHANNEL_stable_yarn_test:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM

steps:
- checkout
Expand All @@ -102,6 +105,7 @@ jobs:
yarn_test:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
Expand All @@ -111,6 +115,7 @@ jobs:
RELEASE_CHANNEL_stable_yarn_test_www:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
Expand All @@ -120,6 +125,7 @@ jobs:
RELEASE_CHANNEL_stable_yarn_test_www_variant:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
Expand All @@ -129,6 +135,7 @@ jobs:
RELEASE_CHANNEL_stable_yarn_test_prod_www:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
Expand All @@ -138,6 +145,7 @@ jobs:
RELEASE_CHANNEL_stable_yarn_test_prod_www_variant:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
Expand All @@ -147,6 +155,7 @@ jobs:
yarn_test_www:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
Expand All @@ -156,6 +165,7 @@ jobs:
yarn_test_www_variant:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
Expand All @@ -165,6 +175,7 @@ jobs:
yarn_test_prod_www:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
Expand All @@ -174,6 +185,7 @@ jobs:
yarn_test_prod_www_variant:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
Expand All @@ -183,6 +195,7 @@ jobs:
RELEASE_CHANNEL_stable_yarn_test_persistent:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM

steps:
- checkout
Expand All @@ -193,6 +206,7 @@ jobs:
RELEASE_CHANNEL_stable_yarn_test_prod:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM

steps:
- checkout
Expand All @@ -203,6 +217,7 @@ jobs:
yarn_test_prod:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
Expand All @@ -212,7 +227,7 @@ jobs:
RELEASE_CHANNEL_stable_yarn_build:
docker: *docker
environment: *environment
parallelism: 20
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
Expand Down Expand Up @@ -344,6 +359,7 @@ jobs:
RELEASE_CHANNEL_stable_yarn_test_build:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
steps:
- checkout
- attach_workspace: *attach_workspace
Expand All @@ -354,6 +370,7 @@ jobs:
yarn_test_build:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
steps:
- checkout
- attach_workspace: *attach_workspace
Expand Down Expand Up @@ -404,6 +421,7 @@ jobs:
RELEASE_CHANNEL_stable_yarn_test_build_prod:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
steps:
- checkout
- attach_workspace: *attach_workspace
Expand All @@ -414,6 +432,7 @@ jobs:
yarn_test_build_prod:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
steps:
- checkout
- attach_workspace: *attach_workspace
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/__tests__/ReactClassEquivalence-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ function runJest(testFile) {
cwd,
env: Object.assign({}, process.env, {
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: '',
}),
});

Expand Down
2 changes: 2 additions & 0 deletions scripts/jest/config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = {
timers: 'fake',
snapshotSerializers: [require.resolve('jest-snapshot-serializer-raw')],

testSequencer: require.resolve('./jestSequencer'),

// TODO: Upgrade to Jest 26 which uses jsdom 16 by default.
testEnvironment: require.resolve('jest-environment-jsdom-sixteen'),
};
19 changes: 19 additions & 0 deletions scripts/jest/jestSequencer.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 0cd9a6d

Please sign in to comment.