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

Revert ESM exports #7602

Merged
merged 1 commit into from
Jan 10, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
### 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
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/moduleNameMapper.test.js.snap
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 createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:452:17)
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:433:17)
at Object.require (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 Resolver.resolveModule (../../packages/jest-resolve/build/index.js:217:17)
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:200:17)
at Object.require (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';
import stripAnsi from 'strip-ansi';
const stripAnsi = require('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').default;
const JSDOMEnvironment = require('jest-environment-jsdom');

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

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

import babelJest from '../index';
const babelJest = require('../index');

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

export const createTransformer = (options: any): Transformer => {
const createTransformer = (options: any): Transformer => {
// Allow incoming options to override `cwd`
options = Object.assign({cwd}, options, {
caller: {
Expand Down Expand Up @@ -108,4 +108,5 @@ export const createTransformer = (options: any): Transformer => {
};
};

export default createTransformer();
module.exports = createTransformer();
(module.exports: any).createTransformer = 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;

export default () => {
module.exports = () => {
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';

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

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';

import jestExpect from '../';
import {
const jestExpect = require('../');
const {
any,
anything,
arrayContaining,
arrayNotContaining,
objectContaining,
objectNotContaining,
stringContaining,
stringMatching,
stringNotContaining,
stringMatching,
stringNotMatching,
} from '../asymmetricMatchers';
} = require('../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 @@
*
*/

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

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

import {stringify} from 'jest-matcher-utils';
import jestExpect from '../';
import Immutable from 'immutable';
import chalk from 'chalk';

const {stringify} = require('jest-matcher-utils');
const jestExpect = require('../');
const Immutable = require('immutable');
const chalk = require('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 @@
*
*/

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

['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 @@
*
*/

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

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';

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

// 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';

import {stringify} from 'jest-matcher-utils';
import {
const {stringify} = require('jest-matcher-utils');
const {
emptyObject,
getObjectSubset,
getPath,
hasOwnProperty,
subsetEquality,
} from '../utils';
} = require('../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: Array<any>): ExpectationObject => {
const expect = (actual: any, ...rest): 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: Array<any>) {
function hasAssertions(...args) {
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;

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

'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.
import {it as circusIt, test as circusTest} from '../index.js';

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

aliasCircusIt();

// 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,9 +9,17 @@

'use strict';

let circusIt;

// using jest-jasmine2's 'it' to test jest-circus's 'it'. Had to differentiate
// the two with this alias.
import {it as circusIt} from '../index.js';

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

aliasCircusIt();

describe('test/it.todo error throwing', () => {
it('todo throws error when given no arguments', () => {
Expand Down
3 changes: 1 addition & 2 deletions 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';

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

describe.each([['beforeEach'], ['beforeAll'], ['afterEach'], ['afterAll']])(
'%s hooks error throwing',
Expand All @@ -27,7 +27,6 @@ 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: 17 additions & 7 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;

export const describe = (blockName: BlockName, blockFn: BlockFn) =>
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.
export const beforeEach: THook = (fn, timeout) =>
const beforeEach: THook = (fn, timeout) =>
_addHook(fn, 'beforeEach', beforeEach, timeout);
export const beforeAll: THook = (fn, timeout) =>
const beforeAll: THook = (fn, timeout) =>
_addHook(fn, 'beforeAll', beforeAll, timeout);
export const afterEach: THook = (fn, timeout) =>
const afterEach: THook = (fn, timeout) =>
_addHook(fn, 'afterEach', afterEach, timeout);
export const afterAll: THook = (fn, timeout) =>
const afterAll: THook = (fn, timeout) =>
_addHook(fn, 'afterAll', afterAll, timeout);

export const test = (testName: TestName, fn: TestFn, timeout?: number) =>
const test = (testName: TestName, fn: TestFn, timeout?: number) =>
_addTest(testName, undefined, fn, test, timeout);
export const it = test;
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,3 +138,13 @@ 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';

export default async function jestAdapter(
const jestAdapter = async (
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 @@ export default async function jestAdapter(
testPath,
});
return _addSnapshotData(results, snapshotState);
}
};

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

module.exports = jestAdapter;
Loading