Skip to content

Commit

Permalink
chore: convert jest-cli and jest-validate to esm (#8874)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Aug 26, 2019
1 parent 6e6a8e8 commit 438118a
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 48 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -22,9 +22,14 @@
- `[*]` [**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-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))

### Performance

Expand Down
2 changes: 0 additions & 2 deletions e2e/run-programmatically/cjs.js
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions e2e/run-programmatically/esm.js
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion packages/babel-plugin-jest-hoist/src/index.ts
Expand Up @@ -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;
Expand Down
19 changes: 1 addition & 18 deletions packages/jest-cli/src/index.ts
Expand Up @@ -5,21 +5,4 @@
* LICENSE file in the root directory of this source tree.
*/

// TODO: remove @jest/core exports for the next major
import {
SearchSource,
TestScheduler,
TestWatcher,
getVersion,
runCLI,
} from '@jest/core';
import {run} from './cli';

export = {
SearchSource,
TestScheduler,
TestWatcher,
getVersion,
run,
runCLI,
};
export {run} from './cli';
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/index.ts
Expand Up @@ -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);

Expand Down
8 changes: 3 additions & 5 deletions packages/jest-jasmine2/src/jasmine/jasmineLight.ts
Expand Up @@ -40,7 +40,7 @@ import SpyRegistry from './spyRegistry';
import Suite from './Suite';
import Timer from './Timer';

const create = function(createOptions: Record<string, any>): Jasmine {
export const create = function(createOptions: Record<string, any>): Jasmine {
const j$ = {...createOptions} as Jasmine;

j$._DEFAULT_TIMEOUT_INTERVAL = createOptions.testTimeout || 5000;
Expand All @@ -63,7 +63,8 @@ const create = function(createOptions: Record<string, any>): 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);
Expand Down Expand Up @@ -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};
18 changes: 4 additions & 14 deletions packages/jest-validate/src/index.ts
Expand Up @@ -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';
1 change: 1 addition & 0 deletions packages/jest/package.json
Expand Up @@ -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"
},
Expand Down
10 changes: 8 additions & 2 deletions packages/jest/src/jest.ts
Expand Up @@ -5,6 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import * as cli from 'jest-cli';
export {
SearchSource,
TestScheduler,
TestWatcher,
getVersion,
runCLI,
} from '@jest/core';

export = cli;
export {run} from 'jest-cli';
3 changes: 2 additions & 1 deletion packages/jest/tsconfig.json
Expand Up @@ -5,6 +5,7 @@
"outDir": "build"
},
"references": [
{"path": "../jest-cli"}
{"path": "../jest-cli"},
{"path": "../jest-core"}
]
}

0 comments on commit 438118a

Please sign in to comment.