Skip to content

Commit

Permalink
Removed default support for @providesModule
Browse files Browse the repository at this point in the history
  • Loading branch information
rubennorte committed Oct 10, 2018
1 parent c4646b9 commit 8c902d4
Show file tree
Hide file tree
Showing 30 changed files with 393 additions and 434 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `[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)).
- `[jest-config]` [**BREAKING**] Set default `notifyMode` to `failure-change` ([#7024](https://github.com/facebook/jest/pull/7024))
- `[jest-snapshot]` Enable configurable snapshot paths ([#6143](https://github.com/facebook/jest/pull/6143))
- `[jest-haste-map]` [**BREAKING**] Remove default support for `@providesModule` ([#6104](https://github.com/facebook/jest/pull/6104))

### Fixes

Expand Down
3 changes: 1 addition & 2 deletions e2e/__tests__/dependency_clash.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ test('fails with syntax error on flow types', () => {
}
`,
'__tests__/test.js': `
const invariant = require('invariant');
const invariant = require('../invariant');
test('haii', () => expect(invariant(false, 'haii')).toBe('haii'));
`,
'invariant.js': `/**
* @providesModule invariant
* @flow
*/
const invariant = (condition: boolean, message: string) => message;
Expand Down
64 changes: 43 additions & 21 deletions e2e/__tests__/multi_project_runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import {cleanup, extractSummary, writeFiles} from '../Utils';

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

const fileContentWithProvidesModule = name => `/*
* @providesModule ${name}
*/
module.exports = {};
`;
const SAMPLE_FILE_CONTENT = 'module.exports = {};';

beforeEach(() => cleanup(DIR));
afterEach(() => cleanup(DIR));
Expand Down Expand Up @@ -55,29 +50,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: '<rootDir>/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: '<rootDir>/../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: '<rootDir>/../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: '<rootDir>/../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',
);
Expand All @@ -88,6 +105,9 @@ test('can pass projects or global config', () => {
'global_config.js': `
module.exports = {
projects: ['project1/', 'project2/', 'project3/'],
haste: {
hasteImplModulePath: '<rootDir>/hasteImpl.js',
},
};
`,
});
Expand All @@ -99,6 +119,8 @@ test('can pass projects or global config', () => {
'project1',
'project2',
'project3',
'--config',
'base_config.js',
]));

const result1 = extractSummary(stderr);
Expand Down Expand Up @@ -126,16 +148,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, [
Expand Down Expand Up @@ -170,16 +192,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': '{}',
});

Expand Down
12 changes: 12 additions & 0 deletions packages/jest-cli/src/__tests__/SearchSource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,18 @@ describe('SearchSource', () => {
beforeEach(done => {
const {options: config} = normalize(
{
haste: {
hasteImplModulePath: path.join(
__dirname,
'..',
'..',
'..',
'jest-haste-map',
'src',
'__tests__',
'haste_impl.js',
),
},
name: 'SearchSource-findRelatedTests-tests',
rootDir,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
exports[`HasteMap file system changes processing recovery from duplicate module IDs recovers when the most recent duplicate is fixed 1`] = `
"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:
* \`/project/fruits/blueberry.js\` (module)
* \`/project/fruits/pear.js\` (module)
* \`/project/fruits/Pear.js\` (module)
* \`/project/fruits/another/Pear.js\` (module)
"
`;

exports[`HasteMap file system changes processing recovery from duplicate module IDs recovers when the oldest version of the duplicates is fixed 1`] = `
"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:
* \`/project/fruits/blueberry.js\` (module)
* \`/project/fruits/pear.js\` (module)
* \`/project/fruits/Pear.js\` (module)
* \`/project/fruits/another/Pear.js\` (module)
"
`;

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

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

exports[`HasteMap warns on duplicate mock files 1`] = `
"jest-haste-map: duplicate manual mock found:
Module name: subdir/blueberry
Duplicate Mock path: /project/fruits2/__mocks__/subdir/blueberry.js
Module name: subdir/Blueberry
Duplicate Mock path: /project/fruits2/__mocks__/subdir/Blueberry.js
This warning is caused by two manual mock files with the same file name.
Jest will use the mock file found in:
/project/fruits2/__mocks__/subdir/blueberry.js
/project/fruits2/__mocks__/subdir/Blueberry.js
Please delete one of the following two files:
/project/fruits1/__mocks__/subdir/blueberry.js
/project/fruits2/__mocks__/subdir/blueberry.js
/project/fruits1/__mocks__/subdir/Blueberry.js
/project/fruits2/__mocks__/subdir/Blueberry.js
"
`;

exports[`HasteMap warns on duplicate module ids 1`] = `
"jest-haste-map: @providesModule naming collision:
"jest-haste-map: Haste module naming collision:
Duplicate module name: Strawberry
Paths: /project/fruits/raspberry.js collides with /project/fruits/strawberry.js
Paths: /project/fruits/other/Strawberry.js collides with /project/fruits/Strawberry.js
This warning is caused by a @providesModule declaration with the same name across two different files."
This warning is caused by \`hasteImpl\` returning the same name for different files."
`;
13 changes: 12 additions & 1 deletion packages/jest-haste-map/src/__tests__/haste_impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@

module.exports = {
getHasteName(path) {
return path.substr(path.lastIndexOf('/') + 1).replace(/\.js$/, '');
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|native))?\.js$/, '');
},
};
Loading

0 comments on commit 8c902d4

Please sign in to comment.