mirror of https://github.com/facebook/jest.git
feat(jest-core): Add support for testSequencer written in ESM (#11207)
This commit is contained in:
parent
0e2d4552be
commit
2d96526149
|
@ -14,6 +14,7 @@
|
|||
- `[jest-core]` make `TestWatcher` extend `emittery` ([#10324](https://github.com/facebook/jest/pull/10324))
|
||||
- `[jest-core]` Run failed tests interactively the same way we do with snapshots ([#10858](https://github.com/facebook/jest/pull/10858))
|
||||
- `[jest-core]` more `TestSequencer` methods can be async ([#10980](https://github.com/facebook/jest/pull/10980))
|
||||
- `[jest-core]` Add support for `testSequencer` written in ESM ([#11207](https://github.com/facebook/jest/pull/11207))
|
||||
- `[jest-environment-node]` Add AbortController to globals ([#11182](https://github.com/facebook/jest/pull/11182))
|
||||
- `[@jest/fake-timers]` Update to `@sinonjs/fake-timers` to v7 ([#11198](https://github.com/facebook/jest/pull/11198))
|
||||
- `[jest-haste-map]` Handle injected scm clocks ([#10966](https://github.com/facebook/jest/pull/10966))
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import * as path from 'path';
|
||||
import {onNodeVersions} from '@jest/test-utils';
|
||||
import {extractSummary} from '../Utils';
|
||||
import runJest from '../runJest';
|
||||
const dir = path.resolve(__dirname, '../custom-esm-test-sequencer');
|
||||
|
||||
onNodeVersions('^12.16.0 || >=13.7.0', () => {
|
||||
test('run prioritySequence', () => {
|
||||
const result = runJest(dir, ['-i'], {
|
||||
nodeOptions: '--experimental-vm-modules --no-warnings',
|
||||
});
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
const sequence = extractSummary(result.stderr)
|
||||
.rest.replace(/PASS /g, '')
|
||||
.split('\n');
|
||||
expect(sequence).toEqual([
|
||||
'./a.test.js',
|
||||
'./b.test.js',
|
||||
'./c.test.js',
|
||||
'./d.test.js',
|
||||
'./e.test.js',
|
||||
]);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
test('a', () => {});
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
test('b', () => {});
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
test('c', () => {});
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
test('d', () => {});
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
test('e', () => {});
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"type": "module",
|
||||
"jest": {
|
||||
"testEnvironment": "node",
|
||||
"transform": {},
|
||||
"testSequencer": "<rootDir>/testSequencer.mjs"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import Sequencer from '@jest/test-sequencer';
|
||||
|
||||
export default class CustomSequencer extends Sequencer.default {
|
||||
sort(tests) {
|
||||
const copyTests = Array.from(tests);
|
||||
return copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1));
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@ import type {Config} from '@jest/types';
|
|||
import type {ChangedFiles, ChangedFilesPromise} from 'jest-changed-files';
|
||||
import type {Test} from 'jest-runner';
|
||||
import type {Context} from 'jest-runtime';
|
||||
import {interopRequireDefault, tryRealpath} from 'jest-util';
|
||||
import {requireOrImportModule, tryRealpath} from 'jest-util';
|
||||
import {JestHook, JestHookEmitter} from 'jest-watcher';
|
||||
import type FailedTestsCache from './FailedTestsCache';
|
||||
import SearchSource from './SearchSource';
|
||||
|
@ -142,9 +142,9 @@ export default async function runJest({
|
|||
failedTestsCache?: FailedTestsCache;
|
||||
filter?: Filter;
|
||||
}): Promise<void> {
|
||||
const Sequencer: typeof TestSequencer = interopRequireDefault(
|
||||
require(globalConfig.testSequencer),
|
||||
).default;
|
||||
const Sequencer: typeof TestSequencer = await requireOrImportModule(
|
||||
globalConfig.testSequencer,
|
||||
);
|
||||
const sequencer = new Sequencer();
|
||||
let allTests: Array<Test> = [];
|
||||
|
||||
|
|
Loading…
Reference in New Issue