diff --git a/integration-tests/__tests__/multi_project_runner.test.js b/integration-tests/__tests__/multi_project_runner.test.js index ecd1123667c7..7d5c7440f8a4 100644 --- a/integration-tests/__tests__/multi_project_runner.test.js +++ b/integration-tests/__tests__/multi_project_runner.test.js @@ -20,12 +20,7 @@ const DIR = path.resolve(os.tmpdir(), 'multi_project_runner_test'); SkipOnWindows.suite(); -const fileContentWithProvidesModule = name => `/* - * @providesModule ${name} - */ - -module.exports = {}; -`; +const SAMPLE_FILE_CONTENT = 'module.exports = {};'; beforeEach(() => cleanup(DIR)); afterEach(() => cleanup(DIR)); @@ -58,29 +53,51 @@ test('--listTests doesnt duplicate the test files', () => { test('can pass projects or global config', () => { writeFiles(DIR, { '.watchmanconfig': '', + 'base_config.js': ` + module.exports = { + haste: { + hasteImplModulePath: '/hasteImpl.js', + }, + }; + `, + 'hasteImpl.js': ` + module.exports = { + getHasteName(path) { + return path + .substr(path.lastIndexOf('/') + 1) + .replace(/\.js$/, ''); + }, + }; + `, 'package.json': '{}', 'project1/__tests__/file1.test.js': ` const file1 = require('file1'); test('file1', () => {}); `, - 'project1/file1.js': fileContentWithProvidesModule('file1'), - 'project1/jest.config.js': `module.exports = {rootDir: './', displayName: 'BACKEND'}`, + 'project1/file1.js': SAMPLE_FILE_CONTENT, + 'project1/jest.config.js': `module.exports = {rootDir: './', displayName: 'BACKEND', haste: { + hasteImplModulePath: '/../hasteImpl.js', + },}`, 'project2/__tests__/file1.test.js': ` const file1 = require('file1'); test('file1', () => {}); `, - 'project2/file1.js': fileContentWithProvidesModule('file1'), - 'project2/jest.config.js': `module.exports = {rootDir: './'}`, + 'project2/file1.js': SAMPLE_FILE_CONTENT, + 'project2/jest.config.js': `module.exports = {rootDir: './', haste: { + hasteImplModulePath: '/../hasteImpl.js', + },}`, 'project3/__tests__/file1.test.js': ` const file1 = require('file1'); test('file1', () => {}); `, - 'project3/file1.js': fileContentWithProvidesModule('file1'), - 'project3/jest.config.js': `module.exports = {rootDir: './', displayName: 'UI'}`, + 'project3/file1.js': SAMPLE_FILE_CONTENT, + 'project3/jest.config.js': `module.exports = {rootDir: './', displayName: 'UI', haste: { + hasteImplModulePath: '/../hasteImpl.js', + },}`, }); let stderr; - ({stderr} = runJest(DIR, ['--no-watchman'])); + ({stderr} = runJest(DIR, ['--no-watchman', '--config', 'base_config.js'])); expect(stderr).toMatch( 'The name `file1` was looked up in the Haste module map. It cannot be resolved, because there exists several different files', ); @@ -91,6 +108,9 @@ test('can pass projects or global config', () => { 'global_config.js': ` module.exports = { projects: ['project1/', 'project2/', 'project3/'], + haste: { + hasteImplModulePath: '/hasteImpl.js', + }, }; `, }); @@ -102,6 +122,8 @@ test('can pass projects or global config', () => { 'project1', 'project2', 'project3', + '--config', + 'base_config.js', ])); const result1 = extractSummary(stderr); @@ -129,16 +151,16 @@ test('"No tests found" message for projects', () => { '.watchmanconfig': '', 'package.json': '{}', 'project1/__tests__/file1.test.js': ` - const file1 = require('file1'); + const file1 = require('../file1'); test('file1', () => {}); `, - 'project1/file1.js': fileContentWithProvidesModule('file1'), + 'project1/file1.js': SAMPLE_FILE_CONTENT, 'project1/jest.config.js': `module.exports = {rootDir: './'}`, 'project2/__tests__/file1.test.js': ` - const file1 = require('file1'); + const file1 = require('../file1'); test('file1', () => {}); `, - 'project2/file1.js': fileContentWithProvidesModule('file1'), + 'project2/file1.js': SAMPLE_FILE_CONTENT, 'project2/jest.config.js': `module.exports = {rootDir: './'}`, }); const {stdout: verboseOutput} = runJest(DIR, [ @@ -173,16 +195,16 @@ test('projects can be workspaces with non-JS/JSON files', () => { 'packages/README.md': '# Packages README', 'packages/project1/README.md': '# Project1 README', 'packages/project1/__tests__/file1.test.js': ` - const file1 = require('file1'); + const file1 = require('../file1'); test('file1', () => {}); `, - 'packages/project1/file1.js': fileContentWithProvidesModule('file1'), + 'packages/project1/file1.js': SAMPLE_FILE_CONTENT, 'packages/project1/package.json': '{}', 'packages/project2/__tests__/file2.test.js': ` - const file2 = require('file2'); + const file2 = require('../file2'); test('file2', () => {}); `, - 'packages/project2/file2.js': fileContentWithProvidesModule('file2'), + 'packages/project2/file2.js': SAMPLE_FILE_CONTENT, 'packages/project2/package.json': '{}', }); diff --git a/packages/jest-cli/src/__tests__/search_source.test.js b/packages/jest-cli/src/__tests__/search_source.test.js index cbb79b89cc79..291891fd8e36 100644 --- a/packages/jest-cli/src/__tests__/search_source.test.js +++ b/packages/jest-cli/src/__tests__/search_source.test.js @@ -14,6 +14,16 @@ jest.setTimeout(15000); const SkipOnWindows = require('../../../../scripts/SkipOnWindows'); +const hasteImplModulePath = path.join( + __dirname, + '..', + '..', + '..', + 'jest-haste-map', + 'src', + '__tests__', + 'haste_impl', +); const rootDir = path.resolve(__dirname, 'test_root'); const testRegex = path.sep + '__testtests__' + path.sep; const testMatch = ['**/__testtests__/**/*']; @@ -377,6 +387,9 @@ describe('SearchSource', () => { { name: 'SearchSource-findRelatedTests-tests', rootDir, + haste: { + hasteImplModulePath, + }, }, {}, ); diff --git a/packages/jest-haste-map/src/__tests__/haste_impl.js b/packages/jest-haste-map/src/__tests__/haste_impl.js index 1405d95025b8..0dc26ac5fac6 100644 --- a/packages/jest-haste-map/src/__tests__/haste_impl.js +++ b/packages/jest-haste-map/src/__tests__/haste_impl.js @@ -8,12 +8,17 @@ module.exports = { getHasteName(path) { - if (path.includes('__mocks__') || path.includes('NoHaste')) { + if ( + path.includes('__mocks__') || + path.includes('NoHaste') || + path.includes('/module_dir/') || + path.includes('/sourcemaps/') + ) { return undefined; } return path .substr(path.lastIndexOf('/') + 1) - .replace(/(\.(android|ios))?\.js$/, ''); + .replace(/(\.(android|ios|native))?\.js$/, ''); }, }; diff --git a/packages/jest-runtime/src/__mocks__/createRuntime.js b/packages/jest-runtime/src/__mocks__/createRuntime.js index 8c56f2b38010..f573d578f697 100644 --- a/packages/jest-runtime/src/__mocks__/createRuntime.js +++ b/packages/jest-runtime/src/__mocks__/createRuntime.js @@ -18,6 +18,18 @@ module.exports = function createRuntime(filename, config) { { name: 'Runtime-' + filename.replace(/\W/, '-') + '.tests', rootDir: path.resolve(path.dirname(filename), 'test_root'), + haste: { + hasteImplModulePath: path.resolve( + __dirname, + '..', + '..', + '..', + 'jest-haste-map', + 'src', + '__tests__', + 'haste_impl.js', + ), + }, }, config, ), diff --git a/packages/jest-runtime/src/__tests__/test_root/platform/platform.android.js b/packages/jest-runtime/src/__tests__/test_root/platform/Platform.android.js similarity index 100% rename from packages/jest-runtime/src/__tests__/test_root/platform/platform.android.js rename to packages/jest-runtime/src/__tests__/test_root/platform/Platform.android.js diff --git a/packages/jest-runtime/src/__tests__/test_root/platform/platform.ios.js b/packages/jest-runtime/src/__tests__/test_root/platform/Platform.ios.js similarity index 100% rename from packages/jest-runtime/src/__tests__/test_root/platform/platform.ios.js rename to packages/jest-runtime/src/__tests__/test_root/platform/Platform.ios.js diff --git a/packages/jest-runtime/src/__tests__/test_root/platform/platform.js b/packages/jest-runtime/src/__tests__/test_root/platform/Platform.js similarity index 100% rename from packages/jest-runtime/src/__tests__/test_root/platform/platform.js rename to packages/jest-runtime/src/__tests__/test_root/platform/Platform.js diff --git a/packages/jest-runtime/src/__tests__/test_root/platform/platform.native.js b/packages/jest-runtime/src/__tests__/test_root/platform/Platform.native.js similarity index 100% rename from packages/jest-runtime/src/__tests__/test_root/platform/platform.native.js rename to packages/jest-runtime/src/__tests__/test_root/platform/Platform.native.js