Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: convert jest-cli and jest-validate to esm #8874

Merged
merged 5 commits into from Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
thymikee marked this conversation as resolved.
Show resolved Hide resolved
};
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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

followup from last question, should we ditch these exports as well?

A reason not to is that we don't really have a programmatic API yet (and won't from jest 25), so all we'd do is ask people to import directly from @jest/core or jest-cli. I think that if we first ask people to change their imports, we should also give them a real API rather than the internal ones that are used now

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as we don't have clear vision of the new API, I wouldn't change that just yet

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"}
]
}