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

convert all exports to ESM #7548

Merged
merged 2 commits into from
Dec 26, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
### Chore & Maintenance

- `[*]` [**BREAKING**] Require Node.js 6+ for all packages ([#7258](https://github.com/facebook/jest/pull/7258))
- `[*]` [**BREAKING**] Use ESM `import` and `export` all over ([#7548](https://github.com/facebook/jest/pull/7548))
- `[jest-util]` [**BREAKING**] Remove long-deprecated globals for fake timers ([#7285](https://github.com/facebook/jest/pull/7285))
- `[docs]` Fix message property in custom matcher example to return a function instead of a constant. ([#7426](https://github.com/facebook/jest/pull/7426))
- `[jest-circus]` Standardize file naming in `jest-circus` ([#7301](https://github.com/facebook/jest/pull/7301))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports[`moduleNameMapper wrong configuration 1`] = `
12 | module.exports = () => 'test';
13 |

at packages/jest-resolve/build/index.js:433:17
at packages/jest-resolve/build/index.js:452:17
at index.js:10:1

"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exports[`show error message with matching files 1`] = `
| ^
4 |

at packages/jest-resolve/build/index.js:200:17
at packages/jest-resolve/build/index.js:217:17
at index.js:3:18

"
Expand Down
2 changes: 1 addition & 1 deletion e2e/runJest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import path from 'path';
import fs from 'fs';
import execa, {sync as spawnSync} from 'execa';
import {Writable} from 'readable-stream';
const stripAnsi = require('strip-ansi');
import stripAnsi from 'strip-ansi';
import {normalizeIcons} from './Utils';

const JEST_PATH = path.resolve(__dirname, '../packages/jest-cli/bin/jest.js');
Expand Down
2 changes: 1 addition & 1 deletion e2e/test-environment-async/TestEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const fs = require('fs');
const os = require('os');
const mkdirp = require('mkdirp');
const JSDOMEnvironment = require('jest-environment-jsdom');
const JSDOMEnvironment = require('jest-environment-jsdom').default;

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

Expand Down
3 changes: 2 additions & 1 deletion packages/babel-jest/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const babelJest = require('../index');

import babelJest from '../index';

//Mock data for all the tests
const sourceString = `
Expand Down
5 changes: 2 additions & 3 deletions packages/babel-jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import babelIstanbulPlugin from 'babel-plugin-istanbul';
const THIS_FILE = fs.readFileSync(__filename);
const jestPresetPath = require.resolve('babel-preset-jest');

const createTransformer = (options: any): Transformer => {
export const createTransformer = (options: any): Transformer => {
options = Object.assign({}, options, {
compact: false,
plugins: (options && options.plugins) || [],
Expand Down Expand Up @@ -110,5 +110,4 @@ const createTransformer = (options: any): Transformer => {
};
};

module.exports = createTransformer();
(module.exports: any).createTransformer = createTransformer;
export default createTransformer();
2 changes: 1 addition & 1 deletion packages/babel-plugin-jest-hoist/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ FUNCTIONS.deepUnmock = args => args.length === 1 && args[0].isStringLiteral();
FUNCTIONS.disableAutomock = FUNCTIONS.enableAutomock = args =>
args.length === 0;

module.exports = () => {
export default () => {
const isJest = callee =>
callee.get('object').isIdentifier(JEST_GLOBAL) ||
(callee.isMemberExpression() && isJest(callee.get('object')));
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/src/__tests__/assertionCounts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

'use strict';

const jestExpect = require('../');
import jestExpect from '../';

describe('.assertions()', () => {
it('does not throw', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/expect/src/__tests__/asymmetricMatchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

'use strict';

const jestExpect = require('../');
const {
import jestExpect from '../';
import {
any,
anything,
arrayContaining,
arrayNotContaining,
objectContaining,
objectNotContaining,
stringContaining,
stringNotContaining,
stringMatching,
stringNotContaining,
stringNotMatching,
} = require('../asymmetricMatchers');
} from '../asymmetricMatchers';

test('Any.asymmetricMatch()', () => {
const Thing = function() {};
Expand Down
8 changes: 4 additions & 4 deletions packages/expect/src/__tests__/extend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*
*/

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

jestExpect.extend({
toBeDivisibleBy(actual, expected) {
Expand Down
9 changes: 5 additions & 4 deletions packages/expect/src/__tests__/matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
*
*/

const {stringify} = require('jest-matcher-utils');
const jestExpect = require('../');
const Immutable = require('immutable');
const chalk = require('chalk');
import {stringify} from 'jest-matcher-utils';
import jestExpect from '../';
import Immutable from 'immutable';
import chalk from 'chalk';

const chalkEnabled = chalk.enabled;

beforeAll(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/expect/src/__tests__/spyMatchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*
*/

const Immutable = require('immutable');
const jestExpect = require('../');
import Immutable from 'immutable';
import jestExpect from '../';

['toBeCalled', 'toHaveBeenCalled'].forEach(called => {
describe(`${called}`, () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/src/__tests__/stacktrace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*/

const jestExpect = require('../');
import jestExpect from '../';

jestExpect.extend({
toCustomMatch(callback, expectation) {
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/src/__tests__/toThrowMatchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

'use strict';

const jestExpect = require('../');
import jestExpect from '../';

// Custom Error class because node versions have different stack trace strings.
class customError extends Error {
Expand Down
6 changes: 3 additions & 3 deletions packages/expect/src/__tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

'use strict';

const {stringify} = require('jest-matcher-utils');
const {
import {stringify} from 'jest-matcher-utils';
import {
emptyObject,
getObjectSubset,
getPath,
hasOwnProperty,
subsetEquality,
} = require('../utils');
} from '../utils';

describe('getPath()', () => {
test('property exists', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/expect/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const getPromiseMatcher = (name, matcher) => {
return null;
};

const expect = (actual: any, ...rest): ExpectationObject => {
const expect = (actual: any, ...rest: Array<any>): ExpectationObject => {
if (rest.length !== 0) {
throw new Error('Expect takes at most one argument.');
}
Expand Down Expand Up @@ -361,7 +361,7 @@ function assertions(expected: number) {
getState().expectedAssertionsNumber = expected;
getState().expectedAssertionsNumberError = error;
}
function hasAssertions(...args) {
function hasAssertions(...args: Array<any>) {
const error = new Error();
if (Error.captureStackTrace) {
Error.captureStackTrace(error, hasAssertions);
Expand All @@ -384,4 +384,4 @@ expect.getState = getState;
expect.setState = setState;
expect.extractExpectedAssertionsErrors = extractExpectedAssertionsErrors;

module.exports = (expect: Expect);
export default (expect: Expect);
12 changes: 1 addition & 11 deletions packages/jest-circus/src/__tests__/circusItTestError.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,9 @@

'use strict';

let circusIt;
let circusTest;

// using jest-jasmine2's 'it' to test jest-circus's 'it'. Had to differentiate
// the two with this alias.

const aliasCircusIt = () => {
const {it, test} = require('../index.js');
circusIt = it;
circusTest = test;
};

aliasCircusIt();
import {it as circusIt, test as circusTest} from '../index.js';

// A few of these tests require incorrect types to throw errors and thus pass
// the test. The typechecks on jest-circus would prevent that, so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@

'use strict';

let circusIt;

// using jest-jasmine2's 'it' to test jest-circus's 'it'. Had to differentiate
// the two with this alias.

const aliasCircusIt = () => {
const {it} = require('../index.js');
circusIt = it;
};

aliasCircusIt();
import {it as circusIt} from '../index.js';

describe('test/it.todo error throwing', () => {
it('todo throws error when given no arguments', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-circus/src/__tests__/hooksError.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

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

describe.each([['beforeEach'], ['beforeAll'], ['afterEach'], ['afterAll']])(
'%s hooks error throwing',
Expand All @@ -27,6 +27,7 @@ describe.each([['beforeEach'], ['beforeAll'], ['afterEach'], ['afterAll']])(
`${fn} throws an error when %p is provided as a first argument to it`,
el => {
expect(() => {
// eslint-disable-next-line import/namespace
circus[fn](el);
}).toThrowError(
'Invalid first argument. It must be a callback function.',
Expand Down
24 changes: 7 additions & 17 deletions packages/jest-circus/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {dispatch} from './state';

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

const describe = (blockName: BlockName, blockFn: BlockFn) =>
export const describe = (blockName: BlockName, blockFn: BlockFn) =>
_dispatchDescribe(blockFn, blockName, describe);
describe.only = (blockName: BlockName, blockFn: BlockFn) =>
_dispatchDescribe(blockFn, blockName, describe.only, 'only');
Expand Down Expand Up @@ -69,18 +69,18 @@ const _addHook = (fn: HookFn, hookType: HookType, hookFn, timeout: ?number) => {
};

// Hooks have to pass themselves to the HOF in order for us to trim stack traces.
const beforeEach: THook = (fn, timeout) =>
export const beforeEach: THook = (fn, timeout) =>
_addHook(fn, 'beforeEach', beforeEach, timeout);
const beforeAll: THook = (fn, timeout) =>
export const beforeAll: THook = (fn, timeout) =>
_addHook(fn, 'beforeAll', beforeAll, timeout);
const afterEach: THook = (fn, timeout) =>
export const afterEach: THook = (fn, timeout) =>
_addHook(fn, 'afterEach', afterEach, timeout);
const afterAll: THook = (fn, timeout) =>
export const afterAll: THook = (fn, timeout) =>
_addHook(fn, 'afterAll', afterAll, timeout);

const test = (testName: TestName, fn: TestFn, timeout?: number) =>
export const test = (testName: TestName, fn: TestFn, timeout?: number) =>
_addTest(testName, undefined, fn, test, timeout);
const it = test;
export const it = test;
test.skip = (testName: TestName, fn?: TestFn, timeout?: number) =>
_addTest(testName, 'skip', fn, test.skip, timeout);
test.only = (testName: TestName, fn: TestFn, timeout?: number) =>
Expand Down Expand Up @@ -138,13 +138,3 @@ test.skip.each = bindEach(test.skip);
describe.each = bindEach(describe, false);
describe.only.each = bindEach(describe.only, false);
describe.skip.each = bindEach(describe.skip, false);

module.exports = {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
it,
test,
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import type Runtime from 'jest-runtime';
const FRAMEWORK_INITIALIZER = require.resolve('./jestAdapterInit');
import path from 'path';

const jestAdapter = async (
export default async function jestAdapter(
globalConfig: GlobalConfig,
config: ProjectConfig,
environment: Environment,
runtime: Runtime,
testPath: string,
): Promise<TestResult> => {
): Promise<TestResult> {
const {
initialize,
runAndTransformResultsToJestFormat,
Expand Down Expand Up @@ -82,7 +82,7 @@ const jestAdapter = async (
testPath,
});
return _addSnapshotData(results, snapshotState);
};
}

const _addSnapshotData = (results: TestResult, snapshotState) => {
results.testResults.forEach(({fullName, status}) => {
Expand Down Expand Up @@ -110,5 +110,3 @@ const _addSnapshotData = (results: TestResult, snapshotState) => {
results.snapshot.uncheckedKeys = Array.from(uncheckedKeys);
return results;
};

module.exports = jestAdapter;
Loading