From 904c4180959bce9915c45b4cd05dea8aca1a8e16 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 24 Aug 2019 18:48:00 +0200 Subject: [PATCH 1/5] chore: convert jest-cli and jest-validate to esm --- CHANGELOG.md | 2 ++ packages/jest-cli/src/index.ts | 13 ++----------- packages/jest-jasmine2/src/index.ts | 2 +- .../jest-jasmine2/src/jasmine/jasmineLight.ts | 8 +++----- packages/jest-validate/src/index.ts | 18 ++++-------------- 5 files changed, 12 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49322624ffe0..94787e0d4c4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,8 +23,10 @@ - `[*]` Add Node 12 to CI ([#8411](https://github.com/facebook/jest/pull/8411)) - `[*]` [**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-cli]` [**BREAKING**] Use ESM exports - `[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)) +- `[jest-validate]` [**BREAKING**] Use ESM exports ### Performance diff --git a/packages/jest-cli/src/index.ts b/packages/jest-cli/src/index.ts index a03c03018a7a..2f8b64d151d9 100644 --- a/packages/jest-cli/src/index.ts +++ b/packages/jest-cli/src/index.ts @@ -6,20 +6,11 @@ */ // TODO: remove @jest/core exports for the next major -import { +export { SearchSource, TestScheduler, TestWatcher, getVersion, runCLI, } from '@jest/core'; -import {run} from './cli'; - -export = { - SearchSource, - TestScheduler, - TestWatcher, - getVersion, - run, - runCLI, -}; +export {run} from './cli'; diff --git a/packages/jest-jasmine2/src/index.ts b/packages/jest-jasmine2/src/index.ts index 6122832f8fe4..53598542b031 100644 --- a/packages/jest-jasmine2/src/index.ts +++ b/packages/jest-jasmine2/src/index.ts @@ -38,7 +38,7 @@ async function jasmine2( }); const env = jasmine.getEnv(); - const jasmineInterface = jasmineFactory.interface(jasmine, env); + const jasmineInterface = jasmineFactory._interface(jasmine, env); Object.assign(environment.global, jasmineInterface); env.addReporter(jasmineInterface.jsApiReporter); diff --git a/packages/jest-jasmine2/src/jasmine/jasmineLight.ts b/packages/jest-jasmine2/src/jasmine/jasmineLight.ts index 837f04906805..576af1aae1f2 100644 --- a/packages/jest-jasmine2/src/jasmine/jasmineLight.ts +++ b/packages/jest-jasmine2/src/jasmine/jasmineLight.ts @@ -40,7 +40,7 @@ import SpyRegistry from './spyRegistry'; import Suite from './Suite'; import Timer from './Timer'; -const create = function(createOptions: Record): Jasmine { +export const create = function(createOptions: Record): Jasmine { const j$ = {...createOptions} as Jasmine; j$._DEFAULT_TIMEOUT_INTERVAL = createOptions.testTimeout || 5000; @@ -63,7 +63,8 @@ const create = function(createOptions: Record): Jasmine { return j$; }; -const _interface = function(jasmine: Jasmine, env: any) { +// Interface is a reserved word in strict mode, so can't export it as ESM +export const _interface = function(jasmine: Jasmine, env: any) { const jasmineInterface = { describe(description: string, specDefinitions: Function) { return env.describe(description, specDefinitions); @@ -146,6 +147,3 @@ const _interface = function(jasmine: Jasmine, env: any) { return jasmineInterface; }; - -// Interface is a reserved word in strict mode, so can't export it as ESM -export = {create, interface: _interface}; diff --git a/packages/jest-validate/src/index.ts b/packages/jest-validate/src/index.ts index 85661dcf720e..01b9fccab3c1 100644 --- a/packages/jest-validate/src/index.ts +++ b/packages/jest-validate/src/index.ts @@ -5,22 +5,12 @@ * LICENSE file in the root directory of this source tree. */ -import { +export { ValidationError, createDidYouMeanMessage, format, logValidationWarning, } from './utils'; -import validate from './validate'; -import validateCLIOptions from './validateCLIOptions'; -import {multipleValidOptions} from './condition'; - -export = { - ValidationError, - createDidYouMeanMessage, - format, - logValidationWarning, - multipleValidOptions, - validate, - validateCLIOptions, -}; +export {default as validate} from './validate'; +export {default as validateCLIOptions} from './validateCLIOptions'; +export {multipleValidOptions} from './condition'; From 4432dedfd8e73394bad0c6bed33aff2aa1b951c3 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 24 Aug 2019 18:53:24 +0200 Subject: [PATCH 2/5] link to PR --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94787e0d4c4a..3134976e19de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,10 +23,10 @@ - `[*]` Add Node 12 to CI ([#8411](https://github.com/facebook/jest/pull/8411)) - `[*]` [**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-cli]` [**BREAKING**] Use ESM exports +- `[jest-cli]` [**BREAKING**] Use ESM exports ([#8874](https://github.com/facebook/jest/pull/8874)) - `[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)) -- `[jest-validate]` [**BREAKING**] Use ESM exports +- `[jest-validate]` [**BREAKING**] Use ESM exports ([#8874](https://github.com/facebook/jest/pull/8874)) ### Performance From 287270a1a4add409fcbe32f36c1b1ac500979bea Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 24 Aug 2019 19:09:09 +0200 Subject: [PATCH 3/5] update test --- e2e/run-programmatically/cjs.js | 2 -- e2e/run-programmatically/esm.js | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/e2e/run-programmatically/cjs.js b/e2e/run-programmatically/cjs.js index 2366de690bc4..c5fbf6340307 100644 --- a/e2e/run-programmatically/cjs.js +++ b/e2e/run-programmatically/cjs.js @@ -3,8 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ // Running Jest like this is not officially supported, diff --git a/e2e/run-programmatically/esm.js b/e2e/run-programmatically/esm.js index f9120cd5599e..6ee4ddcaaf24 100644 --- a/e2e/run-programmatically/esm.js +++ b/e2e/run-programmatically/esm.js @@ -3,12 +3,10 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ -import myJestImport from 'jest'; +import {run} from 'jest'; // Running Jest like this is not officially supported, // but it is common practice until there is a proper API as a substitute. -myJestImport.run(process.argv); +run(process.argv); From e32aad1694457080b0a3a835898c78bd997a853f Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 24 Aug 2019 19:14:29 +0200 Subject: [PATCH 4/5] babel plugin and jest as well --- CHANGELOG.md | 2 ++ packages/babel-plugin-jest-hoist/src/index.ts | 2 +- packages/jest/src/jest.ts | 11 ++++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3134976e19de..fc5a0bb5ac69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,9 @@ - `[*]` [**BREAKING**] Drop support for Node 6 ([#8455](https://github.com/facebook/jest/pull/8455)) - `[*]` Add Node 12 to CI ([#8411](https://github.com/facebook/jest/pull/8411)) - `[*]` [**BREAKING**] Upgrade to Micromatch v4 ([#8852](https://github.com/facebook/jest/pull/8852)) +- `[babel-plugin-jest-hoist]` [**BREAKING**] Use ESM exports ([#8874](https://github.com/facebook/jest/pull/8874)) - `[docs]` Fix broken link pointing to legacy JS file in "Snapshot Testing". +- `[jest]` [**BREAKING**] Use ESM exports ([#8874](https://github.com/facebook/jest/pull/8874)) - `[jest-cli]` [**BREAKING**] Use ESM exports ([#8874](https://github.com/facebook/jest/pull/8874)) - `[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)) diff --git a/packages/babel-plugin-jest-hoist/src/index.ts b/packages/babel-plugin-jest-hoist/src/index.ts index d321b13af59a..5a5d51b99fc3 100644 --- a/packages/babel-plugin-jest-hoist/src/index.ts +++ b/packages/babel-plugin-jest-hoist/src/index.ts @@ -154,7 +154,7 @@ FUNCTIONS.deepUnmock = args => args.length === 1 && args[0].isStringLiteral(); FUNCTIONS.disableAutomock = FUNCTIONS.enableAutomock = args => args.length === 0; -export = () => { +export default () => { const shouldHoistExpression = (expr: NodePath): boolean => { if (!expr.isCallExpression()) { return false; diff --git a/packages/jest/src/jest.ts b/packages/jest/src/jest.ts index f7322540629f..9a30dee1c3f9 100644 --- a/packages/jest/src/jest.ts +++ b/packages/jest/src/jest.ts @@ -5,6 +5,11 @@ * LICENSE file in the root directory of this source tree. */ -import * as cli from 'jest-cli'; - -export = cli; +export { + SearchSource, + TestScheduler, + TestWatcher, + getVersion, + run, + runCLI, +} from 'jest-cli'; From a2383749bf09b877bb9beec8777fa78c6dc8f80c Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 26 Aug 2019 08:31:01 +0200 Subject: [PATCH 5/5] remove re-exports from jest-core --- CHANGELOG.md | 1 + packages/jest-cli/src/index.ts | 8 -------- packages/jest/package.json | 1 + packages/jest/src/jest.ts | 5 +++-- packages/jest/tsconfig.json | 3 ++- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc5a0bb5ac69..ce698c98f80e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - `[docs]` Fix broken link pointing to legacy JS file in "Snapshot Testing". - `[jest]` [**BREAKING**] Use ESM exports ([#8874](https://github.com/facebook/jest/pull/8874)) - `[jest-cli]` [**BREAKING**] Use ESM exports ([#8874](https://github.com/facebook/jest/pull/8874)) +- `[jest-cli]` [**BREAKING**] Remove re-exports from `@jest/core` ([#8874](https://github.com/facebook/jest/pull/8874)) - `[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)) - `[jest-validate]` [**BREAKING**] Use ESM exports ([#8874](https://github.com/facebook/jest/pull/8874)) diff --git a/packages/jest-cli/src/index.ts b/packages/jest-cli/src/index.ts index 2f8b64d151d9..67f1ad99ff3f 100644 --- a/packages/jest-cli/src/index.ts +++ b/packages/jest-cli/src/index.ts @@ -5,12 +5,4 @@ * LICENSE file in the root directory of this source tree. */ -// TODO: remove @jest/core exports for the next major -export { - SearchSource, - TestScheduler, - TestWatcher, - getVersion, - runCLI, -} from '@jest/core'; export {run} from './cli'; diff --git a/packages/jest/package.json b/packages/jest/package.json index c93b3082f821..f094070eaccf 100644 --- a/packages/jest/package.json +++ b/packages/jest/package.json @@ -5,6 +5,7 @@ "main": "build/jest.js", "types": "build/jest.d.ts", "dependencies": { + "@jest/core": "^24.9.0", "import-local": "^3.0.2", "jest-cli": "^24.9.0" }, diff --git a/packages/jest/src/jest.ts b/packages/jest/src/jest.ts index 9a30dee1c3f9..ff2c31c2f394 100644 --- a/packages/jest/src/jest.ts +++ b/packages/jest/src/jest.ts @@ -10,6 +10,7 @@ export { TestScheduler, TestWatcher, getVersion, - run, runCLI, -} from 'jest-cli'; +} from '@jest/core'; + +export {run} from 'jest-cli'; diff --git a/packages/jest/tsconfig.json b/packages/jest/tsconfig.json index 0e089576b519..f3e9271cd4a7 100644 --- a/packages/jest/tsconfig.json +++ b/packages/jest/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "build" }, "references": [ - {"path": "../jest-cli"} + {"path": "../jest-cli"}, + {"path": "../jest-core"} ] }