File tree Expand file tree Collapse file tree 5 files changed +95
-1
lines changed Expand file tree Collapse file tree 5 files changed +95
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
### Features
4
4
5
+ - ` [jest-test-sequencer, jest-core] ` Exposes globalConfig & contexts to TestSequencer ([ #14535 ] ( https://github.com/jestjs/jest/pull/14535 ) )
6
+
5
7
### Fixes
6
8
7
9
- ` [jest-leak-detector] ` Make leak-detector more aggressive when running GC ([ #14526 ] ( https://github.com/jestjs/jest/pull/14526 ) )
Original file line number Diff line number Diff line change @@ -79,3 +79,55 @@ test('run failed tests async', () => {
79
79
. split ( '\n' ) ;
80
80
expect ( sequence ) . toEqual ( [ './c.test.js' , './d.test.js' ] ) ;
81
81
} ) ;
82
+
83
+ test ( 'run tests based on even seed' , ( ) => {
84
+ const result = runJest (
85
+ dir ,
86
+ [
87
+ '-i' ,
88
+ '--config' ,
89
+ JSON . stringify ( {
90
+ testSequencer : '<rootDir>/testSequencerWithSeed.js' ,
91
+ } ) ,
92
+ '--seed=2' ,
93
+ ] ,
94
+ { } ,
95
+ ) ;
96
+ expect ( result . exitCode ) . toBe ( 0 ) ;
97
+ const sequence = extractSummary ( result . stderr )
98
+ . rest . replace ( / P A S S / g, '' )
99
+ . split ( '\n' ) ;
100
+ expect ( sequence ) . toEqual ( [
101
+ './a.test.js' ,
102
+ './b.test.js' ,
103
+ './c.test.js' ,
104
+ './d.test.js' ,
105
+ './e.test.js' ,
106
+ ] ) ;
107
+ } ) ;
108
+
109
+ test ( 'run tests based on odd seed' , ( ) => {
110
+ const result = runJest (
111
+ dir ,
112
+ [
113
+ '-i' ,
114
+ '--config' ,
115
+ JSON . stringify ( {
116
+ testSequencer : '<rootDir>/testSequencerWithSeed.js' ,
117
+ } ) ,
118
+ '--seed=1' ,
119
+ ] ,
120
+ { } ,
121
+ ) ;
122
+ expect ( result . exitCode ) . toBe ( 0 ) ;
123
+ const sequence = extractSummary ( result . stderr )
124
+ . rest . replace ( / P A S S / g, '' )
125
+ . split ( '\n' ) ;
126
+ expect ( sequence ) . toEqual ( [
127
+ './e.test.js' ,
128
+ './d.test.js' ,
129
+ './c.test.js' ,
130
+ './b.test.js' ,
131
+ './a.test.js' ,
132
+ ] ) ;
133
+ } ) ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
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
+ const Sequencer = require ( '@jest/test-sequencer' ) . default ;
9
+
10
+ class CustomSequencer extends Sequencer {
11
+ constructor ( _options ) {
12
+ super ( _options ) ;
13
+ this . globalConfig = _options . globalConfig ;
14
+ }
15
+
16
+ sort ( tests ) {
17
+ const copyTests = Array . from ( tests ) ;
18
+ const seed = this . globalConfig . seed ;
19
+ const sortedTests = copyTests . sort ( ( testA , testB ) =>
20
+ testA . path > testB . path ? 1 : - 1 ,
21
+ ) ;
22
+
23
+ if ( seed % 2 === 0 ) {
24
+ return sortedTests ;
25
+ } else {
26
+ return sortedTests . reverse ( ) ;
27
+ }
28
+ }
29
+ }
30
+
31
+ module . exports = CustomSequencer ;
Original file line number Diff line number Diff line change @@ -159,7 +159,7 @@ export default async function runJest({
159
159
const Sequencer : typeof TestSequencer = await requireOrImportModule (
160
160
globalConfig . testSequencer ,
161
161
) ;
162
- const sequencer = new Sequencer ( ) ;
162
+ const sequencer = new Sequencer ( { contexts , globalConfig } ) ;
163
163
let allTests : Array < Test > = [ ] ;
164
164
165
165
if ( changedFilesPromise && globalConfig . watch ) {
Original file line number Diff line number Diff line change @@ -10,11 +10,17 @@ import * as path from 'path';
10
10
import * as fs from 'graceful-fs' ;
11
11
import slash = require( 'slash' ) ;
12
12
import type { AggregatedResult , Test , TestContext } from '@jest/test-result' ;
13
+ import type { Config } from '@jest/types' ;
13
14
import HasteMap from 'jest-haste-map' ;
14
15
15
16
const FAIL = 0 ;
16
17
const SUCCESS = 1 ;
17
18
19
+ export type TestSequencerOptions = {
20
+ contexts : ReadonlyArray < TestContext > ;
21
+ globalConfig : Config . GlobalConfig ;
22
+ } ;
23
+
18
24
type Cache = {
19
25
[ key : string ] :
20
26
| [ testStatus : typeof FAIL | typeof SUCCESS , testDuration : number ]
@@ -46,6 +52,9 @@ type ShardPositionOptions = ShardOptions & {
46
52
export default class TestSequencer {
47
53
private readonly _cache = new Map < TestContext , Cache > ( ) ;
48
54
55
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
56
+ constructor ( _options ?: TestSequencerOptions ) { }
57
+
49
58
_getCachePath ( testContext : TestContext ) : string {
50
59
const { config} = testContext ;
51
60
const HasteMapClass = HasteMap . getStatic ( config ) ;
You can’t perform that action at this time.
0 commit comments