File tree 10 files changed +95
-4
lines changed
custom-esm-test-sequencer
10 files changed +95
-4
lines changed Original file line number Diff line number Diff line change 14
14
- ` [jest-core] ` make ` TestWatcher ` extend ` emittery ` ([ #10324 ] ( https://github.com/facebook/jest/pull/10324 ) )
15
15
- ` [jest-core] ` Run failed tests interactively the same way we do with snapshots ([ #10858 ] ( https://github.com/facebook/jest/pull/10858 ) )
16
16
- ` [jest-core] ` more ` TestSequencer ` methods can be async ([ #10980 ] ( https://github.com/facebook/jest/pull/10980 ) )
17
+ - ` [jest-core] ` Add support for ` testSequencer ` written in ESM ([ #11207 ] ( https://github.com/facebook/jest/pull/11207 ) )
17
18
- ` [jest-environment-node] ` Add AbortController to globals ([ #11182 ] ( https://github.com/facebook/jest/pull/11182 ) )
18
19
- ` [@jest/fake-timers] ` Update to ` @sinonjs/fake-timers ` to v7 ([ #11198 ] ( https://github.com/facebook/jest/pull/11198 ) )
19
20
- ` [jest-haste-map] ` Handle injected scm clocks ([ #10966 ] ( https://github.com/facebook/jest/pull/10966 ) )
Original file line number Diff line number Diff line change
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 * as path from 'path' ;
9
+ import { onNodeVersions } from '@jest/test-utils' ;
10
+ import { extractSummary } from '../Utils' ;
11
+ import runJest from '../runJest' ;
12
+ const dir = path . resolve ( __dirname , '../custom-esm-test-sequencer' ) ;
13
+
14
+ onNodeVersions ( '^12.16.0 || >=13.7.0' , ( ) => {
15
+ test ( 'run prioritySequence' , ( ) => {
16
+ const result = runJest ( dir , [ '-i' ] , {
17
+ nodeOptions : '--experimental-vm-modules --no-warnings' ,
18
+ } ) ;
19
+
20
+ expect ( result . exitCode ) . toBe ( 0 ) ;
21
+ const sequence = extractSummary ( result . stderr )
22
+ . rest . replace ( / P A S S / g, '' )
23
+ . split ( '\n' ) ;
24
+ expect ( sequence ) . toEqual ( [
25
+ './a.test.js' ,
26
+ './b.test.js' ,
27
+ './c.test.js' ,
28
+ './d.test.js' ,
29
+ './e.test.js' ,
30
+ ] ) ;
31
+ } ) ;
32
+ } ) ;
Original file line number Diff line number Diff line change
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' , ( ) => { } ) ;
Original file line number Diff line number Diff line change
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' , ( ) => { } ) ;
Original file line number Diff line number Diff line change
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' , ( ) => { } ) ;
Original file line number Diff line number Diff line change
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' , ( ) => { } ) ;
Original file line number Diff line number Diff line change
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' , ( ) => { } ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "type" : " module" ,
3
+ "jest" : {
4
+ "testEnvironment" : " node" ,
5
+ "transform" : {},
6
+ "testSequencer" : " <rootDir>/testSequencer.mjs"
7
+ }
8
+ }
Original file line number Diff line number Diff line change
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 Sequencer from '@jest/test-sequencer' ;
9
+
10
+ export default class CustomSequencer extends Sequencer . default {
11
+ sort ( tests ) {
12
+ const copyTests = Array . from ( tests ) ;
13
+ return copyTests . sort ( ( testA , testB ) => ( testA . path > testB . path ? 1 : - 1 ) ) ;
14
+ }
15
+ }
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ import type {Config} from '@jest/types';
20
20
import type { ChangedFiles , ChangedFilesPromise } from 'jest-changed-files' ;
21
21
import type { Test } from 'jest-runner' ;
22
22
import type { Context } from 'jest-runtime' ;
23
- import { interopRequireDefault , tryRealpath } from 'jest-util' ;
23
+ import { requireOrImportModule , tryRealpath } from 'jest-util' ;
24
24
import { JestHook , JestHookEmitter } from 'jest-watcher' ;
25
25
import type FailedTestsCache from './FailedTestsCache' ;
26
26
import SearchSource from './SearchSource' ;
@@ -142,9 +142,9 @@ export default async function runJest({
142
142
failedTestsCache ?: FailedTestsCache ;
143
143
filter ?: Filter ;
144
144
} ) : Promise < void > {
145
- const Sequencer : typeof TestSequencer = interopRequireDefault (
146
- require ( globalConfig . testSequencer ) ,
147
- ) . default ;
145
+ const Sequencer : typeof TestSequencer = await requireOrImportModule (
146
+ globalConfig . testSequencer ,
147
+ ) ;
148
148
const sequencer = new Sequencer ( ) ;
149
149
let allTests : Array < Test > = [ ] ;
150
150
You can’t perform that action at this time.
0 commit comments