@@ -20,12 +20,7 @@ const DIR = path.resolve(os.tmpdir(), 'multi_project_runner_test');
2020
2121SkipOnWindows . suite ( ) ;
2222
23- const fileContentWithProvidesModule = name => `/*
24- * @providesModule ${ name }
25- */
26-
27- module.exports = {};
28- ` ;
23+ const SAMPLE_FILE_CONTENT = 'module.exports = {};' ;
2924
3025beforeEach ( ( ) => cleanup ( DIR ) ) ;
3126afterEach ( ( ) => cleanup ( DIR ) ) ;
@@ -58,29 +53,51 @@ test('--listTests doesnt duplicate the test files', () => {
5853test ( 'can pass projects or global config' , ( ) => {
5954 writeFiles ( DIR , {
6055 '.watchmanconfig' : '' ,
56+ 'base_config.js' : `
57+ module.exports = {
58+ haste: {
59+ hasteImplModulePath: '<rootDir>/hasteImpl.js',
60+ },
61+ };
62+ ` ,
63+ 'hasteImpl.js' : `
64+ module.exports = {
65+ getHasteName(path) {
66+ return path
67+ .substr(path.lastIndexOf('/') + 1)
68+ .replace(/\.js$/, '');
69+ },
70+ };
71+ ` ,
6172 'package.json' : '{}' ,
6273 'project1/__tests__/file1.test.js' : `
6374 const file1 = require('file1');
6475 test('file1', () => {});
6576 ` ,
66- 'project1/file1.js' : fileContentWithProvidesModule ( 'file1' ) ,
67- 'project1/jest.config.js' : `module.exports = {rootDir: './', displayName: 'BACKEND'}` ,
77+ 'project1/file1.js' : SAMPLE_FILE_CONTENT ,
78+ 'project1/jest.config.js' : `module.exports = {rootDir: './', displayName: 'BACKEND', haste: {
79+ hasteImplModulePath: '<rootDir>/../hasteImpl.js',
80+ },}` ,
6881 'project2/__tests__/file1.test.js' : `
6982 const file1 = require('file1');
7083 test('file1', () => {});
7184 ` ,
72- 'project2/file1.js' : fileContentWithProvidesModule ( 'file1' ) ,
73- 'project2/jest.config.js' : `module.exports = {rootDir: './'}` ,
85+ 'project2/file1.js' : SAMPLE_FILE_CONTENT ,
86+ 'project2/jest.config.js' : `module.exports = {rootDir: './', haste: {
87+ hasteImplModulePath: '<rootDir>/../hasteImpl.js',
88+ },}` ,
7489 'project3/__tests__/file1.test.js' : `
7590 const file1 = require('file1');
7691 test('file1', () => {});
7792 ` ,
78- 'project3/file1.js' : fileContentWithProvidesModule ( 'file1' ) ,
79- 'project3/jest.config.js' : `module.exports = {rootDir: './', displayName: 'UI'}` ,
93+ 'project3/file1.js' : SAMPLE_FILE_CONTENT ,
94+ 'project3/jest.config.js' : `module.exports = {rootDir: './', displayName: 'UI', haste: {
95+ hasteImplModulePath: '<rootDir>/../hasteImpl.js',
96+ },}` ,
8097 } ) ;
8198 let stderr ;
8299
83- ( { stderr} = runJest ( DIR , [ '--no-watchman' ] ) ) ;
100+ ( { stderr} = runJest ( DIR , [ '--no-watchman' , '--config' , 'base_config.js' ] ) ) ;
84101 expect ( stderr ) . toMatch (
85102 'The name `file1` was looked up in the Haste module map. It cannot be resolved, because there exists several different files' ,
86103 ) ;
@@ -91,6 +108,9 @@ test('can pass projects or global config', () => {
91108 'global_config.js' : `
92109 module.exports = {
93110 projects: ['project1/', 'project2/', 'project3/'],
111+ haste: {
112+ hasteImplModulePath: '<rootDir>/hasteImpl.js',
113+ },
94114 };
95115 ` ,
96116 } ) ;
@@ -102,6 +122,8 @@ test('can pass projects or global config', () => {
102122 'project1' ,
103123 'project2' ,
104124 'project3' ,
125+ '--config' ,
126+ 'base_config.js' ,
105127 ] ) ) ;
106128
107129 const result1 = extractSummary ( stderr ) ;
@@ -129,16 +151,16 @@ test('"No tests found" message for projects', () => {
129151 '.watchmanconfig' : '' ,
130152 'package.json' : '{}' ,
131153 'project1/__tests__/file1.test.js' : `
132- const file1 = require('file1');
154+ const file1 = require('../ file1');
133155 test('file1', () => {});
134156 ` ,
135- 'project1/file1.js' : fileContentWithProvidesModule ( 'file1' ) ,
157+ 'project1/file1.js' : SAMPLE_FILE_CONTENT ,
136158 'project1/jest.config.js' : `module.exports = {rootDir: './'}` ,
137159 'project2/__tests__/file1.test.js' : `
138- const file1 = require('file1');
160+ const file1 = require('../ file1');
139161 test('file1', () => {});
140162 ` ,
141- 'project2/file1.js' : fileContentWithProvidesModule ( 'file1' ) ,
163+ 'project2/file1.js' : SAMPLE_FILE_CONTENT ,
142164 'project2/jest.config.js' : `module.exports = {rootDir: './'}` ,
143165 } ) ;
144166 const { stdout : verboseOutput } = runJest ( DIR , [
@@ -173,16 +195,16 @@ test('projects can be workspaces with non-JS/JSON files', () => {
173195 'packages/README.md' : '# Packages README' ,
174196 'packages/project1/README.md' : '# Project1 README' ,
175197 'packages/project1/__tests__/file1.test.js' : `
176- const file1 = require('file1');
198+ const file1 = require('../ file1');
177199 test('file1', () => {});
178200 ` ,
179- 'packages/project1/file1.js' : fileContentWithProvidesModule ( 'file1' ) ,
201+ 'packages/project1/file1.js' : SAMPLE_FILE_CONTENT ,
180202 'packages/project1/package.json' : '{}' ,
181203 'packages/project2/__tests__/file2.test.js' : `
182- const file2 = require('file2');
204+ const file2 = require('../ file2');
183205 test('file2', () => {});
184206 ` ,
185- 'packages/project2/file2.js' : fileContentWithProvidesModule ( 'file2' ) ,
207+ 'packages/project2/file2.js' : SAMPLE_FILE_CONTENT ,
186208 'packages/project2/package.json' : '{}' ,
187209 } ) ;
188210
0 commit comments