Fix DependencyGraph-test in OS.

Reviewed By: davidaurelio

Differential Revision: D5113955

fbshipit-source-id: 892331815393ca314e84112551f516a20126068f
This commit is contained in:
Christoph Pojer 2017-05-23 16:11:47 -07:00 committed by Facebook Github Bot
parent 06bb33eba0
commit 20f7633d53
1 changed files with 14 additions and 5 deletions

View File

@ -22,11 +22,15 @@ jest
// This doesn't have state, and it's huge (Babel) so it's much faster to // This doesn't have state, and it's huge (Babel) so it's much faster to
// require it only once. The variable name is prefixed with "mock" as an escape-hatch // require it only once. The variable name is prefixed with "mock" as an escape-hatch
// for babel-plugin-jest-hoist. // for babel-plugin-jest-hoist.
const mockExtractDependencies = require('../../JSTransformer/worker/extract-dependencies'); let mockExtractDependencies;
jest.mock( jest.mock('../../JSTransformer/worker/extract-dependencies', () => {
'../../JSTransformer/worker/extract-dependencies', if (!mockExtractDependencies) {
() => mockExtractDependencies, mockExtractDependencies = require.requireActual(
); '../../JSTransformer/worker/extract-dependencies',
);
}
return mockExtractDependencies;
});
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
@ -98,6 +102,11 @@ describe('DependencyGraph', function() {
return new Promise(resolve => { return new Promise(resolve => {
let deps = {dependencies: [], dependencyOffsets: []}; let deps = {dependencies: [], dependencyOffsets: []};
if (!module.path.endsWith('.json')) { if (!module.path.endsWith('.json')) {
if (!mockExtractDependencies) {
mockExtractDependencies = require.requireActual(
'../../JSTransformer/worker/extract-dependencies',
);
}
deps = mockExtractDependencies(sourceCode); deps = mockExtractDependencies(sourceCode);
} }
resolve({...deps, code: sourceCode}); resolve({...deps, code: sourceCode});