Skip to content

Commit

Permalink
Use ES module exports (jestjs#4454)
Browse files Browse the repository at this point in the history
* Use ESM exports in jest-config

* Use ESM exports in eslint-plugin-jest

* Use ESM exports in jest-changed-files

* Use ESM exports in jest-circus

* Use ESM exports in jest-diff

* Use ESM exports in jest-editor-support

* Use ESM exports in jest-haste-map

* Use ESM exports in jest-jasmine2

* Use ESM exports in jest-message-util

* Use ESM exports in jest-regex-util

* Use ESM exports in jest-repl

* Use ESM exports in jest-resolve

* Use ESM exports in jest-runner

* Use ESM exports in jest-runtime

* Use ESM exports in jest-snapshot

* Use ESM exports in jest-test-typescript-parser

* Use ESM exports in jest-util

* Use ESM exports in jest-validate

* Fix flow errors

* Activate eslint plugin to enforce correct ESM usage

* Use ESM exports in jest-cli
  • Loading branch information
SimenB authored and tabrindle committed Oct 2, 2017
1 parent 173fc41 commit 5681788
Show file tree
Hide file tree
Showing 213 changed files with 494 additions and 761 deletions.
4 changes: 0 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ module.exports = {
'flowtype/boolean-style': 2,
'flowtype/no-primitive-constructor-types': 2,
'flowtype/require-valid-file-annotation': 2,
// These has to be disabled until the whole code base is converted to ESM
'import/default': 0,
'import/named': 0,
'import/no-duplicates': 2,
'import/no-extraneous-dependencies': [
2,
Expand All @@ -149,7 +146,6 @@ module.exports = {
],
},
],
'import/no-unresolved': [2, {ignore: ['^types/']}],
// This has to be disabled until all type and module imports are combined
// https://github.com/benmosher/eslint-plugin-import/issues/645
'import/order': 0,
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/__tests__/find_related_files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
'use strict';

import runJest from '../runJest';
import {cleanup, writeFiles} from '../utils';
import os from 'os';
import path from 'path';

const {cleanup, writeFiles} = require('../utils');

const skipOnWindows = require('../../scripts/skip_on_windows');
const DIR = path.resolve(os.tmpdir(), 'find_related_tests_test');

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/__tests__/force_exit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
'use strict';

import runJest from '../runJest';
import {cleanup, writeFiles} from '../utils';
import os from 'os';
import path from 'path';
const {cleanup, writeFiles} = require('../utils');

const skipOnWindows = require('../../scripts/skip_on_windows');
const DIR = path.resolve(os.tmpdir(), 'force_exit_test');
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/__tests__/jest_changed_files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

'use strict';

import {cleanup, run, writeFiles} from '../utils';
import os from 'os';
import path from 'path';
import {
findRepos,
getChangedFilesForRoots,
} from '../../packages/jest-changed-files/src';

const skipOnWindows = require('../../scripts/skip_on_windows');
const {cleanup, run, writeFiles} = require('../utils');

skipOnWindows.suite();

const DIR = path.resolve(os.tmpdir(), 'jest_changed_files_test_dir');
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/__tests__/multi_project_runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
'use strict';

import runJest from '../runJest';
import {cleanup, extractSummary, writeFiles} from '../utils';
import os from 'os';
import path from 'path';

const {cleanup, extractSummary, writeFiles} = require('../utils');
const skipOnWindows = require('../../scripts/skip_on_windows');
const DIR = path.resolve(os.tmpdir(), 'multi_project_runner_test');

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/__tests__/only_changed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
'use strict';

import runJest from '../runJest';
import {cleanup, run, writeFiles} from '../utils';
import os from 'os';
import path from 'path';
const {cleanup, run, writeFiles} = require('../utils');

const skipOnWindows = require('../../scripts/skip_on_windows');
const DIR = path.resolve(os.tmpdir(), 'jest_only_changed');
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/__tests__/run_tests_by_path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
'use strict';

import runJest from '../runJest';
import {cleanup, writeFiles} from '../utils';
import os from 'os';
import path from 'path';
const {cleanup, writeFiles} = require('../utils');

const skipOnWindows = require('../../scripts/skip_on_windows');
const DIR = path.resolve(os.tmpdir(), 'run_tests_by_path_test');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
'use strict';

import runJest from '../runJest';
import {cleanup, writeFiles} from '../utils';
import os from 'os';
import path from 'path';
const {cleanup, writeFiles} = require('../utils');

const skipOnWindows = require('../../scripts/skip_on_windows');
const DIR = path.resolve(os.tmpdir(), 'jest_path_pattern_reporter_message');
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/__tests__/use_stderr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
'use strict';

import runJest from '../runJest';
import {cleanup, writeFiles} from '../utils';
import os from 'os';
import path from 'path';
const {cleanup, writeFiles} = require('../utils');

const skipOnWindows = require('../../scripts/skip_on_windows');
const DIR = path.resolve(os.tmpdir(), 'use_stderr_test');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

'use strict';

const RuleTester = require('eslint').RuleTester;
const rules = require('../../').rules;
import {RuleTester} from 'eslint';
const {rules} = require('../../');

const ruleTester = new RuleTester();
const expectedErrorMessage = 'Unexpected focused test.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

'use strict';

const RuleTester = require('eslint').RuleTester;
const rules = require('../../').rules;
import {RuleTester} from 'eslint';
const {rules} = require('../../');

const ruleTester = new RuleTester();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

'use strict';

const RuleTester = require('eslint').RuleTester;
const rules = require('../../').rules;
import {RuleTester} from 'eslint';
const {rules} = require('../../');

const ruleTester = new RuleTester();
const expectedErrorMessage = 'Unexpected disabled test.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

'use strict';

const RuleTester = require('eslint').RuleTester;
const rules = require('../../').rules;
import {RuleTester} from 'eslint';
const {rules} = require('../../');

const ruleTester = new RuleTester();

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-jest/src/rules/no_disabled_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const isPropertyNamedSkip = property =>
const isCallToTestSkipFunction = callee =>
matchesTestFunction(callee.object) && isPropertyNamedSkip(callee.property);

module.exports = (context: EslintContext) => ({
export default (context: EslintContext) => ({
CallExpression(node: CallExpression) {
const callee = node.callee;
if (!callee) {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-jest/src/rules/no_focused_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const isPropertyNamedOnly = property =>
const isCallToTestOnlyFunction = callee =>
matchesTestFunction(callee.object) && isPropertyNamedOnly(callee.property);

module.exports = (context: EslintContext) => ({
export default (context: EslintContext) => ({
CallExpression(node: CallExpression) {
const callee = node.callee;
if (!callee) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const handleTestSuiteTitles = (context, titles, node, title) => {
const isFirstArgLiteral = node =>
node.arguments && node.arguments[0] && node.arguments[0].type === 'Literal';

module.exports = (context: EslintContext) => {
export default (context: EslintContext) => {
const contexts = [newDescribeContext()];
return {
CallExpression(node: CallExpression) {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-jest/src/rules/valid_expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {EslintContext, CallExpression} from './types';

const expectProperties = ['not', 'resolves', 'rejects'];

module.exports = (context: EslintContext) => {
export default (context: EslintContext) => {
return {
CallExpression(node: CallExpression) {
const calleeName = node.callee.name;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-changed-files/src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ const adapter: SCMAdapter = {
},
};

module.exports = adapter;
export default adapter;
2 changes: 1 addition & 1 deletion packages/jest-changed-files/src/hg.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ const adapter: SCMAdapter = {
},
};

module.exports = adapter;
export default adapter;
9 changes: 2 additions & 7 deletions packages/jest-changed-files/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const mutex = throat(5);
const findGitRoot = dir => mutex(() => git.getRoot(dir));
const findHgRoot = dir => mutex(() => hg.getRoot(dir));

const getChangedFilesForRoots = async (
export const getChangedFilesForRoots = async (
roots: Array<Path>,
options: Options,
): ChangedFilesPromise => {
Expand All @@ -49,7 +49,7 @@ const getChangedFilesForRoots = async (
return {changedFiles, repos};
};

const findRepos = async (roots: Array<Path>): Promise<Repos> => {
export const findRepos = async (roots: Array<Path>): Promise<Repos> => {
const gitRepos = await Promise.all(
roots.reduce((promises, root) => promises.concat(findGitRoot(root)), []),
);
Expand All @@ -62,8 +62,3 @@ const findRepos = async (roots: Array<Path>): Promise<Repos> => {
hg: new Set(hgRepos.filter(Boolean)),
};
};

module.exports = {
findRepos,
getChangedFilesForRoots,
};
2 changes: 1 addition & 1 deletion packages/jest-circus/src/event_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ const handler: EventHandler = (event, state): void => {
}
};

module.exports = handler;
export default handler;
2 changes: 1 addition & 1 deletion packages/jest-circus/src/format_node_assert_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const humanReadableOperators = {
notDeepStrictEqual: 'not to deeply and strictly equal',
};

module.exports = (event: Event, state: State) => {
export default (event: Event, state: State) => {
switch (event.name) {
case 'test_failure':
case 'test_success': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ const _addSnapshotData = (results: TestResult, snapshotState) => {
return results;
};

module.exports = jestAdapter;
export default jestAdapter;
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import {SnapshotState, addSerializer} from 'jest-snapshot';
import {addEventHandler, ROOT_DESCRIBE_BLOCK_NAME} from '../state';
import {getTestID} from '../utils';
import run from '../run';
// eslint-disable-next-line import/default
import globals from '../index';

const initialize = ({
export const initialize = ({
config,
globalConfig,
localRequire,
Expand Down Expand Up @@ -58,7 +59,7 @@ const initialize = ({
return {globals, snapshotState};
};

const runAndTransformResultsToJestFormat = async ({
export const runAndTransformResultsToJestFormat = async ({
config,
globalConfig,
testPath,
Expand Down Expand Up @@ -184,8 +185,3 @@ const _addSuppressedErrors = (test: TestEntry) => {
test.errors = test.errors.concat(suppressedErrors);
}
};

module.exports = {
initialize,
runAndTransformResultsToJestFormat,
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type JasmineMatcher = {
negativeCompare: () => RawMatcherFn,
};

module.exports = (config: {expand: boolean}) => {
export default (config: {expand: boolean}) => {
global.expect = expect;
expect.setState({
expand: config.expand,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ const _callTest = async (
.catch(error => dispatch({error, name: 'test_failure', test}));
};

module.exports = run;
export default run;
18 changes: 5 additions & 13 deletions packages/jest-circus/src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const eventHandlers: Array<EventHandler> = [
formatNodeAssertErrors,
];

const ROOT_DESCRIBE_BLOCK_NAME = 'ROOT_DESCRIBE_BLOCK';
export const ROOT_DESCRIBE_BLOCK_NAME = 'ROOT_DESCRIBE_BLOCK';
const STATE_SYM = Symbol('JEST_STATE_SYMBOL');

const ROOT_DESCRIBE_BLOCK = makeDescribe(ROOT_DESCRIBE_BLOCK_NAME);
Expand All @@ -33,23 +33,15 @@ const INITIAL_STATE: State = {

global[STATE_SYM] = INITIAL_STATE;

const getState = (): State => global[STATE_SYM];
const setState = (state: State): State => (global[STATE_SYM] = state);
export const getState = (): State => global[STATE_SYM];
export const setState = (state: State): State => (global[STATE_SYM] = state);

const dispatch = (event: Event): void => {
export const dispatch = (event: Event): void => {
for (const handler of eventHandlers) {
handler(event, getState());
}
};

const addEventHandler = (handler: EventHandler): void => {
export const addEventHandler = (handler: EventHandler): void => {
eventHandlers.push(handler);
};

module.exports = {
ROOT_DESCRIBE_BLOCK_NAME,
addEventHandler,
dispatch,
getState,
setState,
};
Loading

0 comments on commit 5681788

Please sign in to comment.