diff --git a/CHANGELOG.md b/CHANGELOG.md index 109f2fff0d7a..94a4e20cf389 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- `[jest-cli]` export functions compatible with `import {default}` ([#8080](https://github.com/facebook/jest/pull/8080)) - `[jest-worker]`: Fix retries and error notification in workers ([#8079](https://github.com/facebook/jest/pull/8079)) ### Chore & Maintenance diff --git a/e2e/__tests__/runProgrammatically.test.ts b/e2e/__tests__/runProgrammatically.test.ts index d6eecf7eac09..e9c1a8641e78 100644 --- a/e2e/__tests__/runProgrammatically.test.ts +++ b/e2e/__tests__/runProgrammatically.test.ts @@ -11,7 +11,12 @@ import {run} from '../Utils'; const dir = resolve(__dirname, '..', 'run-programmatically'); -test('run Jest programatically', () => { +test('run Jest programmatically cjs', () => { + const {stdout} = run(`node cjs.js --version`, dir); + expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*-dev$/); +}); + +test('run Jest programmatically esm', () => { const {stdout} = run(`node index.js --version`, dir); expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*-dev$/); }); diff --git a/e2e/run-programmatically/babel.config.js b/e2e/run-programmatically/babel.config.js new file mode 100644 index 000000000000..60a2a5c5a434 --- /dev/null +++ b/e2e/run-programmatically/babel.config.js @@ -0,0 +1,5 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + +module.exports = { + presets: ['@babel/preset-env'], +}; diff --git a/e2e/run-programmatically/cjs.js b/e2e/run-programmatically/cjs.js new file mode 100644 index 000000000000..2366de690bc4 --- /dev/null +++ b/e2e/run-programmatically/cjs.js @@ -0,0 +1,12 @@ +/** + * 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. + * + * @flow + */ + +// Running Jest like this is not officially supported, +// but it is common practice until there is a proper API as a substitute. +require('jest').run(process.argv); diff --git a/e2e/run-programmatically/esm.js b/e2e/run-programmatically/esm.js new file mode 100644 index 000000000000..f9120cd5599e --- /dev/null +++ b/e2e/run-programmatically/esm.js @@ -0,0 +1,14 @@ +/** + * 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. + * + * @flow + */ + +import myJestImport 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); diff --git a/e2e/run-programmatically/index.js b/e2e/run-programmatically/index.js index a397521b7c74..b45fa0b0e585 100644 --- a/e2e/run-programmatically/index.js +++ b/e2e/run-programmatically/index.js @@ -8,6 +8,6 @@ * @flow */ -// Running Jest like this is not officially supported, -// but it is common practice until there is a proper API as a substitute. -require('jest').run(process.argv); +require('@babel/register'); + +require('./esm'); diff --git a/packages/jest-cli/src/index.ts b/packages/jest-cli/src/index.ts index 956d00196105..38dcb1c26fb1 100644 --- a/packages/jest-cli/src/index.ts +++ b/packages/jest-cli/src/index.ts @@ -5,7 +5,16 @@ * LICENSE file in the root directory of this source tree. */ -// TODO: remove exports for the next major -export {runCLI, SearchSource, TestScheduler, TestWatcher} from '@jest/core'; -export {run} from './cli'; -export {default as getVersion} from './version'; +// TODO: remove @jest/core exports for the next major +import {runCLI, SearchSource, TestScheduler, TestWatcher} from '@jest/core'; +import {run} from './cli'; +import {default as getVersion} from './version'; + +export = { + SearchSource, + TestScheduler, + TestWatcher, + getVersion, + run, + runCLI, +}; diff --git a/packages/jest-core/package.json b/packages/jest-core/package.json index b8aad87ad328..b5452c0b62ed 100644 --- a/packages/jest-core/package.json +++ b/packages/jest-core/package.json @@ -34,7 +34,7 @@ "strip-ansi": "^5.0.0" }, "devDependencies": { - "@types/ansi-escapes": "^3.0.0", + "@types/ansi-escapes": "^3.0.1", "@types/exit": "^0.1.30", "@types/graceful-fs": "^4.1.2", "@types/micromatch": "^3.1.0", diff --git a/packages/jest-core/src/watch.ts b/packages/jest-core/src/watch.ts index 4aa5da965b59..b372d33fc04d 100644 --- a/packages/jest-core/src/watch.ts +++ b/packages/jest-core/src/watch.ts @@ -239,7 +239,6 @@ export default function watch( hasExitListener = true; process.on('exit', () => { if (activePlugin) { - // @ts-ignore: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/33423 outputStream.write(ansiEscapes.cursorDown()); outputStream.write(ansiEscapes.eraseDown); } @@ -404,7 +403,6 @@ export default function watch( break; case 'w': if (!shouldDisplayWatchUsage && !isWatchUsageDisplayed) { - // @ts-ignore: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/33423 outputStream.write(ansiEscapes.cursorUp()); outputStream.write(ansiEscapes.eraseDown); outputStream.write(usage(globalConfig, watchPlugins)); diff --git a/yarn.lock b/yarn.lock index 82c4663d3b04..340a5d50f880 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1564,10 +1564,10 @@ resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.7.0.tgz#9a06f4f137ee84d7df0460c1fdb1135ffa6c50fd" integrity sha512-ONhaKPIufzzrlNbqtWFFd+jlnemX6lJAgq9ZeiZtS7I1PIf/la7CW4m83rTXRnVnsMbW2k56pGYu7AUFJD9Pow== -"@types/ansi-escapes@^3.0.0": - version "3.0.0" - resolved "https://registry.yarnpkg.com/@types/ansi-escapes/-/ansi-escapes-3.0.0.tgz#619bbc6d46fc75da6d784e53b5a25d2efff07108" - integrity sha512-aamJrX6PdmIO8E9qhZaYmXiMGXwnkF2lcga/VbqLf8g90aaKGZ4cSFP5AabqxAbmp0h69C9yE3a4fUBtVpqtmg== +"@types/ansi-escapes@^3.0.0", "@types/ansi-escapes@^3.0.1": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@types/ansi-escapes/-/ansi-escapes-3.0.1.tgz#328e46c6ac3177ca4cf2efdeed326cf77da01ef7" + integrity sha512-GD/QLUGxSvy3yGQb+m12qsRtP4p/dewNePDb5F8qV19CXuO+gtbsmMjjsClpG/Nu84y8SF1zPKrTnQZHDiPUgg== dependencies: "@types/node" "*"