From 0de5539c3fbdd52ee9d4bd9882fa770ea920f314 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 22 Aug 2019 08:52:21 +0200 Subject: [PATCH 1/6] chore: remove deprecated exports from jest-util --- packages/jest-core/src/runJest.ts | 3 ++- packages/jest-fake-timers/package.json | 3 ++- .../jest-fake-timers/src/jestFakeTimers.ts | 11 +---------- packages/jest-fake-timers/tsconfig.json | 3 ++- packages/jest-jasmine2/package.json | 1 + packages/jest-jasmine2/src/index.ts | 2 +- packages/jest-jasmine2/tsconfig.json | 1 + packages/jest-reporters/package.json | 1 + .../jest-reporters/src/default_reporter.ts | 3 ++- packages/jest-reporters/tsconfig.json | 1 + packages/jest-util/package.json | 10 +--------- packages/jest-util/src/index.ts | 19 +------------------ packages/jest-util/tsconfig.json | 4 ---- 13 files changed, 16 insertions(+), 46 deletions(-) diff --git a/packages/jest-core/src/runJest.ts b/packages/jest-core/src/runJest.ts index 8082d52cd99c..3a9d293b127b 100644 --- a/packages/jest-core/src/runJest.ts +++ b/packages/jest-core/src/runJest.ts @@ -9,7 +9,7 @@ import * as path from 'path'; import chalk from 'chalk'; import {sync as realpath} from 'realpath-native'; import {CustomConsole} from '@jest/console'; -import {formatTestResults, interopRequireDefault} from 'jest-util'; +import {interopRequireDefault} from 'jest-util'; import exit = require('exit'); import * as fs from 'graceful-fs'; import {JestHook, JestHookEmitter} from 'jest-watcher'; @@ -18,6 +18,7 @@ import {Test} from 'jest-runner'; import {Config} from '@jest/types'; import { AggregatedResult, + formatTestResults, makeEmptyAggregatedTestResult, } from '@jest/test-result'; // eslint-disable-next-line import/no-extraneous-dependencies diff --git a/packages/jest-fake-timers/package.json b/packages/jest-fake-timers/package.json index 03719109627f..52c246bbf7c0 100644 --- a/packages/jest-fake-timers/package.json +++ b/packages/jest-fake-timers/package.json @@ -12,7 +12,8 @@ "dependencies": { "@jest/types": "^24.9.0", "jest-message-util": "^24.9.0", - "jest-mock": "^24.9.0" + "jest-mock": "^24.9.0", + "jest-util": "^24.9.0" }, "engines": { "node": ">= 8" diff --git a/packages/jest-fake-timers/src/jestFakeTimers.ts b/packages/jest-fake-timers/src/jestFakeTimers.ts index 457d85fdf166..804320848897 100644 --- a/packages/jest-fake-timers/src/jestFakeTimers.ts +++ b/packages/jest-fake-timers/src/jestFakeTimers.ts @@ -7,6 +7,7 @@ import {ModuleMocker} from 'jest-mock'; import {StackTraceConfig, formatStackTrace} from 'jest-message-util'; +import {setGlobal} from 'jest-util'; type Callback = (...args: Array) => void; @@ -42,16 +43,6 @@ type TimerConfig = { const MS_IN_A_YEAR = 31536000000; -// TODO: Copied from `jest-util` to avoid cyclic dependency. Import from `jest-util` in the next major -const setGlobal = ( - globalToMutate: NodeJS.Global | Window, - key: string, - value: unknown, -) => { - // @ts-ignore: no index - globalToMutate[key] = value; -}; - export default class FakeTimers { private _cancelledTicks!: Record; private _config: StackTraceConfig; diff --git a/packages/jest-fake-timers/tsconfig.json b/packages/jest-fake-timers/tsconfig.json index 335b1e9c373a..7105524da628 100644 --- a/packages/jest-fake-timers/tsconfig.json +++ b/packages/jest-fake-timers/tsconfig.json @@ -6,6 +6,7 @@ }, "references": [ {"path": "../jest-message-util"}, - {"path": "../jest-mock"} + {"path": "../jest-mock"}, + {"path": "../jest-util"} ] } diff --git a/packages/jest-jasmine2/package.json b/packages/jest-jasmine2/package.json index ada9c9ed4394..e2c82903825c 100644 --- a/packages/jest-jasmine2/package.json +++ b/packages/jest-jasmine2/package.json @@ -12,6 +12,7 @@ "dependencies": { "@babel/traverse": "^7.1.0", "@jest/environment": "^24.9.0", + "@jest/source-map": "^24.9.0", "@jest/test-result": "^24.9.0", "@jest/types": "^24.9.0", "chalk": "^2.0.1", diff --git a/packages/jest-jasmine2/src/index.ts b/packages/jest-jasmine2/src/index.ts index af9bd39281dd..6122832f8fe4 100644 --- a/packages/jest-jasmine2/src/index.ts +++ b/packages/jest-jasmine2/src/index.ts @@ -12,7 +12,7 @@ import {JestEnvironment} from '@jest/environment'; import {SnapshotStateType} from 'jest-snapshot'; import Runtime = require('jest-runtime'); -import {getCallsite} from 'jest-util'; +import {getCallsite} from '@jest/source-map'; import installEach from './each'; import {installErrorOnPrivate} from './errorOnPrivate'; import JasmineReporter from './reporter'; diff --git a/packages/jest-jasmine2/tsconfig.json b/packages/jest-jasmine2/tsconfig.json index 9cad84ed04af..a52d122e4792 100644 --- a/packages/jest-jasmine2/tsconfig.json +++ b/packages/jest-jasmine2/tsconfig.json @@ -12,6 +12,7 @@ {"path": "../jest-message-util"}, {"path": "../jest-runtime"}, {"path": "../jest-snapshot"}, + {"path": "../jest-source-map"}, {"path": "../jest-test-result"}, {"path": "../jest-types"}, {"path": "../jest-util"}, diff --git a/packages/jest-reporters/package.json b/packages/jest-reporters/package.json index aa3431cc7e26..d6f3cb2f3eb8 100644 --- a/packages/jest-reporters/package.json +++ b/packages/jest-reporters/package.json @@ -5,6 +5,7 @@ "main": "build/index.js", "types": "build/index.d.ts", "dependencies": { + "@jest/console": "^24.9.0", "@jest/environment": "^24.9.0", "@jest/test-result": "^24.9.0", "@jest/transform": "^24.9.0", diff --git a/packages/jest-reporters/src/default_reporter.ts b/packages/jest-reporters/src/default_reporter.ts index c141434d5776..9f9f613ac001 100644 --- a/packages/jest-reporters/src/default_reporter.ts +++ b/packages/jest-reporters/src/default_reporter.ts @@ -7,7 +7,8 @@ import {Config} from '@jest/types'; import {AggregatedResult, TestResult} from '@jest/test-result'; -import {clearLine, getConsoleOutput, isInteractive} from 'jest-util'; +import {clearLine, isInteractive} from 'jest-util'; +import {getConsoleOutput} from '@jest/console'; import chalk from 'chalk'; import {ReporterOnStartOptions, Test} from './types'; import BaseReporter from './base_reporter'; diff --git a/packages/jest-reporters/tsconfig.json b/packages/jest-reporters/tsconfig.json index 00dffcebc22f..bdf1b1cdc9ee 100644 --- a/packages/jest-reporters/tsconfig.json +++ b/packages/jest-reporters/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "build" }, "references": [ + {"path": "../jest-console"}, {"path": "../jest-environment"}, {"path": "../jest-haste-map"}, {"path": "../jest-resolve"}, diff --git a/packages/jest-util/package.json b/packages/jest-util/package.json index 9860ef69b91e..e2d3e4c6bb4c 100644 --- a/packages/jest-util/package.json +++ b/packages/jest-util/package.json @@ -10,18 +10,10 @@ "main": "build/index.js", "types": "build/index.d.ts", "dependencies": { - "@jest/console": "^24.9.0", - "@jest/fake-timers": "^24.9.0", - "@jest/source-map": "^24.9.0", - "@jest/test-result": "^24.9.0", "@jest/types": "^24.9.0", - "callsites": "^3.0.0", "chalk": "^2.0.1", - "graceful-fs": "^4.1.15", "is-ci": "^2.0.0", - "mkdirp": "^0.5.1", - "slash": "^3.0.0", - "source-map": "^0.6.0" + "mkdirp": "^0.5.1" }, "devDependencies": { "@types/graceful-fs": "^4.1.2", diff --git a/packages/jest-util/src/index.ts b/packages/jest-util/src/index.ts index 6f1f6cf92d19..7315e2391644 100644 --- a/packages/jest-util/src/index.ts +++ b/packages/jest-util/src/index.ts @@ -5,16 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -// TODO: Remove these exports in the next major -import {JestFakeTimers as FakeTimers} from '@jest/fake-timers'; -import {getCallsite} from '@jest/source-map'; -import { - BufferedConsole, - CustomConsole, - NullConsole, - getConsoleOutput, -} from '@jest/console'; -import {formatTestResults} from '@jest/test-result'; import clearLine from './clearLine'; import createDirectory from './createDirectory'; import ErrorWithStack from './ErrorWithStack'; @@ -32,19 +22,12 @@ import testPathPatternToRegExp from './testPathPatternToRegExp'; import * as preRunMessage from './preRunMessage'; import pluralize from './pluralize'; -export = { - BufferedConsole, - Console: CustomConsole, +export { ErrorWithStack, - FakeTimers, - NullConsole, clearLine, convertDescriptorToString, createDirectory, deepCyclicCopy, - formatTestResults, - getCallsite, - getConsoleOutput, getFailedSnapshotTests, installCommonGlobals, interopRequireDefault, diff --git a/packages/jest-util/tsconfig.json b/packages/jest-util/tsconfig.json index f40d52b2fb32..b802dbf5ce24 100644 --- a/packages/jest-util/tsconfig.json +++ b/packages/jest-util/tsconfig.json @@ -5,10 +5,6 @@ "outDir": "build" }, "references": [ - {"path": "../jest-console"}, - {"path": "../jest-fake-timers"}, - {"path": "../jest-source-map"}, - {"path": "../jest-test-result"}, {"path": "../jest-types"} ] } From 8efe639728c8c90cd6ed1512cc9ed3bf08ae5fd5 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 22 Aug 2019 09:01:17 +0200 Subject: [PATCH 2/6] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7cb0197dfaf..6e69f012f177 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - `[*]` [**BREAKING**] Upgrade to Micromatch v4 ([#8852](https://github.com/facebook/jest/pull/8852)) - `[docs]` Fix broken link pointing to legacy JS file in "Snapshot Testing". - `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM from v11 to v15 ([#8851](https://github.com/facebook/jest/pull/8851)) +- `[jest-util]` [**BREAKING**] Remove deprecated exports ([#8863](https://github.com/facebook/jest/pull/8863)) ### Performance From 23e21b3022c5cefde9a3468443214beedc317321 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 22 Aug 2019 09:17:46 +0200 Subject: [PATCH 3/6] remove unused export --- .../src/__tests__/getFailedSnapshot.test.ts | 72 ------------------- .../jest-util/src/getFailedSnapshotTests.ts | 26 ------- packages/jest-util/src/index.ts | 2 - 3 files changed, 100 deletions(-) delete mode 100644 packages/jest-util/src/__tests__/getFailedSnapshot.test.ts delete mode 100644 packages/jest-util/src/getFailedSnapshotTests.ts diff --git a/packages/jest-util/src/__tests__/getFailedSnapshot.test.ts b/packages/jest-util/src/__tests__/getFailedSnapshot.test.ts deleted file mode 100644 index d1dbcd19d10b..000000000000 --- a/packages/jest-util/src/__tests__/getFailedSnapshot.test.ts +++ /dev/null @@ -1,72 +0,0 @@ -/** - * 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 getFailedSnapshotTests from '../getFailedSnapshotTests'; - -test('return a list of path', () => { - const targetFilename = 'somewhere.js'; - const param = { - numFailedTests: 1, - testResults: [ - { - snapshot: { - unmatched: 1, - }, - testFilePath: targetFilename, - }, - ], - }; - // @ts-ignore - expect(getFailedSnapshotTests(param)).toEqual([targetFilename]); -}); - -test('handle missing snapshot object', () => { - const targetFilename = 'somewhere.js'; - const param = { - numFailedTests: 1, - testResults: [ - { - testFilePath: targetFilename, - }, - ], - }; - // @ts-ignore - expect(getFailedSnapshotTests(param)).toEqual([]); -}); - -test('handle missing testResults object', () => { - const param = { - numFailedTests: 1, - }; - // @ts-ignore - expect(getFailedSnapshotTests(param)).toEqual([]); -}); - -test('return empty if not failed tests', () => { - const param = { - numFailedTests: 0, - }; - // @ts-ignore - expect(getFailedSnapshotTests(param)).toEqual([]); -}); - -test('return empty if not failed snapshot tests', () => { - const targetFilename = 'somewhere.js'; - const param = { - numFailedTests: 0, - testResults: [ - { - snapshot: { - unmatched: 0, - }, - testFilePath: targetFilename, - }, - ], - }; - // @ts-ignore - expect(getFailedSnapshotTests(param)).toEqual([]); -}); diff --git a/packages/jest-util/src/getFailedSnapshotTests.ts b/packages/jest-util/src/getFailedSnapshotTests.ts deleted file mode 100644 index 913c954440b4..000000000000 --- a/packages/jest-util/src/getFailedSnapshotTests.ts +++ /dev/null @@ -1,26 +0,0 @@ -/** - * 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 {Config} from '@jest/types'; -import {AggregatedResult} from '@jest/test-result'; - -function getFailedSnapshotTests(testResults: AggregatedResult) { - const failedTestPaths: Array = []; - if (testResults.numFailedTests === 0 || !testResults.testResults) { - return failedTestPaths; - } - - testResults.testResults.forEach(testResult => { - if (testResult.snapshot && testResult.snapshot.unmatched) { - failedTestPaths.push(testResult.testFilePath); - } - }); - - return failedTestPaths; -} - -export default getFailedSnapshotTests; diff --git a/packages/jest-util/src/index.ts b/packages/jest-util/src/index.ts index 7315e2391644..db8872b0df36 100644 --- a/packages/jest-util/src/index.ts +++ b/packages/jest-util/src/index.ts @@ -8,7 +8,6 @@ import clearLine from './clearLine'; import createDirectory from './createDirectory'; import ErrorWithStack from './ErrorWithStack'; -import getFailedSnapshotTests from './getFailedSnapshotTests'; import installCommonGlobals from './installCommonGlobals'; import interopRequireDefault from './interopRequireDefault'; import isInteractive from './isInteractive'; @@ -28,7 +27,6 @@ export { convertDescriptorToString, createDirectory, deepCyclicCopy, - getFailedSnapshotTests, installCommonGlobals, interopRequireDefault, isInteractive, From b230b7556938a0b67c7a54d07aa48c7a54e3f61a Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 22 Aug 2019 10:21:45 +0200 Subject: [PATCH 4/6] use default reporter to debug ci --- jest.config.ci.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jest.config.ci.js b/jest.config.ci.js index ecf98bc0bb54..7ba51a3f2b7c 100644 --- a/jest.config.ci.js +++ b/jest.config.ci.js @@ -12,6 +12,6 @@ module.exports = Object.assign({}, require('./jest.config'), { coverageReporters: ['json'], reporters: [ ['jest-junit', {output: 'reports/junit/js-test-results.xml'}], - ['jest-silent-reporter', {useDots: true}], + 'default', ], }); From ab8df48eae6176cdb9b91628aa140e6bc6179313 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 22 Aug 2019 11:26:00 +0200 Subject: [PATCH 5/6] fix reporter test --- .../src/__tests__/default_reporter.test.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/jest-reporters/src/__tests__/default_reporter.test.js b/packages/jest-reporters/src/__tests__/default_reporter.test.js index 060e817fa37b..c714842eb3a9 100644 --- a/packages/jest-reporters/src/__tests__/default_reporter.test.js +++ b/packages/jest-reporters/src/__tests__/default_reporter.test.js @@ -5,7 +5,13 @@ * LICENSE file in the root directory of this source tree. */ -'use strict'; +import DefaultReporter from '../default_reporter'; + +jest.mock('jest-util', () => ({ + ...jest.requireActual('jest-util'), + // This is not a CI environment, which removes all output by default. + isInteractive: true, +})); const aggregatedResults = {}; const options = {}; @@ -26,7 +32,6 @@ const testResult = { testFilePath: '/foo', }; -let DefaultReporter; let stdout; let oldIsTTY; @@ -34,14 +39,8 @@ let oldStderr; let oldStdout; beforeEach(() => { - jest.resetModules(); jest.useFakeTimers(); - // This is not a CI environment, which removes all output by default. - jest.unmock('jest-util'); - const util = require('jest-util'); - util.isInteractive = true; - oldIsTTY = process.stdin.isTTY; oldStdout = process.stdout.write; oldStderr = process.stderr.write; @@ -52,8 +51,6 @@ beforeEach(() => { process.stdin.isTTY = true; process.stderr.write = jest.fn(); stdout = process.stdout.write = jest.fn(); - - DefaultReporter = require('../default_reporter').default; }); afterEach(() => { From 1a588997865dbf7bee39318f4a033ac0e5016694 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 22 Aug 2019 15:27:23 +0200 Subject: [PATCH 6/6] Revert "use default reporter to debug ci" This reverts commit b230b7556938a0b67c7a54d07aa48c7a54e3f61a. --- jest.config.ci.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jest.config.ci.js b/jest.config.ci.js index 7ba51a3f2b7c..ecf98bc0bb54 100644 --- a/jest.config.ci.js +++ b/jest.config.ci.js @@ -12,6 +12,6 @@ module.exports = Object.assign({}, require('./jest.config'), { coverageReporters: ['json'], reporters: [ ['jest-junit', {output: 'reports/junit/js-test-results.xml'}], - 'default', + ['jest-silent-reporter', {useDots: true}], ], });