Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallelize Jest in CI #19552

Merged
merged 1 commit into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
acdlite marked this conversation as resolved.
Show resolved Hide resolved
// 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;