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

Fix: jest-worker exposing .default babel interop #5811

Closed
Closed
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 .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"plugins": [
"syntax-trailing-function-commas",
"add-module-exports",
"transform-flow-strip-types",
"transform-es2015-destructuring",
"transform-es2015-parameters",
Expand Down
2 changes: 1 addition & 1 deletion docs/JestObjectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default {

```js
// __tests__/genMockFromModule.test.js
const utils = jest.genMockFromModule('../utils').default;
const utils = jest.genMockFromModule('../utils');
utils.isAuthorized = jest.fn(secret => secret === 'not wizard');

test('implementation created by jest.genMockFromModule', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('implementation created by automock', () => {
});

test('implementation created by jest.genMockFromModule', () => {
const utils = jest.genMockFromModule('../utils').default;
const utils = jest.genMockFromModule('../utils');
utils.isAuthorized = jest.fn(secret => secret === 'not wizard');

expect(utils.authorize.mock).toBeTruthy();
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"ansi-styles": "^3.2.0",
"babel-core": "^6.23.1",
"babel-eslint": "^7.2.3",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-syntax-trailing-function-commas": "^6.13.0",
"babel-plugin-transform-async-to-generator": "^6.16.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-circus/src/__mocks__/test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export const runTest = (source: string) => {
global.beforeAll = circus.beforeAll;
global.afterAll = circus.afterAll;

const testEventHandler = require('${TEST_EVENT_HANDLER_PATH}').default;
const testEventHandler = require('${TEST_EVENT_HANDLER_PATH}');
const addEventHandler = require('${CIRCUS_STATE_PATH}').addEventHandler;
addEventHandler(testEventHandler);

${source};

const run = require('${CIRCUS_RUN_PATH}').default;
const run = require('${CIRCUS_RUN_PATH}');

run();
`;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/src/__tests__/search_source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('SearchSource', () => {

beforeEach(() => {
Runtime = require('jest-runtime');
SearchSource = require('../search_source').default;
SearchSource = require('../search_source');
normalize = require('jest-config').normalize;
});

Expand Down
12 changes: 6 additions & 6 deletions packages/jest-cli/src/__tests__/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jest.doMock(
{virtual: true},
);

const watch = require('../watch').default;
const watch = require('../watch');

const nextTick = () => new Promise(res => process.nextTick(res));
const toHex = char => Number(char.charCodeAt(0)).toString(16);
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('Watch mode flows', () => {
const util = require('jest-util');
util.isInteractive = true;

const ci_watch = require('../watch').default;
const ci_watch = require('../watch');
ci_watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
expect(runJestMock.mock.calls[0][0]).toMatchObject({
contexts,
Expand All @@ -161,7 +161,7 @@ describe('Watch mode flows', () => {
const util = require('jest-util');
util.isInteractive = false;

const ci_watch = require('../watch').default;
const ci_watch = require('../watch');
ci_watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
expect(runJestMock.mock.calls[0][0]).toMatchObject({
contexts,
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('Watch mode flows', () => {
const util = require('jest-util');
util.isInteractive = true;

const ci_watch = require('../watch').default;
const ci_watch = require('../watch');
ci_watch(
Object.assign({}, globalConfig, {
rootDir: __dirname,
Expand All @@ -220,7 +220,7 @@ describe('Watch mode flows', () => {
util.isInteractive = true;
results = {snapshot: {failure: true}};

const ci_watch = require('../watch').default;
const ci_watch = require('../watch');
ci_watch(
Object.assign({}, globalConfig, {
rootDir: __dirname,
Expand Down Expand Up @@ -248,7 +248,7 @@ describe('Watch mode flows', () => {
util.getFailedSnapshotTests = jest.fn(() => ['test.js']);
results = {snapshot: {failure: true}};

const ci_watch = require('../watch').default;
const ci_watch = require('../watch');
ci_watch(
Object.assign({}, globalConfig, {
rootDir: __dirname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jest.doMock('../lib/terminal_utils', () => ({
getTerminalWidth: () => terminalWidth,
}));

const watch = require('../watch').default;
const watch = require('../watch');

const nextTick = () => new Promise(res => process.nextTick(res));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jest.doMock('../lib/terminal_utils', () => ({
getTerminalWidth: () => terminalWidth,
}));

const watch = require('../watch').default;
const watch = require('../watch');

const toHex = char => Number(char.charCodeAt(0)).toString(16);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ beforeEach(() => {
write: jest.fn(),
}));

CoverageReporter = require('../coverage_reporter').default;
CoverageReporter = require('../coverage_reporter');
libCoverage = require('istanbul-lib-coverage');
libSourceMaps = require('istanbul-lib-source-maps');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ beforeEach(() => {
jest.resetModules();

fs = require('fs');
generateEmptyCoverage = require('../../generate_empty_coverage').default;
generateEmptyCoverage = require('../../generate_empty_coverage');
worker = require('../coverage_worker').worker;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ beforeEach(() => {
process.stderr.write = jest.fn();
stdout = process.stdout.write = jest.fn();

DefaultReporter = require('../default_reporter').default;
DefaultReporter = require('../default_reporter');
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const wrap = obj => ({suites: obj, tests: [], title: ''});
let groupTestsBySuites;

beforeEach(() => {
const VerboseReporter = require('../verbose_reporter').default;
const VerboseReporter = require('../verbose_reporter');
groupTestsBySuites = VerboseReporter.groupTestsBySuites;
});

Expand Down
6 changes: 3 additions & 3 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ describe('testPathPattern', () => {

it('preserves any use of "\\"', () => {
const argv = {[opt.property]: ['a\\b', 'c\\\\d']};
const {options} = require('../normalize').default(
const {options} = require('../normalize')(
initialOptions,
argv,
);
Expand All @@ -1166,7 +1166,7 @@ describe('testPathPattern', () => {

it('replaces POSIX path separators', () => {
const argv = {[opt.property]: ['a/b']};
const {options} = require('../normalize').default(
const {options} = require('../normalize')(
initialOptions,
argv,
);
Expand All @@ -1176,7 +1176,7 @@ describe('testPathPattern', () => {

it('replaces POSIX paths in multiple args', () => {
const argv = {[opt.property]: ['a/b', 'c/d']};
const {options} = require('../normalize').default(
const {options} = require('../normalize')(
initialOptions,
argv,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-haste-map/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe('HasteMap', () => {
});

it('exports constants', () => {
expect(HasteMap.H).toBe(require('../constants').default);
expect(HasteMap.H).toBe(require('../constants'));
});

it('creates valid cache file paths', () => {
Expand Down Expand Up @@ -1057,7 +1057,7 @@ describe('HasteMap', () => {
} catch (error) {
const {
DuplicateHasteCandidatesError,
} = require('../module_map').default;
} = require('../module_map');
expect(error).toBeInstanceOf(DuplicateHasteCandidatesError);
expect(error.hasteName).toBe('Pear');
expect(error.platform).toBe('g');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
const path = require('path');

jest.mock('fb-watchman', () => {
const normalizePathSep = require('../../lib/normalize_path_sep').default;
const normalizePathSep = require('../../lib/normalize_path_sep');
const Client = jest.fn();
Client.prototype.command = jest.fn((args, callback) =>
setImmediate(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ describe('normalizePathSep', () => {
it('does nothing on posix', () => {
jest.resetModules();
jest.mock('path', () => require.requireActual('path').posix);
const normalizePathSep = require('../normalize_path_sep').default;
const normalizePathSep = require('../normalize_path_sep');
expect(normalizePathSep('foo/bar/baz.js')).toEqual('foo/bar/baz.js');
});

it('replace slashes on windows', () => {
jest.resetModules();
jest.mock('path', () => require.requireActual('path').win32);
const normalizePathSep = require('../normalize_path_sep').default;
const normalizePathSep = require('../normalize_path_sep');
expect(normalizePathSep('foo/bar/baz.js')).toEqual('foo\\bar\\baz.js');
});
});
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/jasmine/Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Spec.prototype.onException = function onException(error) {
}

if (error instanceof require('assert').AssertionError) {
const assertionErrorMessage = require('../assert_support').default;
const assertionErrorMessage = require('../assert_support');
error = assertionErrorMessage(error, {expand: this.expand});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-resolve/src/__tests__/resolve.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const path = require('path');
const ModuleMap = require('jest-haste-map').ModuleMap;
const Resolver = require('../');
const userResolver = require('../__mocks__/userResolver');
const nodeModulesPaths = require('../node_modules_paths').default;
const nodeModulesPaths = require('../node_modules_paths');

beforeEach(() => {
userResolver.mockClear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('ScriptTransformer', () => {
transformIgnorePatterns: ['/node_modules/'],
};

ScriptTransformer = require('../script_transformer').default;
ScriptTransformer = require('../script_transformer');
};

beforeEach(reset);
Expand Down Expand Up @@ -207,7 +207,7 @@ describe('ScriptTransformer', () => {
it('does not transform Node core modules', () => {
jest.mock('../should_instrument');

const shouldInstrument = require('../should_instrument').default;
const shouldInstrument = require('../should_instrument');
const scriptTransformer = new ScriptTransformer(config);
const fsSourceCode = process.binding('natives').fs;

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-util/src/__tests__/fake_timers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('FakeTimers', () => {
let FakeTimers, moduleMocker, timerConfig;

beforeEach(() => {
FakeTimers = require('../fake_timers').default;
FakeTimers = require('../fake_timers');
const mock = require('jest-mock');
const global = vm.runInNewContext('this');
moduleMocker = new mock.ModuleMocker(global);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ beforeEach(() => {
fake = jest.fn();
global.DTRACE_NET_SERVER_CONNECTION = fake;

installCommonGlobals = require('../install_common_globals').default;
installCommonGlobals = require('../install_common_globals');
});

it('returns the passed object', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-util/src/__tests__/is_interactive.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ it('Returns true when running on interactive environment', () => {
process.stdout.isTTY = true;
process.env.TERM = 'xterm-256color';

const isInteractive = require('../is_interative').default;
const isInteractive = require('../is_interative');
expect(isInteractive).toBe(true);
});

Expand All @@ -29,30 +29,30 @@ it('Returns false when running on a non-interactive environment', () => {
jest.doMock('is-ci', () => true);
process.stdout.isTTY = false;
process.env.TERM = 'xterm-256color';
isInteractive = require('../is_interative').default;
isInteractive = require('../is_interative');
expect(isInteractive).toBe(expectedResult);

// Test with is-ci being false and isTTY false
jest.resetModules();
jest.doMock('is-ci', () => false);
process.stdout.isTTY = false;
process.env.TERM = 'xterm-256color';
isInteractive = require('../is_interative').default;
isInteractive = require('../is_interative');
expect(isInteractive).toBe(expectedResult);

// Test with is-ci being true and isTTY true
jest.resetModules();
jest.doMock('is-ci', () => true);
process.stdout.isTTY = true;
process.env.TERM = 'xterm-256color';
isInteractive = require('../is_interative').default;
isInteractive = require('../is_interative');
expect(isInteractive).toBe(expectedResult);

// Test with dumb terminal
jest.resetModules();
jest.doMock('is-ci', () => false);
process.stdout.isTTY = false;
process.env.TERM = 'dumb';
isInteractive = require('../is_interative').default;
isInteractive = require('../is_interative');
expect(isInteractive).toBe(expectedResult);
});
2 changes: 1 addition & 1 deletion packages/jest-worker/src/__performance_tests__/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const workerFarm = require('worker-farm');
const assert = require('assert');
const JestWorker = require('../../build').default;
const JestWorker = require('../../build');

// Typical tests: node --expose-gc test.js empty 100000
// node --expose-gc test.js loadTest 10000
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-worker/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ beforeEach(() => {
{virtual: true},
);

Worker = require('../worker').default;
Farm = require('../index').default;
Worker = require('../worker');
Farm = require('../index');
});

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-worker/src/__tests__/worker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ beforeEach(() => {
return forkInterface;
});

Worker = require('../worker').default;
Worker = require('../worker');
});

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion website/versioned_docs/version-22.4/JestObjectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export default {

```js
// __tests__/genMockFromModule.test.js
const utils = jest.genMockFromModule('../utils').default;
const utils = jest.genMockFromModule('../utils');
utils.isAuthorized = jest.fn(secret => secret === 'not wizard');

test('implementation created by jest.genMockFromModule', () => {
Expand Down