Skip to content

Commit 6a066c6

Browse files
authored
Revert ESM exports (#7602)
1 parent 50c3852 commit 6a066c6

File tree

109 files changed

+485
-416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+485
-416
lines changed

CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@
114114
### Chore & Maintenance
115115

116116
- `[*]` [**BREAKING**] Require Node.js 6+ for all packages ([#7258](https://github.com/facebook/jest/pull/7258))
117-
- `[*]` [**BREAKING**] Use ESM `import` and `export` all over ([#7548](https://github.com/facebook/jest/pull/7548))
118117
- `[jest-util]` [**BREAKING**] Remove long-deprecated globals for fake timers ([#7285](https://github.com/facebook/jest/pull/7285))
119118
- `[docs]` Fix message property in custom matcher example to return a function instead of a constant. ([#7426](https://github.com/facebook/jest/pull/7426))
120119
- `[jest-circus]` Standardize file naming in `jest-circus` ([#7301](https://github.com/facebook/jest/pull/7301))

e2e/__tests__/__snapshots__/moduleNameMapper.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ exports[`moduleNameMapper wrong configuration 1`] = `
3232
12 | module.exports = () => 'test';
3333
13 |
3434
35-
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:452:17)
35+
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:433:17)
3636
at Object.require (index.js:10:1)
3737
3838
"

e2e/__tests__/__snapshots__/resolveNoFileExtensions.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ exports[`show error message with matching files 1`] = `
3333
| ^
3434
4 |
3535
36-
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:217:17)
36+
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:200:17)
3737
at Object.require (index.js:3:18)
3838
3939
"

e2e/runJest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import path from 'path';
1212
import fs from 'fs';
1313
import execa, {sync as spawnSync} from 'execa';
1414
import {Writable} from 'readable-stream';
15-
import stripAnsi from 'strip-ansi';
15+
const stripAnsi = require('strip-ansi');
1616
import {normalizeIcons} from './Utils';
1717

1818
const JEST_PATH = path.resolve(__dirname, '../packages/jest-cli/bin/jest.js');

e2e/test-environment-async/TestEnvironment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const fs = require('fs');
66
const os = require('os');
77
const mkdirp = require('mkdirp');
8-
const JSDOMEnvironment = require('jest-environment-jsdom').default;
8+
const JSDOMEnvironment = require('jest-environment-jsdom');
99

1010
const DIR = os.tmpdir() + '/jest-test-environment';
1111

packages/babel-jest/src/__tests__/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
7-
8-
import babelJest from '../index';
7+
const babelJest = require('../index');
98

109
//Mock data for all the tests
1110
const sourceString = `

packages/babel-jest/src/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const jestPresetPath = require.resolve('babel-preset-jest');
2525
const babelIstanbulPlugin = require.resolve('babel-plugin-istanbul');
2626
const cwd = process.cwd();
2727

28-
export const createTransformer = (options: any): Transformer => {
28+
const createTransformer = (options: any): Transformer => {
2929
// Allow incoming options to override `cwd`
3030
options = Object.assign({cwd}, options, {
3131
caller: {
@@ -108,4 +108,5 @@ export const createTransformer = (options: any): Transformer => {
108108
};
109109
};
110110

111-
export default createTransformer();
111+
module.exports = createTransformer();
112+
(module.exports: any).createTransformer = createTransformer;

packages/babel-plugin-jest-hoist/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ FUNCTIONS.deepUnmock = args => args.length === 1 && args[0].isStringLiteral();
139139
FUNCTIONS.disableAutomock = FUNCTIONS.enableAutomock = args =>
140140
args.length === 0;
141141

142-
export default () => {
142+
module.exports = () => {
143143
const isJest = callee =>
144144
callee.get('object').isIdentifier(JEST_GLOBAL) ||
145145
(callee.isMemberExpression() && isJest(callee.get('object')));

packages/expect/src/__tests__/assertionCounts.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
'use strict';
1010

11-
import jestExpect from '../';
11+
const jestExpect = require('../');
1212

1313
describe('.assertions()', () => {
1414
it('does not throw', () => {

packages/expect/src/__tests__/asymmetricMatchers.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88

99
'use strict';
1010

11-
import jestExpect from '../';
12-
import {
11+
const jestExpect = require('../');
12+
const {
1313
any,
1414
anything,
1515
arrayContaining,
1616
arrayNotContaining,
1717
objectContaining,
1818
objectNotContaining,
1919
stringContaining,
20-
stringMatching,
2120
stringNotContaining,
21+
stringMatching,
2222
stringNotMatching,
23-
} from '../asymmetricMatchers';
23+
} = require('../asymmetricMatchers');
2424

2525
test('Any.asymmetricMatch()', () => {
2626
const Thing = function() {};

packages/expect/src/__tests__/extend.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
*
77
*/
88

9-
import * as matcherUtils from 'jest-matcher-utils';
10-
import {iterableEquality, subsetEquality} from '../utils';
11-
import {equals} from '../jasmineUtils';
12-
import jestExpect from '../';
9+
const matcherUtils = require('jest-matcher-utils');
10+
const {iterableEquality, subsetEquality} = require('../utils');
11+
const {equals} = require('../jasmineUtils');
12+
const jestExpect = require('../');
1313

1414
jestExpect.extend({
1515
toBeDivisibleBy(actual, expected) {

packages/expect/src/__tests__/matchers.test.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
*
77
*/
88

9-
import {stringify} from 'jest-matcher-utils';
10-
import jestExpect from '../';
11-
import Immutable from 'immutable';
12-
import chalk from 'chalk';
13-
9+
const {stringify} = require('jest-matcher-utils');
10+
const jestExpect = require('../');
11+
const Immutable = require('immutable');
12+
const chalk = require('chalk');
1413
const chalkEnabled = chalk.enabled;
1514

1615
beforeAll(() => {

packages/expect/src/__tests__/spyMatchers.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*
77
*/
88

9-
import Immutable from 'immutable';
10-
import jestExpect from '../';
9+
const Immutable = require('immutable');
10+
const jestExpect = require('../');
1111

1212
['toBeCalled', 'toHaveBeenCalled'].forEach(called => {
1313
describe(`${called}`, () => {

packages/expect/src/__tests__/stacktrace.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*/
88

9-
import jestExpect from '../';
9+
const jestExpect = require('../');
1010

1111
jestExpect.extend({
1212
toCustomMatch(callback, expectation) {

packages/expect/src/__tests__/toThrowMatchers.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
'use strict';
1010

11-
import jestExpect from '../';
11+
const jestExpect = require('../');
1212

1313
// Custom Error class because node versions have different stack trace strings.
1414
class customError extends Error {

packages/expect/src/__tests__/utils.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
'use strict';
1010

11-
import {stringify} from 'jest-matcher-utils';
12-
import {
11+
const {stringify} = require('jest-matcher-utils');
12+
const {
1313
emptyObject,
1414
getObjectSubset,
1515
getPath,
1616
hasOwnProperty,
1717
subsetEquality,
18-
} from '../utils';
18+
} = require('../utils');
1919

2020
describe('getPath()', () => {
2121
test('property exists', () => {

packages/expect/src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const getPromiseMatcher = (name, matcher) => {
7777
return null;
7878
};
7979

80-
const expect = (actual: any, ...rest: Array<any>): ExpectationObject => {
80+
const expect = (actual: any, ...rest): ExpectationObject => {
8181
if (rest.length !== 0) {
8282
throw new Error('Expect takes at most one argument.');
8383
}
@@ -361,7 +361,7 @@ function assertions(expected: number) {
361361
getState().expectedAssertionsNumber = expected;
362362
getState().expectedAssertionsNumberError = error;
363363
}
364-
function hasAssertions(...args: Array<any>) {
364+
function hasAssertions(...args) {
365365
const error = new Error();
366366
if (Error.captureStackTrace) {
367367
Error.captureStackTrace(error, hasAssertions);
@@ -384,4 +384,4 @@ expect.getState = getState;
384384
expect.setState = setState;
385385
expect.extractExpectedAssertionsErrors = extractExpectedAssertionsErrors;
386386

387-
export default (expect: Expect);
387+
module.exports = (expect: Expect);

packages/jest-circus/src/__tests__/circusItTestError.test.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,19 @@
99

1010
'use strict';
1111

12+
let circusIt;
13+
let circusTest;
14+
1215
// using jest-jasmine2's 'it' to test jest-circus's 'it'. Had to differentiate
1316
// the two with this alias.
14-
import {it as circusIt, test as circusTest} from '../index.js';
17+
18+
const aliasCircusIt = () => {
19+
const {it, test} = require('../index.js');
20+
circusIt = it;
21+
circusTest = test;
22+
};
23+
24+
aliasCircusIt();
1525

1626
// A few of these tests require incorrect types to throw errors and thus pass
1727
// the test. The typechecks on jest-circus would prevent that, so

packages/jest-circus/src/__tests__/circusItTodoTestError.test.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@
99

1010
'use strict';
1111

12+
let circusIt;
13+
1214
// using jest-jasmine2's 'it' to test jest-circus's 'it'. Had to differentiate
1315
// the two with this alias.
14-
import {it as circusIt} from '../index.js';
16+
17+
const aliasCircusIt = () => {
18+
const {it} = require('../index.js');
19+
circusIt = it;
20+
};
21+
22+
aliasCircusIt();
1523

1624
describe('test/it.todo error throwing', () => {
1725
it('todo throws error when given no arguments', () => {

packages/jest-circus/src/__tests__/hooksError.test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
import * as circus from '../index.js';
12+
const circus = require('../index.js');
1313

1414
describe.each([['beforeEach'], ['beforeAll'], ['afterEach'], ['afterAll']])(
1515
'%s hooks error throwing',
@@ -27,7 +27,6 @@ describe.each([['beforeEach'], ['beforeAll'], ['afterEach'], ['afterAll']])(
2727
`${fn} throws an error when %p is provided as a first argument to it`,
2828
el => {
2929
expect(() => {
30-
// eslint-disable-next-line import/namespace
3130
circus[fn](el);
3231
}).toThrowError(
3332
'Invalid first argument. It must be a callback function.',

packages/jest-circus/src/index.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {dispatch} from './state';
2323

2424
type THook = (fn: HookFn, timeout?: number) => void;
2525

26-
export const describe = (blockName: BlockName, blockFn: BlockFn) =>
26+
const describe = (blockName: BlockName, blockFn: BlockFn) =>
2727
_dispatchDescribe(blockFn, blockName, describe);
2828
describe.only = (blockName: BlockName, blockFn: BlockFn) =>
2929
_dispatchDescribe(blockFn, blockName, describe.only, 'only');
@@ -69,18 +69,18 @@ const _addHook = (fn: HookFn, hookType: HookType, hookFn, timeout: ?number) => {
6969
};
7070

7171
// Hooks have to pass themselves to the HOF in order for us to trim stack traces.
72-
export const beforeEach: THook = (fn, timeout) =>
72+
const beforeEach: THook = (fn, timeout) =>
7373
_addHook(fn, 'beforeEach', beforeEach, timeout);
74-
export const beforeAll: THook = (fn, timeout) =>
74+
const beforeAll: THook = (fn, timeout) =>
7575
_addHook(fn, 'beforeAll', beforeAll, timeout);
76-
export const afterEach: THook = (fn, timeout) =>
76+
const afterEach: THook = (fn, timeout) =>
7777
_addHook(fn, 'afterEach', afterEach, timeout);
78-
export const afterAll: THook = (fn, timeout) =>
78+
const afterAll: THook = (fn, timeout) =>
7979
_addHook(fn, 'afterAll', afterAll, timeout);
8080

81-
export const test = (testName: TestName, fn: TestFn, timeout?: number) =>
81+
const test = (testName: TestName, fn: TestFn, timeout?: number) =>
8282
_addTest(testName, undefined, fn, test, timeout);
83-
export const it = test;
83+
const it = test;
8484
test.skip = (testName: TestName, fn?: TestFn, timeout?: number) =>
8585
_addTest(testName, 'skip', fn, test.skip, timeout);
8686
test.only = (testName: TestName, fn: TestFn, timeout?: number) =>
@@ -138,3 +138,13 @@ test.skip.each = bindEach(test.skip);
138138
describe.each = bindEach(describe, false);
139139
describe.only.each = bindEach(describe.only, false);
140140
describe.skip.each = bindEach(describe.skip, false);
141+
142+
module.exports = {
143+
afterAll,
144+
afterEach,
145+
beforeAll,
146+
beforeEach,
147+
describe,
148+
it,
149+
test,
150+
};

packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import type Runtime from 'jest-runtime';
1515
const FRAMEWORK_INITIALIZER = require.resolve('./jestAdapterInit');
1616
import path from 'path';
1717

18-
export default async function jestAdapter(
18+
const jestAdapter = async (
1919
globalConfig: GlobalConfig,
2020
config: ProjectConfig,
2121
environment: Environment,
2222
runtime: Runtime,
2323
testPath: string,
24-
): Promise<TestResult> {
24+
): Promise<TestResult> => {
2525
const {
2626
initialize,
2727
runAndTransformResultsToJestFormat,
@@ -82,7 +82,7 @@ export default async function jestAdapter(
8282
testPath,
8383
});
8484
return _addSnapshotData(results, snapshotState);
85-
}
85+
};
8686

8787
const _addSnapshotData = (results: TestResult, snapshotState) => {
8888
results.testResults.forEach(({fullName, status}) => {
@@ -110,3 +110,5 @@ const _addSnapshotData = (results: TestResult, snapshotState) => {
110110
results.snapshot.uncheckedKeys = Array.from(uncheckedKeys);
111111
return results;
112112
};
113+
114+
module.exports = jestAdapter;

0 commit comments

Comments
 (0)