Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- `[jest-config, jest-runtime]` Support ESM for files other than `.js` and `.mjs` ([#10823](https://github.com/facebook/jest/pull/10823))
- `[jest-config, jest-runtime]` [**BREAKING**] Use "modern" implementation as default for fake timers ([#10874](https://github.com/facebook/jest/pull/10874))
- `[jest-core]` make `TestWatcher` extend `emittery` ([#10324](https://github.com/facebook/jest/pull/10324))
- `[jest-core]` more `TestSequencer` methods can be async ([#10980](https://github.com/facebook/jest/pull/10980))
- `[jest-haste-map]` Handle injected scm clocks ([#10966](https://github.com/facebook/jest/pull/10966))
- `[jest-repl, jest-runner]` [**BREAKING**] Run transforms over environment ([#8751](https://github.com/facebook/jest/pull/8751))
- `[jest-runner]` [**BREAKING**] set exit code to 1 if test logs after teardown ([#10728](https://github.com/facebook/jest/pull/10728))
Expand Down
20 changes: 20 additions & 0 deletions e2e/__tests__/customTestSequencers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,23 @@ test('run prioritySequence first async', () => {
'./e.test.js',
]);
});

test('run failed tests async', () => {
const result = runJest(
dir,
[
'--onlyFailures',
'-i',
'--config',
JSON.stringify({
testSequencer: '<rootDir>/testSequencerAsync.js',
}),
],
{},
);
expect(result.exitCode).toBe(0);
const sequence = extractSummary(result.stderr)
.rest.replace(/PASS /g, '')
.split('\n');
expect(sequence).toEqual(['./c.test.js', './d.test.js']);
});
22 changes: 13 additions & 9 deletions e2e/custom-test-sequencer/testSequencerAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@

const Sequencer = require('@jest/test-sequencer').default;

const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

class CustomSequencer extends Sequencer {
sort(tests) {
return new Promise(resolve => {
setTimeout(() => {
const copyTests = Array.from(tests);
resolve(
copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1)),
);
}, 50);
});
async sort(tests) {
await sleep(50);
const copyTests = Array.from(tests);
return copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1));
}

async allFailedTests(tests) {
await sleep(50);
return tests.filter(
t => t.path.endsWith('c.test.js') || t.path.endsWith('d.test.js'),
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/jest-core/src/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default async function runJest({
if (failedTestsCache) {
allTests = failedTestsCache.filterTests(allTests);
} else {
allTests = sequencer.allFailedTests(allTests);
allTests = await sequencer.allFailedTests(allTests);
}
}

Expand Down Expand Up @@ -272,7 +272,7 @@ export default async function runJest({
testSchedulerContext,
).scheduleTests(allTests, testWatcher);

sequencer.cacheResults(allTests, results);
await sequencer.cacheResults(allTests, results);

if (hasTests) {
await runGlobalHook({allTests, globalConfig, moduleName: 'globalTeardown'});
Expand Down