Skip to content

Commit 2bc6280

Browse files
WeiAnAnSimenB
authored andcommitted
Add option testSequencer allow user use custom sequencer. (#8223)
1 parent ac9bbed commit 2bc6280

File tree

29 files changed

+207
-5
lines changed

29 files changed

+207
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
### Features
44

5+
- `[@jest/core, @jest/test-sequencer]` Move `testSequencer` to individual package `@jest/test-sequencer` ([#8223](https://github.com/facebook/jest/pull/8223))
6+
- `[@jest/core, jest-cli, jest-config]` Add option `testSequencer` allow user use custom sequencer. ([#8223](https://github.com/facebook/jest/pull/8223))
7+
58
### Fixes
69

710
### Chore & Maintenance

docs/CLI.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ An array of regexp pattern strings that is tested against all tests paths before
297297

298298
Lets you specify a custom test runner.
299299

300+
### `--testSequencer=<path>`
301+
302+
Lets you specify a custom test sequencer. Please refer to the documentation of the corresponding configuration property for details.
303+
300304
### `--updateSnapshot`
301305

302306
Alias: `-u`. Use this flag to re-record every snapshot that fails during this test run. Can be used together with a test suite pattern or with `--testNamePattern` to re-record snapshots.

docs/Configuration.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,31 @@ function testRunner(
10181018

10191019
An example of such function can be found in our default [jasmine2 test runner package](https://github.com/facebook/jest/blob/master/packages/jest-jasmine2/src/index.js).
10201020

1021+
### `testSequencer` [string]
1022+
1023+
Default: `@jest/test-sequencer`
1024+
1025+
This option allows you to use a custom sequencer instead of Jest's default.
1026+
1027+
Example:
1028+
1029+
Sort test path alphabetically
1030+
1031+
```js
1032+
const Sequencer = require('@jest/test-sequencer').default;
1033+
1034+
class CustomSequencer extends Sequencer {
1035+
sort(tests) {
1036+
// Test structure information
1037+
// https://github.com/facebook/jest/blob/6b8b1404a1d9254e7d5d90a8934087a9c9899dab/packages/jest-runner/src/types.ts#L17-L21
1038+
const copyTests = Array.from(tests);
1039+
return copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1));
1040+
}
1041+
}
1042+
1043+
module.exports = CustomSequencer;
1044+
```
1045+
10211046
### `testURL` [string]
10221047

10231048
Default: `http://localhost`

e2e/__tests__/__snapshots__/showConfig.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
117117
"testFailureExitCode": 1,
118118
"testPathPattern": "",
119119
"testResultsProcessor": null,
120+
"testSequencer": "@jest/test-sequencer",
120121
"updateSnapshot": "all",
121122
"useStderr": false,
122123
"verbose": null,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import path from 'path';
9+
import runJest from '../runJest';
10+
import {extractSummary} from '../Utils';
11+
const dir = path.resolve(__dirname, '../custom-test-sequencer');
12+
13+
test('run prioritySequence first', () => {
14+
const result = runJest(dir, ['-i']);
15+
expect(result.status).toBe(0);
16+
const sequence = extractSummary(result.stderr)
17+
.rest.replace(/PASS /g, '')
18+
.split('\n');
19+
expect(sequence).toEqual([
20+
'./a.test.js',
21+
'./b.test.js',
22+
'./c.test.js',
23+
'./d.test.js',
24+
'./e.test.js',
25+
]);
26+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
test('a', () => {});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
test('b', () => {});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
test('c', () => {});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
test('d', () => {});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
test('e', () => {});

0 commit comments

Comments
 (0)