Skip to content

Commit

Permalink
fix(runner): handle module loaders with default exports (#10541)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Sep 21, 2020
1 parent d955dc0 commit 6499deb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- `[jest-circus, jest-config, jest-runtime]` Add new `injectGlobals` config and CLI option to disable injecting global variables into the runtime ([#10484](https://github.com/facebook/jest/pull/10484))
- `[jest-each]` Fixes `.each` type to always be callable ([#10447](https://github.com/facebook/jest/pull/10447))
- `[jest-runner]` Add support for `moduleLoader`s with `default` exports ([#10541](https://github.com/facebook/jest/pull/10541))

### Fixes

Expand Down
16 changes: 10 additions & 6 deletions packages/jest-runner/src/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ async function runTestInternal(
const TestEnvironment: typeof JestEnvironment = interopRequireDefault(
require(testEnvironment),
).default;
const testFramework: TestFramework =
const testFramework: TestFramework = interopRequireDefault(
process.env.JEST_CIRCUS === '1'
? require('jest-circus/runner') // eslint-disable-line import/no-extraneous-dependencies
: require(config.testRunner);
const Runtime: typeof RuntimeClass = config.moduleLoader
? require(config.moduleLoader)
: require('jest-runtime');
? // eslint-disable-next-line import/no-extraneous-dependencies
require('jest-circus/runner')
: require(config.testRunner),
).default;
const Runtime: typeof RuntimeClass = interopRequireDefault(
config.moduleLoader
? require(config.moduleLoader)
: require('jest-runtime'),
).default;

const consoleOut = globalConfig.useStderr ? process.stderr : process.stdout;
const consoleFormatter = (type: LogType, message: LogMessage) =>
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-runtime/src/__mocks__/createRuntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import path from 'path';

module.exports = async function createRuntime(filename, config) {
const NodeEnvironment = require('jest-environment-node');
const Runtime = require('../');
const {default: NodeEnvironment} = await import('jest-environment-node');
const {default: Runtime} = await import('../');

const {normalize} = require('jest-config');
const {normalize} = await import('jest-config');

config = normalize(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import HasteMap from 'jest-haste-map';
const Runtime = require('../');
import Runtime from '../';

jest.mock('jest-haste-map');

Expand Down
6 changes: 2 additions & 4 deletions packages/jest-runtime/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {setGlobal, tryRealpath} from 'jest-util';
import {validateCLIOptions} from 'jest-validate';
import {deprecationEntries, readConfig} from 'jest-config';
import {VERSION} from '../version';
import type {Context} from '../types';
import * as args from './args';

export async function run(
Expand Down Expand Up @@ -67,11 +66,10 @@ export async function run(
automock: false,
};

// Break circular dependency
const Runtime: any = require('..');
const Runtime: typeof import('..') = require('..');

try {
const hasteMap: Context = await Runtime.createContext(config, {
const hasteMap = await Runtime.createContext(config, {
maxWorkers: Math.max(cpus().length - 1, 1),
watchman: globalConfig.watchman,
});
Expand Down

0 comments on commit 6499deb

Please sign in to comment.