From cac8a660cd7309b238cb0e8e9c2c9bafb56b5cd9 Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Wed, 27 Mar 2019 01:26:59 +0800 Subject: [PATCH 01/27] move testSequencer to individual package --- packages/jest-core/package.json | 1 + packages/jest-core/src/runJest.ts | 2 +- packages/jest-core/tsconfig.json | 1 + packages/jest-test-sequencer/.npmignore | 3 +++ packages/jest-test-sequencer/package.json | 25 +++++++++++++++++++ .../src/__tests__/test_sequencer.test.js | 2 +- .../src/index.ts} | 4 ++- packages/jest-test-sequencer/tsconfig.json | 13 ++++++++++ 8 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 packages/jest-test-sequencer/.npmignore create mode 100644 packages/jest-test-sequencer/package.json rename packages/{jest-core => jest-test-sequencer}/src/__tests__/test_sequencer.test.js (99%) rename packages/{jest-core/src/TestSequencer.ts => jest-test-sequencer/src/index.ts} (98%) create mode 100644 packages/jest-test-sequencer/tsconfig.json diff --git a/packages/jest-core/package.json b/packages/jest-core/package.json index e9056ba5018c..6e4c673d75ae 100644 --- a/packages/jest-core/package.json +++ b/packages/jest-core/package.json @@ -8,6 +8,7 @@ "@jest/console": "^24.3.0", "@jest/reporters": "^24.5.0", "@jest/test-result": "^24.5.0", + "@jest/test-sequencer": "^24.5.0", "@jest/transform": "^24.5.0", "@jest/types": "^24.5.0", "ansi-escapes": "^3.0.0", diff --git a/packages/jest-core/src/runJest.ts b/packages/jest-core/src/runJest.ts index fad2435d8ee0..6386f1e35517 100644 --- a/packages/jest-core/src/runJest.ts +++ b/packages/jest-core/src/runJest.ts @@ -25,7 +25,7 @@ import getNoTestsFoundMessage from './getNoTestsFoundMessage'; import runGlobalHook from './runGlobalHook'; import SearchSource from './SearchSource'; import TestScheduler, {TestSchedulerContext} from './TestScheduler'; -import TestSequencer from './TestSequencer'; +import TestSequencer from '@jest/test-sequencer'; import FailedTestsCache from './FailedTestsCache'; import collectNodeHandles from './collectHandles'; import TestWatcher from './TestWatcher'; diff --git a/packages/jest-core/tsconfig.json b/packages/jest-core/tsconfig.json index 79f9f35b848b..f943dccf39d0 100644 --- a/packages/jest-core/tsconfig.json +++ b/packages/jest-core/tsconfig.json @@ -17,6 +17,7 @@ {"path": "../jest-runtime"}, {"path": "../jest-snapshot"}, {"path": "../jest-test-result"}, + {"path": "../jest-test-sequencer"}, {"path": "../jest-types"}, {"path": "../jest-transform"}, {"path": "../jest-util"}, diff --git a/packages/jest-test-sequencer/.npmignore b/packages/jest-test-sequencer/.npmignore new file mode 100644 index 000000000000..85e48fe7b0a4 --- /dev/null +++ b/packages/jest-test-sequencer/.npmignore @@ -0,0 +1,3 @@ +**/__mocks__/** +**/__tests__/** +src diff --git a/packages/jest-test-sequencer/package.json b/packages/jest-test-sequencer/package.json new file mode 100644 index 000000000000..69327e50b91b --- /dev/null +++ b/packages/jest-test-sequencer/package.json @@ -0,0 +1,25 @@ +{ + "name": "@jest/test-sequencer", + "version": "24.5.0", + "repository": { + "type": "git", + "url": "https://github.com/facebook/jest.git", + "directory": "packages/test-sequencer" + }, + "license": "MIT", + "main": "build/index.js", + "types": "build/index.d.ts", + "dependencies": { + "@jest/test-result": "^24.5.0", + "jest-haste-map": "^24.5.0", + "jest-runtime": "^24.5.0", + "jest-runner": "^24.5.0" + }, + "engines": { + "node": ">= 6" + }, + "publishConfig": { + "access": "public" + }, + "gitHead": "800533020f5b2f153615c821ed7cb12fd868fa6f" +} diff --git a/packages/jest-core/src/__tests__/test_sequencer.test.js b/packages/jest-test-sequencer/src/__tests__/test_sequencer.test.js similarity index 99% rename from packages/jest-core/src/__tests__/test_sequencer.test.js rename to packages/jest-test-sequencer/src/__tests__/test_sequencer.test.js index 2e0c8d00f0ea..1252dc1e6e15 100644 --- a/packages/jest-core/src/__tests__/test_sequencer.test.js +++ b/packages/jest-test-sequencer/src/__tests__/test_sequencer.test.js @@ -6,7 +6,7 @@ */ 'use strict'; -import TestSequencer from '../TestSequencer'; +import TestSequencer from '../index'; jest.mock('fs'); diff --git a/packages/jest-core/src/TestSequencer.ts b/packages/jest-test-sequencer/src/index.ts similarity index 98% rename from packages/jest-core/src/TestSequencer.ts rename to packages/jest-test-sequencer/src/index.ts index fc1ef479c517..7dc25fde487f 100644 --- a/packages/jest-core/src/TestSequencer.ts +++ b/packages/jest-test-sequencer/src/index.ts @@ -31,7 +31,7 @@ type Cache = { * TestSequencer.cacheResults(tests: Array, results: AggregatedResult) * is called to store/update this information on the cache map. */ -export default class TestSequencer { +class TestSequencer { private _cache: Map = new Map(); _getCachePath(context: Context) { @@ -128,3 +128,5 @@ export default class TestSequencer { ); } } + +export = TestSequencer; diff --git a/packages/jest-test-sequencer/tsconfig.json b/packages/jest-test-sequencer/tsconfig.json new file mode 100644 index 000000000000..78fc3a6be9ed --- /dev/null +++ b/packages/jest-test-sequencer/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + }, + "references": [ + {"path": "../jest-haste-map"}, + {"path": "../jest-runner"}, + {"path": "../jest-test-result"}, + {"path": "../jest-types"} + ] +} From 27b7ebab888b4a78217c870c19d680d7753b341f Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Wed, 27 Mar 2019 01:41:11 +0800 Subject: [PATCH 02/27] add testSequencer option to let user use custom sequencer --- .../__snapshots__/showConfig.test.ts.snap | 1 + e2e/__tests__/customTestSequencers.test.ts | 42 ++++++ e2e/custom-test-sequencer/a.test.js | 1 + e2e/custom-test-sequencer/b.test.js | 1 + e2e/custom-test-sequencer/c.test.js | 1 + e2e/custom-test-sequencer/d.test.js | 1 + e2e/custom-test-sequencer/e.test.js | 1 + e2e/custom-test-sequencer/package.json | 6 + e2e/custom-test-sequencer/testSequencer.js | 125 ++++++++++++++++++ packages/jest-cli/src/cli/args.ts | 7 + packages/jest-config/src/Defaults.ts | 1 + packages/jest-config/src/ValidConfig.ts | 1 + packages/jest-config/src/index.ts | 1 + packages/jest-config/src/normalize.ts | 1 + .../jest-core/src/__tests__/run_jest.test.js | 2 +- packages/jest-core/src/runJest.ts | 3 +- packages/jest-types/src/Config.ts | 4 + 17 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 e2e/__tests__/customTestSequencers.test.ts create mode 100644 e2e/custom-test-sequencer/a.test.js create mode 100644 e2e/custom-test-sequencer/b.test.js create mode 100644 e2e/custom-test-sequencer/c.test.js create mode 100644 e2e/custom-test-sequencer/d.test.js create mode 100644 e2e/custom-test-sequencer/e.test.js create mode 100644 e2e/custom-test-sequencer/package.json create mode 100644 e2e/custom-test-sequencer/testSequencer.js diff --git a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap index 8b27dc1ba115..44f0f007f29a 100644 --- a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap +++ b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap @@ -117,6 +117,7 @@ exports[`--showConfig outputs config info and exits 1`] = ` "testFailureExitCode": 1, "testPathPattern": "", "testResultsProcessor": null, + "testSequencer": "@jest/test-sequencer", "updateSnapshot": "all", "useStderr": false, "verbose": null, diff --git a/e2e/__tests__/customTestSequencers.test.ts b/e2e/__tests__/customTestSequencers.test.ts new file mode 100644 index 000000000000..99fe4b326b5a --- /dev/null +++ b/e2e/__tests__/customTestSequencers.test.ts @@ -0,0 +1,42 @@ +/** + * 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 path from 'path'; +import runJest from '../runJest'; +import {extractSummary} from '../Utils'; +const dir = path.resolve(__dirname, '../custom-test-sequencer'); + +expect.extend({ + toBeIn(received, arr) { + const isIn = arr.includes(received); + if (isIn) + return { + message: `expect ${received} not to be in [${arr.join(', ')}]`, + pass: true, + }; + else + return { + message: `expect ${received} to be in [${arr.join(', ')}]`, + pass: false, + }; + }, +}); + +test('run prioritySequence first', () => { + const result = runJest(dir); + expect(result.status).toBe(0); + const sequence = extractSummary(result.stderr) + .rest.replace(/PASS /g, '') + .split('\n'); + expect(sequence).toEqual([ + './d.test.js', + './b.test.js', + './c.test.js', + expect.toBeIn(['./a.test.js', './e.test.js']), + expect.toBeIn(['./a.test.js', './e.test.js']), + ]); +}); diff --git a/e2e/custom-test-sequencer/a.test.js b/e2e/custom-test-sequencer/a.test.js new file mode 100644 index 000000000000..f624979c394a --- /dev/null +++ b/e2e/custom-test-sequencer/a.test.js @@ -0,0 +1 @@ +test('a', () => {}); diff --git a/e2e/custom-test-sequencer/b.test.js b/e2e/custom-test-sequencer/b.test.js new file mode 100644 index 000000000000..f809da6a6962 --- /dev/null +++ b/e2e/custom-test-sequencer/b.test.js @@ -0,0 +1 @@ +test('b', () => {}); diff --git a/e2e/custom-test-sequencer/c.test.js b/e2e/custom-test-sequencer/c.test.js new file mode 100644 index 000000000000..cb4854cfb2c9 --- /dev/null +++ b/e2e/custom-test-sequencer/c.test.js @@ -0,0 +1 @@ +test('c', () => {}); diff --git a/e2e/custom-test-sequencer/d.test.js b/e2e/custom-test-sequencer/d.test.js new file mode 100644 index 000000000000..5b88b3563be6 --- /dev/null +++ b/e2e/custom-test-sequencer/d.test.js @@ -0,0 +1 @@ +test('d', () => {}); diff --git a/e2e/custom-test-sequencer/e.test.js b/e2e/custom-test-sequencer/e.test.js new file mode 100644 index 000000000000..a1bc20bfe046 --- /dev/null +++ b/e2e/custom-test-sequencer/e.test.js @@ -0,0 +1 @@ +test('e', () => {}); diff --git a/e2e/custom-test-sequencer/package.json b/e2e/custom-test-sequencer/package.json new file mode 100644 index 000000000000..80ef569e593c --- /dev/null +++ b/e2e/custom-test-sequencer/package.json @@ -0,0 +1,6 @@ +{ + "jest": { + "testEnvironment": "node", + "testSequencer": "/testSequencer.js" + } +} diff --git a/e2e/custom-test-sequencer/testSequencer.js b/e2e/custom-test-sequencer/testSequencer.js new file mode 100644 index 000000000000..61e1deea40dc --- /dev/null +++ b/e2e/custom-test-sequencer/testSequencer.js @@ -0,0 +1,125 @@ +/** + * 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. + */ + +const fs = require('fs'); +const path = require('path'); +const {getCacheFilePath} = require('../../packages/jest-haste-map/build'); + +const priorityOrder = [ + path.resolve('./d.test.js'), + path.resolve('./b.test.js'), + path.resolve('./c.test.js'), +]; +const FAIL = 0; +const SUCCESS = 1; + +class TestSequencer { + constructor() { + this._cache = new Map(); + } + _getCachePath(context) { + const {config} = context; + return getCacheFilePath(config.cacheDirectory, 'perf-cache-' + config.name); + } + + _getCache(test) { + const {context} = test; + if (!this._cache.has(context) && context.config.cache) { + const cachePath = this._getCachePath(context); + if (fs.existsSync(cachePath)) { + try { + this._cache.set( + context, + JSON.parse(fs.readFileSync(cachePath, 'utf8')) + ); + } catch (e) {} + } + } + + let cache = this._cache.get(context); + if (!cache) { + cache = {}; + this._cache.set(context, cache); + } + + return cache; + } + + /** + * Sorting tests is very important because it has a great impact on the + * user-perceived responsiveness and speed of the test run. + * + * If such information is on cache, tests are sorted based on: + * -> Has it failed during the last run ? + * Since it's important to provide the most expected feedback as quickly + * as possible. + * -> How long it took to run ? + * Because running long tests first is an effort to minimize worker idle + * time at the end of a long test run. + * And if that information is not available they are sorted based on file size + * since big test files usually take longer to complete. + * + * Note that a possible improvement would be to analyse other information + * from the file other than its size. + * + */ + sort(tests) { + const stats = {}; + const fileSize = ({path, context: {hasteFS}}) => + stats[path] || (stats[path] = hasteFS.getSize(path) || 0); + const hasFailed = (cache, test) => + cache[test.path] && cache[test.path][0] === FAIL; + const time = (cache, test) => cache[test.path] && cache[test.path][1]; + + tests.forEach(test => (test.duration = time(this._getCache(test), test))); + return tests.sort((testA, testB) => { + const cacheA = this._getCache(testA); + const cacheB = this._getCache(testB); + const failedA = hasFailed(cacheA, testA); + const failedB = hasFailed(cacheB, testB); + const hasTimeA = testA.duration != null; + const indexA = priorityOrder.indexOf(testA.path); + const indexB = priorityOrder.indexOf(testB.path); + + if (indexA !== indexB) { + if (indexA === -1) return 1; + if (indexB === -1) return -1; + return indexA < indexB ? -1 : 1; + } else if (failedA !== failedB) { + return failedA ? -1 : 1; + } else if (hasTimeA != (testB.duration != null)) { + // If only one of two tests has timing information, run it last + return hasTimeA ? 1 : -1; + } else if (testA.duration != null && testB.duration != null) { + return testA.duration < testB.duration ? 1 : -1; + } else { + return fileSize(testA) < fileSize(testB) ? 1 : -1; + } + }); + } + + cacheResults(tests, results) { + const map = Object.create(null); + tests.forEach(test => (map[test.path] = test)); + results.testResults.forEach(testResult => { + if (testResult && map[testResult.testFilePath] && !testResult.skipped) { + const cache = this._getCache(map[testResult.testFilePath]); + const perf = testResult.perfStats; + cache[testResult.testFilePath] = [ + testResult.numFailingTests ? FAIL : SUCCESS, + perf.end - perf.start || 0, + ]; + } + }); + + this._cache.forEach((cache, context) => + fs.writeFileSync(this._getCachePath(context), JSON.stringify(cache)) + ); + } +} + +module.exports = TestSequencer; diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index b98baa1791b1..41bcdc2f5d81 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -615,6 +615,13 @@ export const options = { '`/path/to/testRunner.js`.', type: 'string' as 'string', }, + testSequencer: { + description: + 'Allows to specify a custom test sequencer. The default is ' + + '`jest-test-sequencer`. A path to a custom test sequencer can be ' + + 'provided: `/path/to/testSequencer.js`', + type: 'string' as 'string', + }, testURL: { description: 'This option sets the URL for the jsdom environment.', type: 'string' as 'string', diff --git a/packages/jest-config/src/Defaults.ts b/packages/jest-config/src/Defaults.ts index 10fed37c6da5..18feac7a11c0 100644 --- a/packages/jest-config/src/Defaults.ts +++ b/packages/jest-config/src/Defaults.ts @@ -72,6 +72,7 @@ const defaultOptions: Config.DefaultOptions = { testRegex: [], testResultsProcessor: null, testRunner: 'jasmine2', + testSequencer: '@jest/test-sequencer', testURL: 'http://localhost', timers: 'real', transform: null, diff --git a/packages/jest-config/src/ValidConfig.ts b/packages/jest-config/src/ValidConfig.ts index fb25df1599bc..544ad1840cd9 100644 --- a/packages/jest-config/src/ValidConfig.ts +++ b/packages/jest-config/src/ValidConfig.ts @@ -112,6 +112,7 @@ const initialOptions: Config.InitialOptions = { ), testResultsProcessor: 'processor-node-module', testRunner: 'jasmine2', + testSequencer: '@jest/test-sequencer', testURL: 'http://localhost', timers: 'real', transform: { diff --git a/packages/jest-config/src/index.ts b/packages/jest-config/src/index.ts index 45bebcafcdac..9f929864554b 100644 --- a/packages/jest-config/src/index.ts +++ b/packages/jest-config/src/index.ts @@ -148,6 +148,7 @@ const groupOptions = ( testNamePattern: options.testNamePattern, testPathPattern: options.testPathPattern, testResultsProcessor: options.testResultsProcessor, + testSequencer: options.testSequencer, updateSnapshot: options.updateSnapshot, useStderr: options.useStderr, verbose: options.verbose, diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index e43bd523af8a..7bad95fb0d0f 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -571,6 +571,7 @@ export default function normalize( case 'snapshotResolver': case 'testResultsProcessor': case 'testRunner': + case 'testSequencer': case 'filter': { const option = oldOptions[key]; diff --git a/packages/jest-core/src/__tests__/run_jest.test.js b/packages/jest-core/src/__tests__/run_jest.test.js index 3c4c6d170cbc..3293dd4fbcbc 100644 --- a/packages/jest-core/src/__tests__/run_jest.test.js +++ b/packages/jest-core/src/__tests__/run_jest.test.js @@ -16,7 +16,7 @@ describe('runJest', () => { await runJest({ changedFilesPromise: Promise.resolve({repos: {git: {size: 0}}}), contexts: [], - globalConfig: {watch: true}, + globalConfig: {testSequencer: '@jest/test-sequencer', watch: true}, onComplete: () => null, outputStream: {}, startRun: {}, diff --git a/packages/jest-core/src/runJest.ts b/packages/jest-core/src/runJest.ts index 6386f1e35517..c1046afe8567 100644 --- a/packages/jest-core/src/runJest.ts +++ b/packages/jest-core/src/runJest.ts @@ -143,7 +143,8 @@ export default (async function runJest({ failedTestsCache?: FailedTestsCache; filter?: Filter; }) { - const sequencer = new TestSequencer(); + const Sequencer: typeof TestSequencer = require(globalConfig.testSequencer); + const sequencer = new Sequencer(); let allTests: Array = []; if (changedFilesPromise && globalConfig.watch) { diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index 76e4d06ef343..f3f4142f1e61 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -89,6 +89,7 @@ export type DefaultOptions = { testRegex: Array; testResultsProcessor: string | null | undefined; testRunner: string | null | undefined; + testSequencer: string; testURL: string; timers: 'real' | 'fake'; transform: @@ -197,6 +198,7 @@ export type InitialOptions = { testRegex?: string | Array; testResultsProcessor?: string | null | undefined; testRunner?: string; + testSequencer?: string; testURL?: string; timers?: 'real' | 'fake'; transform?: { @@ -293,6 +295,7 @@ export type GlobalConfig = { testNamePattern: string; testPathPattern: string; testResultsProcessor: string | null | undefined; + testSequencer: string; updateSnapshot: SnapshotUpdateState; useStderr: boolean; verbose: boolean | null | undefined; @@ -436,6 +439,7 @@ export type Argv = Arguments< testRegex: string | Array; testResultsProcessor: string | null | undefined; testRunner: string; + testSequencer: string; testURL: string; timers: string; transform: string; From 4b12436b3811fb69e0a0bfed6fdc9853521bb420 Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Wed, 27 Mar 2019 02:10:47 +0800 Subject: [PATCH 03/27] giving testSequencer own normalize function --- packages/jest-config/src/normalize.ts | 13 ++++++++++++- packages/jest-config/src/utils.ts | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index 7bad95fb0d0f..99ec941516f1 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -28,6 +28,7 @@ import { getRunner, getWatchPlugin, resolve, + getSequencer, } from './utils'; import {DEFAULT_JS_PATTERN, DEFAULT_REPORTER_LABEL} from './constants'; import {validateReporters} from './ReporterValidationErrors'; @@ -571,7 +572,6 @@ export default function normalize( case 'snapshotResolver': case 'testResultsProcessor': case 'testRunner': - case 'testSequencer': case 'filter': { const option = oldOptions[key]; @@ -595,6 +595,17 @@ export default function normalize( }); } break; + case 'testSequencer': + { + const option = oldOptions[key]; + value = + option && + getSequencer(newOptions.resolver, { + filePath: option, + rootDir: options.rootDir, + }); + } + break; case 'prettierPath': { // We only want this to throw if "prettierPath" is explicitly passed diff --git a/packages/jest-config/src/utils.ts b/packages/jest-config/src/utils.ts index ca7c5d9d0047..9308f99b6c7d 100644 --- a/packages/jest-config/src/utils.ts +++ b/packages/jest-config/src/utils.ts @@ -223,3 +223,15 @@ export const isJSONString = (text?: JSONString | string): text is JSONString => typeof text === 'string' && text.startsWith('{') && text.endsWith('}'); + +export const getSequencer = ( + resolver: string | undefined | null, + {filePath, rootDir}: {filePath: string; rootDir: Config.Path}, +) => + resolveWithPrefix(resolver, { + filePath, + humanOptionName: 'Jest Sequencer', + optionName: 'sequencer', + prefix: 'jest-sequencer-', + rootDir, + }); From aeea6ade0b10d5c6c32580b343cf7c69c12b684d Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Wed, 27 Mar 2019 02:35:13 +0800 Subject: [PATCH 04/27] lint --- e2e/custom-test-sequencer/a.test.js | 6 ++++++ e2e/custom-test-sequencer/b.test.js | 6 ++++++ e2e/custom-test-sequencer/c.test.js | 6 ++++++ e2e/custom-test-sequencer/d.test.js | 6 ++++++ e2e/custom-test-sequencer/e.test.js | 6 ++++++ packages/jest-core/src/runJest.ts | 2 +- 6 files changed, 31 insertions(+), 1 deletion(-) diff --git a/e2e/custom-test-sequencer/a.test.js b/e2e/custom-test-sequencer/a.test.js index f624979c394a..1187e8309f87 100644 --- a/e2e/custom-test-sequencer/a.test.js +++ b/e2e/custom-test-sequencer/a.test.js @@ -1 +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', () => {}); diff --git a/e2e/custom-test-sequencer/b.test.js b/e2e/custom-test-sequencer/b.test.js index f809da6a6962..04e77e777bb1 100644 --- a/e2e/custom-test-sequencer/b.test.js +++ b/e2e/custom-test-sequencer/b.test.js @@ -1 +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', () => {}); diff --git a/e2e/custom-test-sequencer/c.test.js b/e2e/custom-test-sequencer/c.test.js index cb4854cfb2c9..332d8682ab00 100644 --- a/e2e/custom-test-sequencer/c.test.js +++ b/e2e/custom-test-sequencer/c.test.js @@ -1 +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', () => {}); diff --git a/e2e/custom-test-sequencer/d.test.js b/e2e/custom-test-sequencer/d.test.js index 5b88b3563be6..4102fe8c1925 100644 --- a/e2e/custom-test-sequencer/d.test.js +++ b/e2e/custom-test-sequencer/d.test.js @@ -1 +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', () => {}); diff --git a/e2e/custom-test-sequencer/e.test.js b/e2e/custom-test-sequencer/e.test.js index a1bc20bfe046..6b4bbf07b9b4 100644 --- a/e2e/custom-test-sequencer/e.test.js +++ b/e2e/custom-test-sequencer/e.test.js @@ -1 +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', () => {}); diff --git a/packages/jest-core/src/runJest.ts b/packages/jest-core/src/runJest.ts index c1046afe8567..2123e0a0bc37 100644 --- a/packages/jest-core/src/runJest.ts +++ b/packages/jest-core/src/runJest.ts @@ -20,12 +20,12 @@ import { AggregatedResult, makeEmptyAggregatedTestResult, } from '@jest/test-result'; +import TestSequencer from '@jest/test-sequencer'; import {ChangedFiles, ChangedFilesPromise} from 'jest-changed-files'; import getNoTestsFoundMessage from './getNoTestsFoundMessage'; import runGlobalHook from './runGlobalHook'; import SearchSource from './SearchSource'; import TestScheduler, {TestSchedulerContext} from './TestScheduler'; -import TestSequencer from '@jest/test-sequencer'; import FailedTestsCache from './FailedTestsCache'; import collectNodeHandles from './collectHandles'; import TestWatcher from './TestWatcher'; From 5093f46cf931d5c939fcea60cfafd17ff0e2b67a Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Wed, 27 Mar 2019 10:39:27 +0800 Subject: [PATCH 05/27] remove test comment --- e2e/custom-test-sequencer/testSequencer.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/e2e/custom-test-sequencer/testSequencer.js b/e2e/custom-test-sequencer/testSequencer.js index 61e1deea40dc..892e334ba522 100644 --- a/e2e/custom-test-sequencer/testSequencer.js +++ b/e2e/custom-test-sequencer/testSequencer.js @@ -49,24 +49,6 @@ class TestSequencer { return cache; } - /** - * Sorting tests is very important because it has a great impact on the - * user-perceived responsiveness and speed of the test run. - * - * If such information is on cache, tests are sorted based on: - * -> Has it failed during the last run ? - * Since it's important to provide the most expected feedback as quickly - * as possible. - * -> How long it took to run ? - * Because running long tests first is an effort to minimize worker idle - * time at the end of a long test run. - * And if that information is not available they are sorted based on file size - * since big test files usually take longer to complete. - * - * Note that a possible improvement would be to analyse other information - * from the file other than its size. - * - */ sort(tests) { const stats = {}; const fileSize = ({path, context: {hasteFS}}) => From b94e545785c7bd70b15815b5bde0c04c5d29d434 Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Wed, 27 Mar 2019 10:40:08 +0800 Subject: [PATCH 06/27] keep export default --- packages/jest-test-sequencer/src/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/jest-test-sequencer/src/index.ts b/packages/jest-test-sequencer/src/index.ts index 7dc25fde487f..fc1ef479c517 100644 --- a/packages/jest-test-sequencer/src/index.ts +++ b/packages/jest-test-sequencer/src/index.ts @@ -31,7 +31,7 @@ type Cache = { * TestSequencer.cacheResults(tests: Array, results: AggregatedResult) * is called to store/update this information on the cache map. */ -class TestSequencer { +export default class TestSequencer { private _cache: Map = new Map(); _getCachePath(context: Context) { @@ -128,5 +128,3 @@ class TestSequencer { ); } } - -export = TestSequencer; From ca3305e579122aff8c9e111ca6503b1952d18818 Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Wed, 27 Mar 2019 10:41:21 +0800 Subject: [PATCH 07/27] use interopRequireDefault to import package --- packages/jest-core/src/runJest.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/jest-core/src/runJest.ts b/packages/jest-core/src/runJest.ts index 2123e0a0bc37..ce61fdecbf32 100644 --- a/packages/jest-core/src/runJest.ts +++ b/packages/jest-core/src/runJest.ts @@ -9,7 +9,7 @@ import path from 'path'; import chalk from 'chalk'; import {sync as realpath} from 'realpath-native'; import {CustomConsole} from '@jest/console'; -import {formatTestResults} from 'jest-util'; +import {formatTestResults, interopRequireDefault} from 'jest-util'; import exit from 'exit'; import fs from 'graceful-fs'; import {JestHook, JestHookEmitter} from 'jest-watcher'; @@ -143,7 +143,9 @@ export default (async function runJest({ failedTestsCache?: FailedTestsCache; filter?: Filter; }) { - const Sequencer: typeof TestSequencer = require(globalConfig.testSequencer); + const Sequencer: typeof TestSequencer = interopRequireDefault( + require(globalConfig.testSequencer), + ).default; const sequencer = new Sequencer(); let allTests: Array = []; From b5c593a668ee170e98fc671084c4b39d515e784e Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Wed, 27 Mar 2019 10:41:41 +0800 Subject: [PATCH 08/27] correct `testSequencer` default package name --- packages/jest-cli/src/cli/args.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index 41bcdc2f5d81..4c68b6e1a9c9 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -618,7 +618,7 @@ export const options = { testSequencer: { description: 'Allows to specify a custom test sequencer. The default is ' + - '`jest-test-sequencer`. A path to a custom test sequencer can be ' + + '`@jest/test-sequencer`. A path to a custom test sequencer can be ' + 'provided: `/path/to/testSequencer.js`', type: 'string' as 'string', }, From 92234893d07d3b1ed10c0669484b542cd254693a Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Wed, 27 Mar 2019 10:44:26 +0800 Subject: [PATCH 09/27] add runInBand arg to assure running test in sequence --- e2e/__tests__/customTestSequencers.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/__tests__/customTestSequencers.test.ts b/e2e/__tests__/customTestSequencers.test.ts index 99fe4b326b5a..421b5221368f 100644 --- a/e2e/__tests__/customTestSequencers.test.ts +++ b/e2e/__tests__/customTestSequencers.test.ts @@ -27,7 +27,7 @@ expect.extend({ }); test('run prioritySequence first', () => { - const result = runJest(dir); + const result = runJest(dir, ['-i']); expect(result.status).toBe(0); const sequence = extractSummary(result.stderr) .rest.replace(/PASS /g, '') From ec029bbea0313e6dae5f72a0b6f2670c44525b89 Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Wed, 27 Mar 2019 10:56:59 +0800 Subject: [PATCH 10/27] update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 944c19d56f65..06ecc70dab33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ - `[jest-runner]` Support default exports for test environments ([#8163](https://github.com/facebook/jest/pull/8163)) - `[pretty-format]` Support React.Suspense ([#8180](https://github.com/facebook/jest/pull/8180)) - `[jest-snapshot]` Indent inline snapshots ([#8198](https://github.com/facebook/jest/pull/8198)) +- `[@jest/core]` Move `testSequencer` to individual package `@jest/test-sequencer` ([#8223](https://github.com/facebook/jest/pull/8223)) +- `[@jest/test-sequencer]` Move `testSequencer` to individual package `@jest/test-sequencer` ([#8223](https://github.com/facebook/jest/pull/8223)) +- `[@jest/core]` Add option `testSequencer` allow user use custom sequencer. ([#8223](https://github.com/facebook/jest/pull/8223)) +- `[jest-config]` Add option `testSequencer` allow user use custom sequencer. ([#8223](https://github.com/facebook/jest/pull/8223)) +- `[jest-cli]` Add option `testSequencer` allow user use custom sequencer. ([#8223](https://github.com/facebook/jest/pull/8223)) ### Fixes From 02f14fa3a66e6754179daf0fcc63af3dbb2207cd Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Wed, 27 Mar 2019 18:17:22 +0800 Subject: [PATCH 11/27] just only implement sort function in test --- e2e/custom-test-sequencer/testSequencer.js | 58 ++-------------------- 1 file changed, 3 insertions(+), 55 deletions(-) diff --git a/e2e/custom-test-sequencer/testSequencer.js b/e2e/custom-test-sequencer/testSequencer.js index 892e334ba522..3d3235d4f312 100644 --- a/e2e/custom-test-sequencer/testSequencer.js +++ b/e2e/custom-test-sequencer/testSequencer.js @@ -5,9 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -const fs = require('fs'); +const Sequencer = require('@jest/test-sequencer').default; const path = require('path'); -const {getCacheFilePath} = require('../../packages/jest-haste-map/build'); const priorityOrder = [ path.resolve('./d.test.js'), @@ -15,40 +14,8 @@ const priorityOrder = [ path.resolve('./c.test.js'), ]; const FAIL = 0; -const SUCCESS = 1; - -class TestSequencer { - constructor() { - this._cache = new Map(); - } - _getCachePath(context) { - const {config} = context; - return getCacheFilePath(config.cacheDirectory, 'perf-cache-' + config.name); - } - - _getCache(test) { - const {context} = test; - if (!this._cache.has(context) && context.config.cache) { - const cachePath = this._getCachePath(context); - if (fs.existsSync(cachePath)) { - try { - this._cache.set( - context, - JSON.parse(fs.readFileSync(cachePath, 'utf8')) - ); - } catch (e) {} - } - } - - let cache = this._cache.get(context); - if (!cache) { - cache = {}; - this._cache.set(context, cache); - } - - return cache; - } +class CustomSequencer extends Sequencer { sort(tests) { const stats = {}; const fileSize = ({path, context: {hasteFS}}) => @@ -83,25 +50,6 @@ class TestSequencer { } }); } - - cacheResults(tests, results) { - const map = Object.create(null); - tests.forEach(test => (map[test.path] = test)); - results.testResults.forEach(testResult => { - if (testResult && map[testResult.testFilePath] && !testResult.skipped) { - const cache = this._getCache(map[testResult.testFilePath]); - const perf = testResult.perfStats; - cache[testResult.testFilePath] = [ - testResult.numFailingTests ? FAIL : SUCCESS, - perf.end - perf.start || 0, - ]; - } - }); - - this._cache.forEach((cache, context) => - fs.writeFileSync(this._getCachePath(context), JSON.stringify(cache)) - ); - } } -module.exports = TestSequencer; +module.exports = CustomSequencer; From 46ef8f02c835d3d0f5f711e76d6cbdf61a5e7ff2 Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Wed, 27 Mar 2019 18:58:40 +0800 Subject: [PATCH 12/27] add a dependency on @jest/test-scheduler to jest-config so it works in yarn PnP --- packages/jest-config/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index 1ac41fc433f4..0e20f11dd993 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -12,6 +12,7 @@ "dependencies": { "@babel/core": "^7.1.0", "@jest/types": "^24.5.0", + "@jest/test-scheduler": "^24.5.0", "babel-jest": "^24.5.0", "chalk": "^2.0.1", "glob": "^7.1.1", From 30ac7e5b544ea7e881a811a1c588558c0cc0bf08 Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Wed, 27 Mar 2019 23:48:17 +0800 Subject: [PATCH 13/27] remove wrong dependency --- packages/jest-config/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index 0e20f11dd993..1ac41fc433f4 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -12,7 +12,6 @@ "dependencies": { "@babel/core": "^7.1.0", "@jest/types": "^24.5.0", - "@jest/test-scheduler": "^24.5.0", "babel-jest": "^24.5.0", "chalk": "^2.0.1", "glob": "^7.1.1", From 4bc5a01ce29285a053b49323b0eaae4422f3c023 Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Wed, 27 Mar 2019 23:52:31 +0800 Subject: [PATCH 14/27] let tests easier --- e2e/__tests__/customTestSequencers.test.ts | 22 ++---------- e2e/custom-test-sequencer/testSequencer.js | 42 ++-------------------- 2 files changed, 5 insertions(+), 59 deletions(-) diff --git a/e2e/__tests__/customTestSequencers.test.ts b/e2e/__tests__/customTestSequencers.test.ts index 421b5221368f..d9cb5f039db4 100644 --- a/e2e/__tests__/customTestSequencers.test.ts +++ b/e2e/__tests__/customTestSequencers.test.ts @@ -10,22 +10,6 @@ import runJest from '../runJest'; import {extractSummary} from '../Utils'; const dir = path.resolve(__dirname, '../custom-test-sequencer'); -expect.extend({ - toBeIn(received, arr) { - const isIn = arr.includes(received); - if (isIn) - return { - message: `expect ${received} not to be in [${arr.join(', ')}]`, - pass: true, - }; - else - return { - message: `expect ${received} to be in [${arr.join(', ')}]`, - pass: false, - }; - }, -}); - test('run prioritySequence first', () => { const result = runJest(dir, ['-i']); expect(result.status).toBe(0); @@ -33,10 +17,10 @@ test('run prioritySequence first', () => { .rest.replace(/PASS /g, '') .split('\n'); expect(sequence).toEqual([ - './d.test.js', + './a.test.js', './b.test.js', './c.test.js', - expect.toBeIn(['./a.test.js', './e.test.js']), - expect.toBeIn(['./a.test.js', './e.test.js']), + './d.test.js', + './e.test.js', ]); }); diff --git a/e2e/custom-test-sequencer/testSequencer.js b/e2e/custom-test-sequencer/testSequencer.js index 3d3235d4f312..c4248cf62a6c 100644 --- a/e2e/custom-test-sequencer/testSequencer.js +++ b/e2e/custom-test-sequencer/testSequencer.js @@ -6,49 +6,11 @@ */ const Sequencer = require('@jest/test-sequencer').default; -const path = require('path'); - -const priorityOrder = [ - path.resolve('./d.test.js'), - path.resolve('./b.test.js'), - path.resolve('./c.test.js'), -]; -const FAIL = 0; class CustomSequencer extends Sequencer { sort(tests) { - const stats = {}; - const fileSize = ({path, context: {hasteFS}}) => - stats[path] || (stats[path] = hasteFS.getSize(path) || 0); - const hasFailed = (cache, test) => - cache[test.path] && cache[test.path][0] === FAIL; - const time = (cache, test) => cache[test.path] && cache[test.path][1]; - - tests.forEach(test => (test.duration = time(this._getCache(test), test))); - return tests.sort((testA, testB) => { - const cacheA = this._getCache(testA); - const cacheB = this._getCache(testB); - const failedA = hasFailed(cacheA, testA); - const failedB = hasFailed(cacheB, testB); - const hasTimeA = testA.duration != null; - const indexA = priorityOrder.indexOf(testA.path); - const indexB = priorityOrder.indexOf(testB.path); - - if (indexA !== indexB) { - if (indexA === -1) return 1; - if (indexB === -1) return -1; - return indexA < indexB ? -1 : 1; - } else if (failedA !== failedB) { - return failedA ? -1 : 1; - } else if (hasTimeA != (testB.duration != null)) { - // If only one of two tests has timing information, run it last - return hasTimeA ? 1 : -1; - } else if (testA.duration != null && testB.duration != null) { - return testA.duration < testB.duration ? 1 : -1; - } else { - return fileSize(testA) < fileSize(testB) ? 1 : -1; - } - }); + const copyTests = Array.from(tests); + return copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1)); } } From 409a9baea5560016c4a906381fa7e1f23e206223 Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Thu, 28 Mar 2019 00:32:48 +0800 Subject: [PATCH 15/27] update docs --- docs/CLI.md | 4 ++++ docs/Configuration.md | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/docs/CLI.md b/docs/CLI.md index 92b7e943441f..858adffdda37 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -297,6 +297,10 @@ An array of regexp pattern strings that is tested against all tests paths before Lets you specify a custom test runner. +### `--testSequencer=` + +Lets you specify a custom test sequencer + ### `--updateSnapshot` 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. diff --git a/docs/Configuration.md b/docs/Configuration.md index 894e840f4b83..b0efae6f4d6f 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -993,6 +993,31 @@ function testRunner( 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). +### `testSequencer` [string] + +Default: `@jest/test-sequencer` + +This option allows you to use a custom sequencer instead of Jest's default test runner. + +You need to export a sequencer class and set path in the config + + +example: + +Sort test path alphabetically +```js +const Sequencer = require('@jest/test-sequencer').default; + +class CustomSequencer extends Sequencer { + sort(tests) { + const copyTests = Array.from(tests); + return copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1)); + } +} + +module.exports = CustomSequencer; +``` + ### `testURL` [string] Default: `http://localhost` From abc58e297739385eae3df1919e6839186441a263 Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Thu, 28 Mar 2019 00:32:59 +0800 Subject: [PATCH 16/27] fix wrong option name --- packages/jest-config/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-config/src/utils.ts b/packages/jest-config/src/utils.ts index 9308f99b6c7d..3cd9f3965a51 100644 --- a/packages/jest-config/src/utils.ts +++ b/packages/jest-config/src/utils.ts @@ -231,7 +231,7 @@ export const getSequencer = ( resolveWithPrefix(resolver, { filePath, humanOptionName: 'Jest Sequencer', - optionName: 'sequencer', + optionName: 'testSequencer', prefix: 'jest-sequencer-', rootDir, }); From 934f77cfc3fb692cb5fa37b17aadbc407151ee4d Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Thu, 28 Mar 2019 00:48:13 +0800 Subject: [PATCH 17/27] lint --- docs/Configuration.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index b0efae6f4d6f..aba0ad64aeaa 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -1001,10 +1001,10 @@ This option allows you to use a custom sequencer instead of Jest's default test You need to export a sequencer class and set path in the config - example: -Sort test path alphabetically +Sort test path alphabetically + ```js const Sequencer = require('@jest/test-sequencer').default; From 1b3f0ef8f064390ffee55d10450d625837f7a8e1 Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Thu, 28 Mar 2019 22:49:01 +0800 Subject: [PATCH 18/27] add Test type in configuration --- docs/Configuration.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index aba0ad64aeaa..59a5b9b0efc2 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -997,11 +997,9 @@ An example of such function can be found in our default [jasmine2 test runner pa Default: `@jest/test-sequencer` -This option allows you to use a custom sequencer instead of Jest's default test runner. +This option allows you to use a custom sequencer instead of Jest's default. -You need to export a sequencer class and set path in the config - -example: +Example: Sort test path alphabetically @@ -1009,7 +1007,9 @@ Sort test path alphabetically const Sequencer = require('@jest/test-sequencer').default; class CustomSequencer extends Sequencer { - sort(tests) { + sort(tests: Array) { + // Test structure information + // https://github.com/facebook/jest/blob/6b8b1404a1d9254e7d5d90a8934087a9c9899dab/packages/jest-runner/src/types.ts#L17-L21 const copyTests = Array.from(tests); return copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1)); } From f8b9b17f400d01c409eb09fdefeb05cb6fc19765 Mon Sep 17 00:00:00 2001 From: Tim Seckinger Date: Sat, 30 Mar 2019 22:24:11 +0800 Subject: [PATCH 19/27] Update docs/CLI.md Co-Authored-By: WeiAnAn --- docs/CLI.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CLI.md b/docs/CLI.md index 858adffdda37..f6b483391f7b 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -299,7 +299,7 @@ Lets you specify a custom test runner. ### `--testSequencer=` -Lets you specify a custom test sequencer +Lets you specify a custom test sequencer. Please refer to the documentation of the corresponding configuration property for details. ### `--updateSnapshot` From 4efe85c60771318af3c9e12a6f5163e2636a3d39 Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Sat, 30 Mar 2019 23:46:07 +0800 Subject: [PATCH 20/27] keep example as js instead of ts --- docs/Configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index 59a5b9b0efc2..0da42e611a35 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -1007,7 +1007,7 @@ Sort test path alphabetically const Sequencer = require('@jest/test-sequencer').default; class CustomSequencer extends Sequencer { - sort(tests: Array) { + sort(tests) { // Test structure information // https://github.com/facebook/jest/blob/6b8b1404a1d9254e7d5d90a8934087a9c9899dab/packages/jest-runner/src/types.ts#L17-L21 const copyTests = Array.from(tests); From 20910a904ccc13b0212d61baf3b79a5b70d51a7d Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Sat, 30 Mar 2019 23:54:49 +0800 Subject: [PATCH 21/27] update changelog which affect multiple packages to one line. --- CHANGELOG.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06ecc70dab33..8c85784982b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,11 +9,8 @@ - `[jest-runner]` Support default exports for test environments ([#8163](https://github.com/facebook/jest/pull/8163)) - `[pretty-format]` Support React.Suspense ([#8180](https://github.com/facebook/jest/pull/8180)) - `[jest-snapshot]` Indent inline snapshots ([#8198](https://github.com/facebook/jest/pull/8198)) -- `[@jest/core]` Move `testSequencer` to individual package `@jest/test-sequencer` ([#8223](https://github.com/facebook/jest/pull/8223)) -- `[@jest/test-sequencer]` Move `testSequencer` to individual package `@jest/test-sequencer` ([#8223](https://github.com/facebook/jest/pull/8223)) -- `[@jest/core]` Add option `testSequencer` allow user use custom sequencer. ([#8223](https://github.com/facebook/jest/pull/8223)) -- `[jest-config]` Add option `testSequencer` allow user use custom sequencer. ([#8223](https://github.com/facebook/jest/pull/8223)) -- `[jest-cli]` Add option `testSequencer` allow user use custom sequencer. ([#8223](https://github.com/facebook/jest/pull/8223)) +- `[@jest/core, @jest/test-sequencer]` Move `testSequencer` to individual package `@jest/test-sequencer` ([#8223](https://github.com/facebook/jest/pull/8223)) +- `[jest-config, jest-cli]` Add option `testSequencer` allow user use custom sequencer. ([#8223](https://github.com/facebook/jest/pull/8223)) ### Fixes From 2e8fe7b16c361c7f893804aa33bebba58a036e9a Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Sun, 31 Mar 2019 00:14:00 +0800 Subject: [PATCH 22/27] add @jest/test-sequencer to dependency --- packages/jest-config/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index 1ac41fc433f4..cd4052527997 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -12,6 +12,7 @@ "dependencies": { "@babel/core": "^7.1.0", "@jest/types": "^24.5.0", + "@jest/test-sequencer": "^24.5.0", "babel-jest": "^24.5.0", "chalk": "^2.0.1", "glob": "^7.1.1", From 9662a12e613c949e265ce826c3f2f2b7b44e1aa6 Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Sun, 31 Mar 2019 00:33:16 +0800 Subject: [PATCH 23/27] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7a42d8bbcb2..2698161198a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ - `[jest-snapshot]` Indent inline snapshots ([#8198](https://github.com/facebook/jest/pull/8198)) - `[jest-config]` Support colors in `displayName` configuration ([#8025](https://github.com/facebook/jest/pull/8025)) - `[@jest/core, @jest/test-sequencer]` Move `testSequencer` to individual package `@jest/test-sequencer` ([#8223](https://github.com/facebook/jest/pull/8223)) -- `[jest-config, jest-cli]` Add option `testSequencer` allow user use custom sequencer. ([#8223](https://github.com/facebook/jest/pull/8223)) +- `[@jest/core, jest-cli, jest-config]` Add option `testSequencer` allow user use custom sequencer. ([#8223](https://github.com/facebook/jest/pull/8223)) ### Fixes From 7e8d15af03f5c2dd29b539ce07fc07a8db492d4e Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Sun, 31 Mar 2019 02:37:42 +0800 Subject: [PATCH 24/27] move @jest/test-sequencer to dev dependency --- packages/jest-core/package.json | 4 ++-- packages/jest-core/src/runJest.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/jest-core/package.json b/packages/jest-core/package.json index 6e4c673d75ae..fff8db179a62 100644 --- a/packages/jest-core/package.json +++ b/packages/jest-core/package.json @@ -8,7 +8,6 @@ "@jest/console": "^24.3.0", "@jest/reporters": "^24.5.0", "@jest/test-result": "^24.5.0", - "@jest/test-sequencer": "^24.5.0", "@jest/transform": "^24.5.0", "@jest/types": "^24.5.0", "ansi-escapes": "^3.0.0", @@ -41,7 +40,8 @@ "@types/micromatch": "^3.1.0", "@types/p-each-series": "^1.0.0", "@types/rimraf": "^2.0.2", - "@types/strip-ansi": "^3.0.0" + "@types/strip-ansi": "^3.0.0", + "@jest/test-sequencer": "^24.5.0" }, "engines": { "node": ">= 6" diff --git a/packages/jest-core/src/runJest.ts b/packages/jest-core/src/runJest.ts index ce61fdecbf32..fd88593d05e4 100644 --- a/packages/jest-core/src/runJest.ts +++ b/packages/jest-core/src/runJest.ts @@ -20,7 +20,7 @@ import { AggregatedResult, makeEmptyAggregatedTestResult, } from '@jest/test-result'; -import TestSequencer from '@jest/test-sequencer'; +import TestSequencer from '@jest/test-sequencer'; // eslint-disable-line import/no-extraneous-dependencies import {ChangedFiles, ChangedFilesPromise} from 'jest-changed-files'; import getNoTestsFoundMessage from './getNoTestsFoundMessage'; import runGlobalHook from './runGlobalHook'; From 0866abad983e9ab1fa8f0ccf7758e457f30244f7 Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Tue, 2 Apr 2019 15:58:22 +0800 Subject: [PATCH 25/27] Update @jest/core package.json --- packages/jest-core/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-core/package.json b/packages/jest-core/package.json index fff8db179a62..4393171e59e4 100644 --- a/packages/jest-core/package.json +++ b/packages/jest-core/package.json @@ -34,14 +34,14 @@ "strip-ansi": "^5.0.0" }, "devDependencies": { + "@jest/test-sequencer": "^24.5.0", "@types/ansi-escapes": "^3.0.1", "@types/exit": "^0.1.30", "@types/graceful-fs": "^4.1.2", "@types/micromatch": "^3.1.0", "@types/p-each-series": "^1.0.0", "@types/rimraf": "^2.0.2", - "@types/strip-ansi": "^3.0.0", - "@jest/test-sequencer": "^24.5.0" + "@types/strip-ansi": "^3.0.0" }, "engines": { "node": ">= 6" From 745cad3e4038d31a777cbce67d0050c4166d2cda Mon Sep 17 00:00:00 2001 From: Wei An Yen Date: Tue, 2 Apr 2019 16:06:57 +0800 Subject: [PATCH 26/27] update version to 24.6.0 --- packages/jest-core/package.json | 2 +- packages/jest-test-sequencer/package.json | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/jest-core/package.json b/packages/jest-core/package.json index 1fbb3496abbb..34bd6e9e7990 100644 --- a/packages/jest-core/package.json +++ b/packages/jest-core/package.json @@ -34,7 +34,7 @@ "strip-ansi": "^5.0.0" }, "devDependencies": { - "@jest/test-sequencer": "^24.5.0", + "@jest/test-sequencer": "^24.6.0", "@types/ansi-escapes": "^3.0.1", "@types/exit": "^0.1.30", "@types/graceful-fs": "^4.1.2", diff --git a/packages/jest-test-sequencer/package.json b/packages/jest-test-sequencer/package.json index 69327e50b91b..5aad8dca8318 100644 --- a/packages/jest-test-sequencer/package.json +++ b/packages/jest-test-sequencer/package.json @@ -1,6 +1,6 @@ { "name": "@jest/test-sequencer", - "version": "24.5.0", + "version": "24.6.0", "repository": { "type": "git", "url": "https://github.com/facebook/jest.git", @@ -10,10 +10,10 @@ "main": "build/index.js", "types": "build/index.d.ts", "dependencies": { - "@jest/test-result": "^24.5.0", - "jest-haste-map": "^24.5.0", - "jest-runtime": "^24.5.0", - "jest-runner": "^24.5.0" + "@jest/test-result": "^24.6.0", + "jest-haste-map": "^24.6.0", + "jest-runtime": "^24.6.0", + "jest-runner": "^24.6.0" }, "engines": { "node": ">= 6" From 301a5cda50bf82617fe776938ee3fbd1c24b4a7c Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 2 Apr 2019 17:15:41 +0200 Subject: [PATCH 27/27] sort --- packages/jest-test-sequencer/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-test-sequencer/package.json b/packages/jest-test-sequencer/package.json index 5aad8dca8318..aec99f7bfab3 100644 --- a/packages/jest-test-sequencer/package.json +++ b/packages/jest-test-sequencer/package.json @@ -12,8 +12,8 @@ "dependencies": { "@jest/test-result": "^24.6.0", "jest-haste-map": "^24.6.0", - "jest-runtime": "^24.6.0", - "jest-runner": "^24.6.0" + "jest-runner": "^24.6.0", + "jest-runtime": "^24.6.0" }, "engines": { "node": ">= 6"