Skip to content

Commit 5c45921

Browse files
committed
Fixed some integration tests
1 parent e7b32f6 commit 5c45921

File tree

8 files changed

+75
-23
lines changed

8 files changed

+75
-23
lines changed

integration-tests/__tests__/multi_project_runner.test.js

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ const DIR = path.resolve(os.tmpdir(), 'multi_project_runner_test');
2020

2121
SkipOnWindows.suite();
2222

23-
const fileContentWithProvidesModule = name => `/*
24-
* @providesModule ${name}
25-
*/
26-
27-
module.exports = {};
28-
`;
23+
const SAMPLE_FILE_CONTENT = 'module.exports = {};';
2924

3025
beforeEach(() => cleanup(DIR));
3126
afterEach(() => cleanup(DIR));
@@ -58,29 +53,51 @@ test('--listTests doesnt duplicate the test files', () => {
5853
test('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

packages/jest-cli/src/__tests__/search_source.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ jest.setTimeout(15000);
1414

1515
const SkipOnWindows = require('../../../../scripts/SkipOnWindows');
1616

17+
const hasteImplModulePath = path.join(
18+
__dirname,
19+
'..',
20+
'..',
21+
'..',
22+
'jest-haste-map',
23+
'src',
24+
'__tests__',
25+
'haste_impl',
26+
);
1727
const rootDir = path.resolve(__dirname, 'test_root');
1828
const testRegex = path.sep + '__testtests__' + path.sep;
1929
const testMatch = ['**/__testtests__/**/*'];
@@ -377,6 +387,9 @@ describe('SearchSource', () => {
377387
{
378388
name: 'SearchSource-findRelatedTests-tests',
379389
rootDir,
390+
haste: {
391+
hasteImplModulePath,
392+
},
380393
},
381394
{},
382395
);

packages/jest-haste-map/src/__tests__/haste_impl.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@
88

99
module.exports = {
1010
getHasteName(path) {
11-
if (path.includes('__mocks__') || path.includes('NoHaste')) {
11+
if (
12+
path.includes('__mocks__') ||
13+
path.includes('NoHaste') ||
14+
path.includes('/module_dir/') ||
15+
path.includes('/sourcemaps/')
16+
) {
1217
return undefined;
1318
}
1419

1520
return path
1621
.substr(path.lastIndexOf('/') + 1)
17-
.replace(/(\.(android|ios))?\.js$/, '');
22+
.replace(/(\.(android|ios|native))?\.js$/, '');
1823
},
1924
};

packages/jest-runtime/src/__mocks__/createRuntime.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ module.exports = function createRuntime(filename, config) {
1818
{
1919
name: 'Runtime-' + filename.replace(/\W/, '-') + '.tests',
2020
rootDir: path.resolve(path.dirname(filename), 'test_root'),
21+
haste: {
22+
hasteImplModulePath: path.resolve(
23+
__dirname,
24+
'..',
25+
'..',
26+
'..',
27+
'jest-haste-map',
28+
'src',
29+
'__tests__',
30+
'haste_impl.js',
31+
),
32+
},
2133
},
2234
config,
2335
),

0 commit comments

Comments
 (0)