Skip to content

Commit 6631437

Browse files
committed
Removed default support for @providesModule
1 parent c4646b9 commit 6631437

30 files changed

+393
-434
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- `[jest-worker]` [**BREAKING**] Add functionality to call a `setup` method in the worker before the first call and a `teardown` method when ending the farm ([#7014](https://github.com/facebook/jest/pull/7014)).
99
- `[jest-config]` [**BREAKING**] Set default `notifyMode` to `failure-change` ([#7024](https://github.com/facebook/jest/pull/7024))
1010
- `[jest-snapshot]` Enable configurable snapshot paths ([#6143](https://github.com/facebook/jest/pull/6143))
11+
- `[jest-haste-map]` [**BREAKING**] Remove support for `@providesModule` ([#6104](https://github.com/facebook/jest/pull/6104))
1112

1213
### Fixes
1314

e2e/__tests__/dependency_clash.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ test('fails with syntax error on flow types', () => {
5959
}
6060
`,
6161
'__tests__/test.js': `
62-
const invariant = require('invariant');
62+
const invariant = require('../invariant');
6363
test('haii', () => expect(invariant(false, 'haii')).toBe('haii'));
6464
`,
6565
'invariant.js': `/**
66-
* @providesModule invariant
6766
* @flow
6867
*/
6968
const invariant = (condition: boolean, message: string) => message;

e2e/__tests__/multi_project_runner.test.js

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ import {cleanup, extractSummary, writeFiles} from '../Utils';
1717

1818
const DIR = path.resolve(os.tmpdir(), 'multi_project_runner_test');
1919

20-
const fileContentWithProvidesModule = name => `/*
21-
* @providesModule ${name}
22-
*/
23-
24-
module.exports = {};
25-
`;
20+
const SAMPLE_FILE_CONTENT = 'module.exports = {};';
2621

2722
beforeEach(() => cleanup(DIR));
2823
afterEach(() => cleanup(DIR));
@@ -55,29 +50,51 @@ test('--listTests doesnt duplicate the test files', () => {
5550
test('can pass projects or global config', () => {
5651
writeFiles(DIR, {
5752
'.watchmanconfig': '',
53+
'base_config.js': `
54+
module.exports = {
55+
haste: {
56+
hasteImplModulePath: '<rootDir>/hasteImpl.js',
57+
},
58+
};
59+
`,
60+
'hasteImpl.js': `
61+
module.exports = {
62+
getHasteName(path) {
63+
return path
64+
.substr(path.lastIndexOf('/') + 1)
65+
.replace(/\.js$/, '');
66+
},
67+
};
68+
`,
5869
'package.json': '{}',
5970
'project1/__tests__/file1.test.js': `
6071
const file1 = require('file1');
6172
test('file1', () => {});
6273
`,
63-
'project1/file1.js': fileContentWithProvidesModule('file1'),
64-
'project1/jest.config.js': `module.exports = {rootDir: './', displayName: 'BACKEND'}`,
74+
'project1/file1.js': SAMPLE_FILE_CONTENT,
75+
'project1/jest.config.js': `module.exports = {rootDir: './', displayName: 'BACKEND', haste: {
76+
hasteImplModulePath: '<rootDir>/../hasteImpl.js',
77+
},}`,
6578
'project2/__tests__/file1.test.js': `
6679
const file1 = require('file1');
6780
test('file1', () => {});
6881
`,
69-
'project2/file1.js': fileContentWithProvidesModule('file1'),
70-
'project2/jest.config.js': `module.exports = {rootDir: './'}`,
82+
'project2/file1.js': SAMPLE_FILE_CONTENT,
83+
'project2/jest.config.js': `module.exports = {rootDir: './', haste: {
84+
hasteImplModulePath: '<rootDir>/../hasteImpl.js',
85+
},}`,
7186
'project3/__tests__/file1.test.js': `
7287
const file1 = require('file1');
7388
test('file1', () => {});
7489
`,
75-
'project3/file1.js': fileContentWithProvidesModule('file1'),
76-
'project3/jest.config.js': `module.exports = {rootDir: './', displayName: 'UI'}`,
90+
'project3/file1.js': SAMPLE_FILE_CONTENT,
91+
'project3/jest.config.js': `module.exports = {rootDir: './', displayName: 'UI', haste: {
92+
hasteImplModulePath: '<rootDir>/../hasteImpl.js',
93+
},}`,
7794
});
7895
let stderr;
7996

80-
({stderr} = runJest(DIR, ['--no-watchman']));
97+
({stderr} = runJest(DIR, ['--no-watchman', '--config', 'base_config.js']));
8198
expect(stderr).toMatch(
8299
'The name `file1` was looked up in the Haste module map. It cannot be resolved, because there exists several different files',
83100
);
@@ -88,6 +105,9 @@ test('can pass projects or global config', () => {
88105
'global_config.js': `
89106
module.exports = {
90107
projects: ['project1/', 'project2/', 'project3/'],
108+
haste: {
109+
hasteImplModulePath: '<rootDir>/hasteImpl.js',
110+
},
91111
};
92112
`,
93113
});
@@ -99,6 +119,8 @@ test('can pass projects or global config', () => {
99119
'project1',
100120
'project2',
101121
'project3',
122+
'--config',
123+
'base_config.js',
102124
]));
103125

104126
const result1 = extractSummary(stderr);
@@ -126,16 +148,16 @@ test('"No tests found" message for projects', () => {
126148
'.watchmanconfig': '',
127149
'package.json': '{}',
128150
'project1/__tests__/file1.test.js': `
129-
const file1 = require('file1');
151+
const file1 = require('../file1');
130152
test('file1', () => {});
131153
`,
132-
'project1/file1.js': fileContentWithProvidesModule('file1'),
154+
'project1/file1.js': SAMPLE_FILE_CONTENT,
133155
'project1/jest.config.js': `module.exports = {rootDir: './'}`,
134156
'project2/__tests__/file1.test.js': `
135-
const file1 = require('file1');
157+
const file1 = require('../file1');
136158
test('file1', () => {});
137159
`,
138-
'project2/file1.js': fileContentWithProvidesModule('file1'),
160+
'project2/file1.js': SAMPLE_FILE_CONTENT,
139161
'project2/jest.config.js': `module.exports = {rootDir: './'}`,
140162
});
141163
const {stdout: verboseOutput} = runJest(DIR, [
@@ -170,16 +192,16 @@ test('projects can be workspaces with non-JS/JSON files', () => {
170192
'packages/README.md': '# Packages README',
171193
'packages/project1/README.md': '# Project1 README',
172194
'packages/project1/__tests__/file1.test.js': `
173-
const file1 = require('file1');
195+
const file1 = require('../file1');
174196
test('file1', () => {});
175197
`,
176-
'packages/project1/file1.js': fileContentWithProvidesModule('file1'),
198+
'packages/project1/file1.js': SAMPLE_FILE_CONTENT,
177199
'packages/project1/package.json': '{}',
178200
'packages/project2/__tests__/file2.test.js': `
179-
const file2 = require('file2');
201+
const file2 = require('../file2');
180202
test('file2', () => {});
181203
`,
182-
'packages/project2/file2.js': fileContentWithProvidesModule('file2'),
204+
'packages/project2/file2.js': SAMPLE_FILE_CONTENT,
183205
'packages/project2/package.json': '{}',
184206
});
185207

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,18 @@ describe('SearchSource', () => {
373373
beforeEach(done => {
374374
const {options: config} = normalize(
375375
{
376+
haste: {
377+
hasteImplModulePath: path.join(
378+
__dirname,
379+
'..',
380+
'..',
381+
'..',
382+
'jest-haste-map',
383+
'src',
384+
'__tests__',
385+
'haste_impl.js',
386+
),
387+
},
376388
name: 'SearchSource-findRelatedTests-tests',
377389
rootDir,
378390
},

packages/jest-haste-map/src/__tests__/__snapshots__/index.test.js.snap

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
exports[`HasteMap file system changes processing recovery from duplicate module IDs recovers when the most recent duplicate is fixed 1`] = `
44
"The name \`Pear\` was looked up in the Haste module map. It cannot be resolved, because there exists several different files, or packages, that provide a module for that particular name and platform. The platform is generic (no extension). You must delete or blacklist files until there remains only one of these:
55
6-
* \`/project/fruits/blueberry.js\` (module)
7-
* \`/project/fruits/pear.js\` (module)
6+
* \`/project/fruits/Pear.js\` (module)
7+
* \`/project/fruits/another/Pear.js\` (module)
88
"
99
`;
1010

1111
exports[`HasteMap file system changes processing recovery from duplicate module IDs recovers when the oldest version of the duplicates is fixed 1`] = `
1212
"The name \`Pear\` was looked up in the Haste module map. It cannot be resolved, because there exists several different files, or packages, that provide a module for that particular name and platform. The platform is generic (no extension). You must delete or blacklist files until there remains only one of these:
1313
14-
* \`/project/fruits/blueberry.js\` (module)
15-
* \`/project/fruits/pear.js\` (module)
14+
* \`/project/fruits/Pear.js\` (module)
15+
* \`/project/fruits/another/Pear.js\` (module)
1616
"
1717
`;
1818

1919
exports[`HasteMap throws on duplicate module ids if "throwOnModuleCollision" is set to true 1`] = `
20-
[Error: jest-haste-map: @providesModule naming collision:
20+
[Error: jest-haste-map: Haste module naming collision:
2121
Duplicate module name: Strawberry
22-
Paths: /project/fruits/raspberry.js collides with /project/fruits/strawberry.js
22+
Paths: /project/fruits/another/Strawberry.js collides with /project/fruits/Strawberry.js
2323
24-
This error is caused by a @providesModule declaration with the same name across two different files.]
24+
This error is caused by \`hasteImpl\` returning the same name for different files.]
2525
`;
2626

2727
exports[`HasteMap tries to crawl using node as a fallback 1`] = `
@@ -32,22 +32,22 @@ exports[`HasteMap tries to crawl using node as a fallback 1`] = `
3232

3333
exports[`HasteMap warns on duplicate mock files 1`] = `
3434
"jest-haste-map: duplicate manual mock found:
35-
Module name: subdir/blueberry
36-
Duplicate Mock path: /project/fruits2/__mocks__/subdir/blueberry.js
35+
Module name: subdir/Blueberry
36+
Duplicate Mock path: /project/fruits2/__mocks__/subdir/Blueberry.js
3737
This warning is caused by two manual mock files with the same file name.
3838
Jest will use the mock file found in:
39-
/project/fruits2/__mocks__/subdir/blueberry.js
39+
/project/fruits2/__mocks__/subdir/Blueberry.js
4040
Please delete one of the following two files:
41-
/project/fruits1/__mocks__/subdir/blueberry.js
42-
/project/fruits2/__mocks__/subdir/blueberry.js
41+
/project/fruits1/__mocks__/subdir/Blueberry.js
42+
/project/fruits2/__mocks__/subdir/Blueberry.js
4343
4444
"
4545
`;
4646

4747
exports[`HasteMap warns on duplicate module ids 1`] = `
48-
"jest-haste-map: @providesModule naming collision:
48+
"jest-haste-map: Haste module naming collision:
4949
Duplicate module name: Strawberry
50-
Paths: /project/fruits/raspberry.js collides with /project/fruits/strawberry.js
50+
Paths: /project/fruits/other/Strawberry.js collides with /project/fruits/Strawberry.js
5151
52-
This warning is caused by a @providesModule declaration with the same name across two different files."
52+
This warning is caused by \`hasteImpl\` returning the same name for different files."
5353
`;

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88

99
module.exports = {
1010
getHasteName(path) {
11-
return path.substr(path.lastIndexOf('/') + 1).replace(/\.js$/, '');
11+
if (
12+
path.includes('__mocks__') ||
13+
path.includes('NoHaste') ||
14+
path.includes('/module_dir/') ||
15+
path.includes('/sourcemaps/')
16+
) {
17+
return undefined;
18+
}
19+
20+
return path
21+
.substr(path.lastIndexOf('/') + 1)
22+
.replace(/(\.(android|ios|native))?\.js$/, '');
1223
},
1324
};

0 commit comments

Comments
 (0)