Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 07720dc

Browse files
committedApr 28, 2017
Fix snapshot serializer require, restructure pretty-format.
1 parent 4f020f6 commit 07720dc

File tree

21 files changed

+74
-49
lines changed

21 files changed

+74
-49
lines changed
 

‎.flowconfig

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
.*/dangerfile.js
88

99
[options]
10+
module.name_mapper='^pretty-format$' -> '<PROJECT_ROOT>/packages/pretty-format/src/index.js'
1011
module.name_mapper='^types/\(.*\)$' -> '<PROJECT_ROOT>/types/\1.js'
1112
module.name_mapper='\(jest-[^/]*\)' -> '<PROJECT_ROOT>/packages/\1/src/index.js'
1213

‎integration_tests/__tests__/__snapshots__/failures-test.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Object {
7070
7171
Expected two assertions to be called but only received one assertion call.
7272
73-
at addAssertionErrors (../../packages/jest-jasmine2/build/setup-jest-globals.js:62:21)
73+
at addAssertionErrors (../../packages/jest-jasmine2/build/setup-jest-globals.js:64:21)
7474
7575
● .assertions() › throws on redeclare of assertion count
7676
@@ -87,7 +87,7 @@ Object {
8787
8888
Expected zero assertions to be called but only received one assertion call.
8989
90-
at addAssertionErrors (../../packages/jest-jasmine2/build/setup-jest-globals.js:62:21)
90+
at addAssertionErrors (../../packages/jest-jasmine2/build/setup-jest-globals.js:64:21)
9191
9292
.assertions()
9393
throws

‎packages/jest-diff/src/index.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313
import type {DiffOptions} from './diffStrings';
1414

15-
const ReactElementPlugin = require('pretty-format/build/plugins/ReactElement');
16-
const ReactTestComponentPlugin = require('pretty-format/build/plugins/ReactTestComponent');
17-
const AsymmetricMatcherPlugin = require('pretty-format/build/plugins/AsymmetricMatcher');
18-
const HTMLElementPlugin = require('pretty-format/build/plugins/HTMLElement');
19-
const ImmutablePlugins = require('pretty-format/build/plugins/ImmutablePlugins');
15+
const {
16+
ReactElement,
17+
ReactTestComponent,
18+
AsymmetricMatcher,
19+
HTMLElement,
20+
Immutable,
21+
} = require('pretty-format').plugins;
2022

2123
const chalk = require('chalk');
2224
const diffStrings = require('./diffStrings');
@@ -26,11 +28,11 @@ const prettyFormat = require('pretty-format');
2628
const {NO_DIFF_MESSAGE, SIMILAR_MESSAGE} = require('./constants');
2729

2830
const PLUGINS = [
29-
ReactTestComponentPlugin,
30-
ReactElementPlugin,
31-
AsymmetricMatcherPlugin,
32-
HTMLElementPlugin,
33-
].concat(ImmutablePlugins);
31+
ReactTestComponent,
32+
ReactElement,
33+
AsymmetricMatcher,
34+
HTMLElement,
35+
].concat(Immutable);
3436
const FORMAT_OPTIONS = {
3537
plugins: PLUGINS,
3638
};

‎packages/jest-jasmine2/src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ function jasmine2(
8080
)({
8181
config,
8282
globalConfig,
83+
localRequire: runtime.requireModule.bind(runtime),
8384
testPath,
8485
});
8586

‎packages/jest-jasmine2/src/setup-jest-globals.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'use strict';
1212

1313
import type {GlobalConfig, Path, ProjectConfig} from 'types/Config';
14+
import type {Plugin} from 'types/PrettyFormat';
1415

1516
const {getState, setState} = require('jest-matchers');
1617
const {initializeSnapshotState, addSerializer} = require('jest-snapshot');
@@ -24,6 +25,7 @@ const {
2425
export type SetupOptions = {|
2526
config: ProjectConfig,
2627
globalConfig: GlobalConfig,
28+
localRequire: (moduleName: string) => Plugin,
2729
testPath: Path,
2830
|};
2931

@@ -104,12 +106,16 @@ const patchJasmine = () => {
104106
})(global.jasmine.Spec);
105107
};
106108

107-
module.exports = ({config, globalConfig, testPath}: SetupOptions) => {
109+
module.exports = ({
110+
config,
111+
globalConfig,
112+
localRequire,
113+
testPath,
114+
}: SetupOptions) => {
108115
// Jest tests snapshotSerializers in order preceding built-in serializers.
109116
// Therefore, add in reverse because the last added is the first tested.
110117
config.snapshotSerializers.concat().reverse().forEach(path => {
111-
// $FlowFixMe
112-
addSerializer(require(path));
118+
addSerializer(localRequire(path));
113119
});
114120
setState({testPath});
115121
patchJasmine();

‎packages/jest-matcher-utils/src/index.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212

1313
const chalk = require('chalk');
1414
const prettyFormat = require('pretty-format');
15-
const AsymmetricMatcherPlugin = require('pretty-format/build/plugins/AsymmetricMatcher');
16-
const ReactElementPlugin = require('pretty-format/build/plugins/ReactElement');
17-
const HTMLElementPlugin = require('pretty-format/build/plugins/HTMLElement');
18-
const ImmutablePlugins = require('pretty-format/build/plugins/ImmutablePlugins');
19-
20-
const PLUGINS = [
21-
AsymmetricMatcherPlugin,
22-
ReactElementPlugin,
23-
HTMLElementPlugin,
24-
].concat(ImmutablePlugins);
15+
const {
16+
AsymmetricMatcher,
17+
ReactElement,
18+
HTMLElement,
19+
Immutable,
20+
} = require('pretty-format').plugins;
21+
22+
const PLUGINS = [AsymmetricMatcher, ReactElement, HTMLElement].concat(
23+
Immutable,
24+
);
2525

2626
export type ValueType =
2727
| 'array'

‎packages/jest-snapshot/src/plugins.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
*/
1010
'use strict';
1111

12-
const ReactElementPlugin = require('pretty-format/build/plugins/ReactElement');
13-
const ReactTestComponentPlugin = require('pretty-format/build/plugins/ReactTestComponent');
14-
const HTMLElementPlugin = require('pretty-format/build/plugins/HTMLElement');
15-
const ImmutablePlugins = require('pretty-format/build/plugins/ImmutablePlugins');
12+
import type {Plugin} from 'types/PrettyFormat';
1613

17-
let PLUGINS = [
18-
ReactElementPlugin,
19-
ReactTestComponentPlugin,
20-
HTMLElementPlugin,
21-
].concat(ImmutablePlugins);
14+
const {
15+
HTMLElement,
16+
Immutable,
17+
ReactElement,
18+
ReactTestComponent,
19+
} = require('pretty-format').plugins;
20+
21+
let PLUGINS = [HTMLElement, ReactElement, ReactTestComponent].concat(Immutable);
2222

2323
// Prepend to list so the last added is the first tested.
24-
exports.addSerializer = (plugin: any) => {
24+
exports.addSerializer = (plugin: Plugin) => {
2525
PLUGINS = [plugin].concat(PLUGINS);
2626
};
2727

‎packages/pretty-format/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ prettyFormat(obj, {
117117

118118
```js
119119
const prettyFormat = require('pretty-format');
120-
const reactTestPlugin = require('pretty-format/build/plugins/ReactTestComponent');
121-
const reactElementPlugin = require('pretty-format/build/plugins/ReactElement');
120+
const reactTestPlugin = require('pretty-format').plugins.ReactTestComponent;
121+
const reactElementPlugin = require('pretty-format').plugins.ReactElement;
122122

123123
const React = require('react');
124124
const renderer = require('react-test-renderer');

‎packages/pretty-format/src/index.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111

1212
'use strict';
1313

14-
import type {Colors, Refs, StringOrNull, Plugins, Options} from './types.js';
14+
import type {
15+
Colors,
16+
Refs,
17+
StringOrNull,
18+
Plugins,
19+
Options,
20+
} from 'types/PrettyFormat';
1521

1622
const style = require('ansi-styles');
1723

@@ -949,4 +955,13 @@ function prettyFormat(val: any, initialOptions?: InitialOptions): string {
949955
);
950956
}
951957

958+
prettyFormat.plugins = {
959+
AsymmetricMatcher: require('./plugins/AsymmetricMatcher'),
960+
ConvertAnsi: require('./plugins/ConvertAnsi'),
961+
HTMLElement: require('./plugins/HTMLElement'),
962+
Immutable: require('./plugins/ImmutablePlugins'),
963+
ReactElement: require('./plugins/ReactElement'),
964+
ReactTestComponent: require('./plugins/ReactTestComponent'),
965+
};
966+
952967
module.exports = prettyFormat;

‎packages/pretty-format/src/plugins/AsymmetricMatcher.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
import type {Colors, Indent, Options, Print, Plugin} from '../types.js';
12+
import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat';
1313

1414
const asymmetricMatcher = Symbol.for('jest.asymmetricMatcher');
1515
const SPACE = ' ';

‎packages/pretty-format/src/plugins/ConvertAnsi.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
'use strict';
1212

13-
import type {Colors, Indent, Options, Print, Plugin} from '../types.js';
13+
import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat';
1414

1515
const ansiRegex = require('ansi-regex');
1616

‎packages/pretty-format/src/plugins/HTMLElement.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
'use strict';
1212

13-
import type {Colors, Indent, Options, Print, Plugin} from '../types.js';
13+
import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat';
1414

1515
const escapeHTML = require('./lib/escapeHTML');
1616
const HTML_ELEMENT_REGEXP = /(HTML\w*?Element)/;

‎packages/pretty-format/src/plugins/ImmutableList.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
'use strict';
1212

13-
import type {Colors, Indent, Options, Print, Plugin} from '../types.js';
13+
import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat';
1414

1515
const printImmutable = require('./lib/printImmutable');
1616

‎packages/pretty-format/src/plugins/ImmutableMap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
'use strict';
1212

13-
import type {Colors, Indent, Options, Print, Plugin} from '../types.js';
13+
import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat';
1414

1515
const printImmutable = require('./lib/printImmutable');
1616

‎packages/pretty-format/src/plugins/ImmutableOrderedMap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
'use strict';
1212

13-
import type {Colors, Indent, Options, Print, Plugin} from '../types.js';
13+
import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat';
1414

1515
const printImmutable = require('./lib/printImmutable');
1616

‎packages/pretty-format/src/plugins/ImmutableOrderedSet.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
'use strict';
1212

13-
import type {Colors, Indent, Options, Print, Plugin} from '../types.js';
13+
import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat';
1414

1515
const printImmutable = require('./lib/printImmutable');
1616

‎packages/pretty-format/src/plugins/ImmutableSet.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
'use strict';
1212

13-
import type {Colors, Indent, Options, Print, Plugin} from '../types.js';
13+
import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat';
1414

1515
const printImmutable = require('./lib/printImmutable');
1616

‎packages/pretty-format/src/plugins/ImmutableStack.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
'use strict';
1212

13-
import type {Colors, Indent, Options, Print, Plugin} from '../types.js';
13+
import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat';
1414

1515
const printImmutable = require('./lib/printImmutable');
1616

‎packages/pretty-format/src/plugins/ReactTestComponent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
Plugin,
1919
ReactTestObject,
2020
ReactTestChild,
21-
} from '../types.js';
21+
} from 'types/PrettyFormat';
2222

2323
const escapeHTML = require('./lib/escapeHTML');
2424

‎packages/pretty-format/src/plugins/lib/printImmutable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
'use strict';
1212

13-
import type {Colors, Indent, Options, Print} from '../../types.js';
13+
import type {Colors, Indent, Options, Print} from 'types/PrettyFormat';
1414

1515
const IMMUTABLE_NAMESPACE = 'Immutable.';
1616
const SPACE = ' ';
File renamed without changes.

0 commit comments

Comments
 (0)
Please sign in to comment.