From 20f7633d5346752cb8dd75c60b231fad4b59c391 Mon Sep 17 00:00:00 2001 From: Christoph Pojer Date: Tue, 23 May 2017 16:11:47 -0700 Subject: [PATCH] Fix DependencyGraph-test in OS. Reviewed By: davidaurelio Differential Revision: D5113955 fbshipit-source-id: 892331815393ca314e84112551f516a20126068f --- .../__tests__/DependencyGraph-test.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js b/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js index 3ac36cf5..d8a6d139 100644 --- a/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js +++ b/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js @@ -22,11 +22,15 @@ jest // 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 // for babel-plugin-jest-hoist. -const mockExtractDependencies = require('../../JSTransformer/worker/extract-dependencies'); -jest.mock( - '../../JSTransformer/worker/extract-dependencies', - () => mockExtractDependencies, -); +let mockExtractDependencies; +jest.mock('../../JSTransformer/worker/extract-dependencies', () => { + if (!mockExtractDependencies) { + mockExtractDependencies = require.requireActual( + '../../JSTransformer/worker/extract-dependencies', + ); + } + return mockExtractDependencies; +}); jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; @@ -98,6 +102,11 @@ describe('DependencyGraph', function() { return new Promise(resolve => { let deps = {dependencies: [], dependencyOffsets: []}; if (!module.path.endsWith('.json')) { + if (!mockExtractDependencies) { + mockExtractDependencies = require.requireActual( + '../../JSTransformer/worker/extract-dependencies', + ); + } deps = mockExtractDependencies(sourceCode); } resolve({...deps, code: sourceCode});