diff --git a/integration_tests/__tests__/haste-retain-all-ignore-paths-test.js b/integration_tests/__tests__/haste-retain-all-ignore-paths-test.js new file mode 100644 index 000000000000..d12724af0e27 --- /dev/null +++ b/integration_tests/__tests__/haste-retain-all-ignore-paths-test.js @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +'use strict'; + +const runJest = require('../runJest'); +const skipOnWindows = require('skipOnWindows'); + +skipOnWindows.suite(); + +it('does not run tests in node_modules/', () => { + const result = runJest.json('haste-retain-all-ignore-paths').json; + + const testNames = result.testResults.map(res => res.name).sort(); + + expect( + testNames.some(x => x.includes('library/__tests__/shouldnt-run.js')), + ).toBe(false); +}); + +it('runs tests in src/node_modules/', () => { + const result = runJest.json('haste-retain-all-ignore-paths').json; + + const testNames = result.testResults.map(res => res.name).sort(); + + expect( + testNames.some(x => x.includes('src-library/__tests__/should-run.js')), + ).toBe(true); +}); diff --git a/integration_tests/haste-retain-all-ignore-paths/example/src/node_modules/src-library/__tests__/should-run.js b/integration_tests/haste-retain-all-ignore-paths/example/src/node_modules/src-library/__tests__/should-run.js new file mode 100644 index 000000000000..24906857a9ec --- /dev/null +++ b/integration_tests/haste-retain-all-ignore-paths/example/src/node_modules/src-library/__tests__/should-run.js @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +'use strict'; + +// This test should run +test('stub', () => expect(1).toBe(1)); \ No newline at end of file diff --git a/integration_tests/haste-retain-all-ignore-paths/node_modules/library/__tests__/shouldnt-run.js b/integration_tests/haste-retain-all-ignore-paths/node_modules/library/__tests__/shouldnt-run.js new file mode 100644 index 000000000000..4afd8655d408 --- /dev/null +++ b/integration_tests/haste-retain-all-ignore-paths/node_modules/library/__tests__/shouldnt-run.js @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +'use strict'; + +// This test shouldn't run +test('stub', () => expect(1).toBe(2)); \ No newline at end of file diff --git a/integration_tests/haste-retain-all-ignore-paths/package.json b/integration_tests/haste-retain-all-ignore-paths/package.json new file mode 100644 index 000000000000..75b1d8144378 --- /dev/null +++ b/integration_tests/haste-retain-all-ignore-paths/package.json @@ -0,0 +1,11 @@ +{ + "jest": { + "haste": { + "retainAllFiles": true + }, + "testEnvironment": "node", + "testPathIgnorePatterns": [ + "/node_modules/" + ] + } +} diff --git a/packages/jest-runtime/src/__tests__/Runtime-static-createHasteMap-test.js b/packages/jest-runtime/src/__tests__/Runtime-static-createHasteMap-test.js new file mode 100644 index 000000000000..1264fba1ff18 --- /dev/null +++ b/packages/jest-runtime/src/__tests__/Runtime-static-createHasteMap-test.js @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +'use strict'; + +jest.mock('jest-haste-map', () => { + return class HeatMapMock { + constructor(options) { + this.options = options; + } + }; +}); + +const Runtime = require('../'); + +const defaultHasteConfig = { + providesModuleNodeModules: [], +}; + +const defaultConfig = { + cacheDirectory: '', + haste: defaultHasteConfig, + mocksPattern: '', + moduleFileExtensions: [], + modulePathIgnorePatterns: [], + name: '', + testPathDirs: [], + watchman: false, +}; + +const defaultOptions = { + maxWorkers: 0, + resetCache: false, +}; + +describe('Runtime', () => { + describe('createHasteMap', () => { + it('retainAllFiles from haste config if provided', () => { + const haste = Object.assign({}, defaultHasteConfig, { + retainAllFiles: true, + }); + + const config = Object.assign({}, defaultConfig, { + haste, + }); + + const hasteMap = Runtime.createHasteMap(config, defaultOptions); + + expect(hasteMap.options.retainAllFiles).toBe(true); + }); + + it('retainAllFiles false if not provided', () => { + const hasteMap = Runtime.createHasteMap(defaultConfig, defaultOptions); + + expect(hasteMap.options.retainAllFiles).toBe(false); + }); + }); +}); diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index 490ce6981c98..ad323e9c9c9d 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -213,7 +213,7 @@ class Runtime { platforms: config.haste.platforms || ['ios', 'android'], providesModuleNodeModules: config.haste.providesModuleNodeModules, resetCache: options && options.resetCache, - retainAllFiles: false, + retainAllFiles: config.haste.retainAllFiles || false, roots: config.roots, useWatchman: config.watchman, watch: options && options.watch, diff --git a/types/Config.js b/types/Config.js index 163a08667164..66140a15419c 100644 --- a/types/Config.js +++ b/types/Config.js @@ -17,6 +17,7 @@ export type HasteConfig = {| hasteImplModulePath?: string, platforms?: Array, providesModuleNodeModules: Array, + retainAllFiles?: boolean, |}; export type ConfigGlobals = Object;