Skip to content

Commit

Permalink
Remove support for @providesModule (#6104)
Browse files Browse the repository at this point in the history
* Removed default support for @providesModule
* Upgrade react-native to support windows and hasteImpl
  • Loading branch information
rubennorte committed Oct 10, 2018
1 parent b4d9ed8 commit a1b82ca
Show file tree
Hide file tree
Showing 35 changed files with 1,030 additions and 2,915 deletions.
5 changes: 3 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ jobs:
steps:
- checkout
- restore-cache: *restore-cache
- run: yarn --no-progress
- run: yarn --no-progress --ignore-engines
- save-cache: *save-cache
- run:
command: yarn test-ci-partial
# react-native does not work with node 6
command: rm -rf examples/react-native && yarn test-ci-partial
- store_test_results:
path: reports/junit

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- `[jest-config]` [**BREAKING**] Set default `notifyMode` to `failure-change` ([#7024](https://github.com/facebook/jest/pull/7024))
- `[jest-config]` Add `readConfigs` function, previously in `jest-cli` ([#7096](https://github.com/facebook/jest/pull/7096))
- `[jest-snapshot]` Enable configurable snapshot paths ([#6143](https://github.com/facebook/jest/pull/6143))
- `[jest-haste-map]` [**BREAKING**] Remove 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
65 changes: 44 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,52 @@ 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': `
const path = require('path');
module.exports = {
getHasteName(filename) {
return filename
.substr(filename.lastIndexOf(path.sep) + 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 +106,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 +120,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 +149,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 +193,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
25 changes: 4 additions & 21 deletions examples/react-native/__tests__/__snapshots__/intro.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ exports[`renders correctly 1`] = `
}
>
<Text
accessible={true}
allowFontScaling={true}
ellipsizeMode="tail"
style={
Object {
"fontSize": 20,
Expand All @@ -26,9 +23,6 @@ exports[`renders correctly 1`] = `
Welcome to React Native!
</Text>
<Text
accessible={true}
allowFontScaling={true}
ellipsizeMode="tail"
style={
Object {
"color": "#333333",
Expand Down Expand Up @@ -73,25 +67,13 @@ exports[`renders the ListView component 1`] = `
renderScrollComponent={[Function]}
>
<View>
<Text
accessible={true}
allowFontScaling={true}
ellipsizeMode="tail"
>
<Text>
apple
</Text>
<Text
accessible={true}
allowFontScaling={true}
ellipsizeMode="tail"
>
<Text>
banana
</Text>
<Text
accessible={true}
allowFontScaling={true}
ellipsizeMode="tail"
>
<Text>
kiwi
</Text>
</View>
Expand All @@ -102,6 +84,7 @@ exports[`renders the TextInput component 1`] = `
<TextInput
allowFontScaling={true}
autoCorrect={false}
underlineColorAndroid="transparent"
value="apple banana kiwi"
/>
`;
2 changes: 2 additions & 0 deletions examples/react-native/__tests__/intro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Intro from '../Intro';
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';

jest.setTimeout(15000);

it('renders correctly', () => {
const tree = renderer.create(<Intro />).toJSON();
expect(tree).toMatchSnapshot();
Expand Down
4 changes: 2 additions & 2 deletions examples/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"test": "jest"
},
"dependencies": {
"react": "16.0.0",
"react-native": "^0.51.0"
"react": "16.5.0",
"react-native": "0.57.2"
},
"devDependencies": {
"babel-jest": "*",
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."
`;
17 changes: 15 additions & 2 deletions packages/jest-haste-map/src/__tests__/haste_impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@
*/
'use strict';

const path = require('path');

module.exports = {
getHasteName(path) {
return path.substr(path.lastIndexOf('/') + 1).replace(/\.js$/, '');
getHasteName(filename) {
if (
filename.includes('__mocks__') ||
filename.includes('NoHaste') ||
filename.includes(path.sep + 'module_dir' + path.sep) ||
filename.includes(path.sep + 'sourcemaps' + path.sep)
) {
return undefined;
}

return filename
.substr(filename.lastIndexOf(path.sep) + 1)
.replace(/(\.(android|ios|native))?\.js$/, '');
},
};
Loading

0 comments on commit a1b82ca

Please sign in to comment.