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 "Re-inject native Node modules" #5009

Merged
merged 9 commits into from
Dec 4, 2017
17 changes: 0 additions & 17 deletions integration_tests/__tests__/leak_detection.test.js

This file was deleted.

21 changes: 0 additions & 21 deletions integration_tests/__tests__/require_all_modules.test.js

This file was deleted.

5 changes: 0 additions & 5 deletions integration_tests/leak-detection/package.json

This file was deleted.

27 changes: 0 additions & 27 deletions integration_tests/leak-detection/test.js

This file was deleted.

5 changes: 0 additions & 5 deletions integration_tests/require-all-modules/package.json

This file was deleted.

18 changes: 0 additions & 18 deletions integration_tests/require-all-modules/test.js

This file was deleted.

9 changes: 0 additions & 9 deletions jest-inspect

This file was deleted.

4 changes: 0 additions & 4 deletions packages/jest-editor-support/src/__tests__/runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ const {readFileSync} = require('fs');
const fixtures = path.resolve(__dirname, '../../../../fixtures');
import ProjectWorkspace from '../project_workspace';

// Win32 requires to spawn a process to kill the first one, by using "taskkill".
// Mocking "child_process" avoids the async spawn.
jest.mock('child_process');

// Replace `readFile` with `readFileSync` so we don't get multiple threads
jest.doMock('fs', () => {
return {
Expand Down
20 changes: 3 additions & 17 deletions packages/jest-jasmine2/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,10 @@ const JASMINE = require.resolve('./jasmine/jasmine_light.js');
async function jasmine2(
globalConfig: GlobalConfig,
config: ProjectConfig,
environment: ?Environment,
environment: Environment,
runtime: Runtime,
testPath: string,
): Promise<TestResult> {
// The "environment" parameter is nullable just so that we can clean its
// reference after adding some variables to it; but you still need to pass
// it when calling "jasmine2".
if (!environment) {
throw new ReferenceError('Please pass a valid Jest Environment object');
}

const reporter = new JasmineReporter(
globalConfig,
config,
Expand Down Expand Up @@ -92,17 +85,12 @@ async function jasmine2(
if (config.resetMocks) {
runtime.resetAllMocks();

if (environment && config.timers === 'fake') {
if (config.timers === 'fake') {
environment.fakeTimers.useFakeTimers();
}
}
});

// Free references to environment to avoid leaks.
env.afterAll(() => {
environment = null;
});

env.addReporter(reporter);

runtime
Expand All @@ -126,9 +114,7 @@ async function jasmine2(

if (config.setupTestFramework && config.setupTestFramework.length) {
config.setupTestFramework.forEach(module => {
if (environment) {
require(module)(environment.global);
}
require(module)(environment.global);
});
}

Expand Down
6 changes: 0 additions & 6 deletions packages/jest-message-util/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ type StackTraceOptions = {
// filter for noisy stack trace lines
const JASMINE_IGNORE = /^\s+at(?:(?:.*?vendor\/|jasmine\-)|\s+jasmine\.buildExpectationResult)/;
const JEST_INTERNALS_IGNORE = /^\s+at.*?jest(-.*?)?(\/|\\)(build|node_modules|packages)(\/|\\)/;

const JEST_NODE_NATIVE_IGNORE = /^\s+at.*?jest-node-native-/;
const ANONYMOUS_FN_IGNORE = /^\s+at <anonymous>.*$/;
const ANONYMOUS_PROMISE_IGNORE = /^\s+at (new )?Promise \(<anonymous>\).*$/;
const ANONYMOUS_GENERATOR_IGNORE = /^\s+at Generator.next \(<anonymous>\).*$/;
Expand Down Expand Up @@ -140,10 +138,6 @@ const removeInternalStackEntries = (lines, options: StackTraceOptions) => {
return false;
}

if (JEST_NODE_NATIVE_IGNORE.test(line)) {
return false;
}

if (!STACK_PATH_REGEXP.test(line)) {
return true;
}
Expand Down
43 changes: 12 additions & 31 deletions packages/jest-runner/src/run_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ async function runTestInternal(
RuntimeClass,
>);

let environment = new TestEnvironment(config);

const environment = new TestEnvironment(config);
const leakDetector = config.detectLeaks
? new LeakDetector(environment)
: null;
Expand All @@ -99,24 +98,15 @@ async function runTestInternal(
testConsole = new BufferedConsole();
}

let cacheFS = {[path]: testSource};
const cacheFS = {[path]: testSource};
setGlobal(environment.global, 'console', testConsole);

const coverageOptions = {
const runtime = new Runtime(config, environment, resolver, cacheFS, {
collectCoverage: globalConfig.collectCoverage,
collectCoverageFrom: globalConfig.collectCoverageFrom,
collectCoverageOnlyFrom: globalConfig.collectCoverageOnlyFrom,
mapCoverage: globalConfig.mapCoverage,
};

let runtime = new Runtime(
config,
environment,
resolver,
cacheFS,
coverageOptions,
path,
);
});

const start = Date.now();
await environment.setup();
Expand All @@ -139,23 +129,19 @@ async function runTestInternal(
result.skipped = testCount === result.numPendingTests;
result.displayName = config.displayName;

if (globalConfig.logHeapUsage) {
if (global.gc) {
global.gc();
}
result.memoryUsage = process.memoryUsage().heapUsed;
}

// Delay the resolution to allow log messages to be output.
return new Promise(resolve => {
setImmediate(() => resolve({leakDetector, result}));
});
} finally {
if (environment.teardown) {
await environment.teardown();
}

if (runtime.reset) {
await runtime.reset();
}

// Free references to environment to avoid leaks.
cacheFS = null;
environment = null;
runtime = null;
await environment.teardown();
}
}

Expand All @@ -172,11 +158,6 @@ export default async function runTest(
resolver,
);

if (globalConfig.logHeapUsage) {
global.gc && global.gc();
result.memoryUsage = process.memoryUsage().heapUsed;
}

// Resolve leak detector, outside the "runTestInternal" closure.
result.leaks = leakDetector ? leakDetector.isLeaking() : false;

Expand Down
Loading