Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean references to @providesModule #7147

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
- `[*]` Bump dated dependencies ([#6978](https://github.com/facebook/jest/pull/6978))
- `[scripts]` Don’t make empty subfolders for ignored files in build folder ([#7001](https://github.com/facebook/jest/pull/7001))
- `[docs]` Add missing export statement in `puppeteer_environment.js` under `docs/Puppeteer.md` ([#7127](https://github.com/facebook/jest/pull/7127))
- `[docs]` Remove references to `@providesModule` which isn't supported anymore ([#7147](https://github.com/facebook/jest/pull/7147))

## 23.6.0

Expand Down
19 changes: 0 additions & 19 deletions docs/TutorialReactNative.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,3 @@ jest.mock('Text', () => {
In other cases you may want to mock a native module that isn't a React component. The same technique can be applied. We recommend inspecting the native module's source code and logging the module when running a react native app on a real device and then modeling a manual mock after the real module.

If you end up mocking the same modules over and over it is recommended to define these mocks in a separate file and add it to the list of `setupFiles`.

### `@providesModule`

If you'd like to use Facebook's `@providesModule` module system through an npm package, the default haste config option must be overwritten and npm modules must be added to `providesModuleNodeModules`:

```json
"haste": {
"defaultPlatform": "ios",
"platforms": ["android", "ios"],
"providesModuleNodeModules": [
"react",
"react-native",
"my-awesome-module",
"my-text-component"
]
},
```

If you'd like to test a different default platform or if you are building for other platforms, the `defaultPlatform` and `platforms` configuration option can be updated.
44 changes: 19 additions & 25 deletions packages/jest-docblock/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('docblock', () => {
const code =
'/**' +
os.EOL +
' * @providesModule foo' +
' * @team foo' +
os.EOL +
'* // TODO: test' +
os.EOL +
Expand All @@ -28,7 +28,7 @@ describe('docblock', () => {
expect(docblock.extract(code)).toBe(
'/**' +
os.EOL +
' * @providesModule foo' +
' * @team foo' +
os.EOL +
'* // TODO: test' +
os.EOL +
Expand All @@ -40,43 +40,43 @@ describe('docblock', () => {
const code =
'/**' +
os.EOL +
' * @providesModule foo' +
' * @team foo' +
os.EOL +
'*/' +
os.EOL +
'const x = foo;';
expect(docblock.extract(code)).toBe(
'/**' + os.EOL + ' * @providesModule foo' + os.EOL + '*/',
'/**' + os.EOL + ' * @team foo' + os.EOL + '*/',
);
});

it('extracts valid docblock with more comments', () => {
const code =
'/**' +
os.EOL +
' * @providesModule foo' +
' * @team foo' +
os.EOL +
'*/' +
os.EOL +
'const x = foo;' +
os.EOL +
'/**foo*/';
expect(docblock.extract(code)).toBe(
'/**' + os.EOL + ' * @providesModule foo' + os.EOL + '*/',
'/**' + os.EOL + ' * @team foo' + os.EOL + '*/',
);
});

it('extracts from invalid docblock', () => {
const code =
'/*' +
os.EOL +
' * @providesModule foo' +
' * @team foo' +
os.EOL +
'*/' +
os.EOL +
'const x = foo;';
expect(docblock.extract(code)).toBe(
'/*' + os.EOL + ' * @providesModule foo' + os.EOL + '*/',
'/*' + os.EOL + ' * @team foo' + os.EOL + '*/',
);
});

Expand All @@ -102,7 +102,7 @@ describe('docblock', () => {
'/**' +
os.EOL +
'' +
' * @providesModule foo' +
' * @team foo' +
os.EOL +
'' +
' * @css a b' +
Expand All @@ -115,7 +115,7 @@ describe('docblock', () => {
expect(docblock.parse(code)).toEqual({
css: 'a b',
'preserve-whitespace': '',
providesModule: 'foo',
team: 'foo',
});
});

Expand Down Expand Up @@ -168,7 +168,7 @@ describe('docblock', () => {
' * Copyright 2004-present Facebook. All Rights Reserved.' +
os.EOL +
'' +
' * @providesModule foo' +
' * @team foo' +
os.EOL +
'' +
' * @css a b' +
Expand All @@ -187,7 +187,7 @@ describe('docblock', () => {
expect(docblock.parse(code)).toEqual({
css: 'a b',
'preserve-whitespace': '',
providesModule: 'foo',
team: 'foo',
});
});

Expand All @@ -196,7 +196,7 @@ describe('docblock', () => {
'/**' +
os.EOL +
'' +
' * @providesModule foo' +
' * @team foo' +
os.EOL +
'' +
' * // TODO: test' +
Expand All @@ -205,7 +205,7 @@ describe('docblock', () => {
' */';
expect(docblock.parseWithComments(code)).toEqual({
comments: '// TODO: test',
pragmas: {providesModule: 'foo'},
pragmas: {team: 'foo'},
});
});

Expand Down Expand Up @@ -283,17 +283,11 @@ describe('docblock', () => {
});
});

it('supports slashes in @providesModule directive', () => {
it('supports slashes in @team directive', () => {
const code =
'/**' +
os.EOL +
'' +
' * @providesModule apple/banana' +
os.EOL +
'' +
' */';
'/**' + os.EOL + '' + ' * @team apple/banana' + os.EOL + '' + ' */';
expect(docblock.parse(code)).toEqual({
providesModule: 'apple/banana',
team: 'apple/banana',
});
});

Expand Down Expand Up @@ -456,14 +450,14 @@ describe('docblock', () => {
it('prints docblocks with pragmas', () => {
const pragmas = {
flow: 'foo',
providesModule: 'x/y/z',
team: 'x/y/z',
};
expect(docblock.print({pragmas})).toEqual(
'/**' +
os.EOL +
' * @flow foo' +
os.EOL +
' * @providesModule x/y/z' +
' * @team x/y/z' +
os.EOL +
' */',
);
Expand Down