From b2820315179cf44fd59f4f65a5e0fcb98dd29a15 Mon Sep 17 00:00:00 2001 From: Miguel Jimenez Esun Date: Tue, 28 Nov 2017 03:08:08 -0800 Subject: [PATCH] Make tests compatible with the latest Jest version Reviewed By: cpojer Differential Revision: D6419868 fbshipit-source-id: f01a3f4d54ca1aa3539d92363a51f70247642463 --- .../traverseDependencies-integration-test.js | 68 ++++++++++--------- .../src/node-haste/__tests__/Module-test.js | 6 +- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/packages/metro-bundler/src/DeltaBundler/__tests__/traverseDependencies-integration-test.js b/packages/metro-bundler/src/DeltaBundler/__tests__/traverseDependencies-integration-test.js index 95ca2ecd..438347a3 100644 --- a/packages/metro-bundler/src/DeltaBundler/__tests__/traverseDependencies-integration-test.js +++ b/packages/metro-bundler/src/DeltaBundler/__tests__/traverseDependencies-integration-test.js @@ -133,16 +133,19 @@ describe('traverseDependencies', function() { let DependencyGraph; let processDgraph; const consoleWarn = console.warn; - const realPlatform = process.platform; beforeEach(function() { - process.platform = 'linux'; + Object.defineProperty(process, 'platform', { + configurable: true, + enumerable: true, + value: 'linux', + }); + DependencyGraph = require('../../node-haste/DependencyGraph'); processDgraph = processDgraphFor.bind(null, DependencyGraph); }); afterEach(function() { console.warn = consoleWarn; - process.platform = realPlatform; }); it('should get dependencies', async () => { @@ -2403,11 +2406,14 @@ describe('traverseDependencies', function() { }); describe('get sync dependencies (win32)', () => { - const realPlatform = process.platform; let DependencyGraph; let processDgraph; beforeEach(function() { - process.platform = 'win32'; + Object.defineProperty(process, 'platform', { + configurable: true, + enumerable: true, + value: 'win32', + }); // reload path module jest.resetModules(); @@ -2416,10 +2422,6 @@ describe('traverseDependencies', function() { processDgraph = processDgraphFor.bind(null, DependencyGraph); }); - afterEach(function() { - process.platform = realPlatform; - }); - it('should get dependencies', async () => { const root = 'C:\\root'; setMockFileSystem({ @@ -2580,20 +2582,20 @@ describe('traverseDependencies', function() { }); describe('node_modules (posix)', function() { - const realPlatform = process.platform; let DependencyGraph; let processDgraph; beforeEach(function() { - process.platform = 'linux'; + Object.defineProperty(process, 'platform', { + configurable: true, + enumerable: true, + value: 'linux', + }); + DependencyGraph = require('../../node-haste/DependencyGraph'); processDgraph = processDgraphFor.bind(null, DependencyGraph); }); - afterEach(function() { - process.platform = realPlatform; - }); - it('should work with nested node_modules', async () => { var root = '/root'; setMockFileSystem({ @@ -3524,11 +3526,15 @@ describe('traverseDependencies', function() { }); describe('node_modules (win32)', function() { - const realPlatform = process.platform; let DependencyGraph; let processDgraph; beforeEach(() => { - process.platform = 'win32'; + Object.defineProperty(process, 'platform', { + configurable: true, + enumerable: true, + value: 'win32', + }); + // reload path module jest.resetModules(); jest.mock('path', () => require.requireActual('path').win32); @@ -3536,10 +3542,6 @@ describe('traverseDependencies', function() { processDgraph = processDgraphFor.bind(null, DependencyGraph); }); - afterEach(() => { - process.platform = realPlatform; - }); - it('should work with nested node_modules', async () => { var root = 'C:\\root'; setMockFileSystem({ @@ -4424,20 +4426,20 @@ describe('traverseDependencies', function() { }); describe('file watch updating', function() { - const realPlatform = process.platform; let DependencyGraph; let processDgraph; beforeEach(function() { - process.platform = 'linux'; + Object.defineProperty(process, 'platform', { + configurable: true, + enumerable: true, + value: 'linux', + }); + DependencyGraph = require('../../node-haste/DependencyGraph'); processDgraph = processDgraphFor.bind(null, DependencyGraph); }); - afterEach(function() { - process.platform = realPlatform; - }); - it('updates module dependencies', async () => { var root = '/root'; var filesystem = setMockFileSystem({ @@ -5092,20 +5094,20 @@ describe('traverseDependencies', function() { }); describe('Extensions', () => { - const realPlatform = process.platform; let DependencyGraph; let processDgraph; beforeEach(function() { - process.platform = 'linux'; + Object.defineProperty(process, 'platform', { + configurable: true, + enumerable: true, + value: 'linux', + }); + DependencyGraph = require('../../node-haste/DependencyGraph'); processDgraph = processDgraphFor.bind(null, DependencyGraph); }); - afterEach(function() { - process.platform = realPlatform; - }); - it('supports custom file extensions', async () => { var root = '/root'; setMockFileSystem({ diff --git a/packages/metro-bundler/src/node-haste/__tests__/Module-test.js b/packages/metro-bundler/src/node-haste/__tests__/Module-test.js index a31ffdff..38545b2b 100644 --- a/packages/metro-bundler/src/node-haste/__tests__/Module-test.js +++ b/packages/metro-bundler/src/node-haste/__tests__/Module-test.js @@ -76,7 +76,11 @@ describe('Module', () => { createModule({...options, file: '/root/package.json'}); beforeEach(function() { - process.platform = 'linux'; + Object.defineProperty(process, 'platform', { + configurable: true, + enumerable: true, + value: 'linux', + }); cache = createCache(); transformCacheKey = 'abcdef'; transformCache.mock.reset();