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

Run Jest in production mode #11616

Merged
merged 35 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
71469e6
Move Jest setup files to /dev/ subdirectory
gaearon Nov 21, 2017
d97968f
Clone Jest /dev/ files into /prod/
gaearon Nov 21, 2017
3c7438a
Move shared code into scripts/jest
gaearon Nov 21, 2017
6e6ce26
Move Jest config into the scripts folder
gaearon Nov 21, 2017
d751fe5
Fix the equivalence test
gaearon Nov 21, 2017
f43aaf5
Add yarn test-prod to run Jest with production environment
gaearon Nov 21, 2017
991e359
Actually flip the production tests to run in prod environment
gaearon Nov 21, 2017
ae39a60
Ignore expectDev() calls in production
gaearon Nov 21, 2017
8325c6d
Decode errors so tests can assert on their messages
gaearon Nov 21, 2017
b8b136b
Remove ReactDOMProduction-test
gaearon Nov 21, 2017
cabddb7
Remove production switches from ReactErrorUtils
gaearon Nov 21, 2017
bc3027f
Add and use spyOnDev() for warnings
gaearon Nov 21, 2017
22e0158
Replace expectDev() with expect() in __DEV__ blocks
gaearon Nov 21, 2017
efa46d3
Enable User Timing API for production testing
gaearon Nov 21, 2017
6e34120
Test for explicit Object.freeze() differences between PROD and DEV
gaearon Nov 21, 2017
871f2d8
Run Jest via "yarn test" on CI
gaearon Nov 22, 2017
0d2bca8
Remove unused variable
gaearon Nov 22, 2017
5ab3775
Assert different error messages
gaearon Nov 22, 2017
623becd
Fix error handling tests
gaearon Nov 22, 2017
50be63d
Fix more assertions
gaearon Nov 22, 2017
9208e42
Change tests to document the DEV/PROD difference for state invariant
gaearon Nov 22, 2017
32dccc4
Remove unnecessary split between DEV/PROD ref tests
gaearon Nov 22, 2017
efc409d
Fix more test message assertions
gaearon Nov 22, 2017
cfdf0fc
Make validateDOMNesting tests DEV-only
gaearon Nov 22, 2017
7b253ff
Fix error message assertions
gaearon Nov 22, 2017
4fe3b85
Document existing DEV/PROD message difference (possible bug)
gaearon Nov 22, 2017
60212f2
Change mocking assertions to be DEV-only
gaearon Nov 22, 2017
b5263d6
Fix the error code test
gaearon Nov 22, 2017
271aff0
Fix more error message assertions
gaearon Nov 22, 2017
5b40873
Fix the last failing test due to known issue
gaearon Nov 22, 2017
1821d1a
Run production tests on CI
gaearon Nov 22, 2017
8ebc499
Unify configuration
gaearon Nov 22, 2017
6758f4c
Fix coverage script
gaearon Nov 22, 2017
16d77e8
Remove expectDev from eslintrc
gaearon Nov 22, 2017
66e4457
Run everything in band
gaearon Nov 22, 2017
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 .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ module.exports = {

globals: {
expectDev: true,
spyOnDev: true,
},
};
33 changes: 2 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,40 +102,11 @@
"linc": "node ./scripts/tasks/linc.js",
"lint": "node ./scripts/tasks/eslint.js",
"postinstall": "node node_modules/fbjs-scripts/node/check-dev-engines.js package.json",
"test": "jest",
"test": "jest --config scripts/jest/dev/config.js",
"test-prod": "jest --config scripts/jest/prod/config.js",
"flow": "node ./scripts/tasks/flow.js",
"prettier": "node ./scripts/prettier/index.js write-changed",
"prettier-all": "node ./scripts/prettier/index.js write",
"version-check": "node ./scripts/tasks/version-check.js"
},
"jest": {
"modulePathIgnorePatterns": [
"<rootDir>/scripts/rollup/shims/",
"<rootDir>/scripts/bench/"
],
"transform": {
".*": "./scripts/jest/preprocessor.js"
},
"setupFiles": [
"./scripts/jest/setup.js",
"./scripts/jest/environment.js"
],
"setupTestFrameworkScriptFile": "./scripts/jest/test-framework-setup.js",
"testRegex": "/__tests__/.*(\\.js|\\.coffee|[^d]\\.ts)$",
"moduleFileExtensions": [
"js",
"json",
"node",
"coffee",
"ts"
],
"roots": [
"<rootDir>/packages",
"<rootDir>/scripts"
],
"collectCoverageFrom": [
"packages/**/*.js"
],
"timers": "fake"
}
}
136 changes: 74 additions & 62 deletions packages/react-dom/src/__tests__/CSSPropertyOperations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@ describe('CSSPropertyOperations', () => {
}
}

spyOn(console, 'error');
spyOnDev(console, 'error');
var root = document.createElement('div');
ReactDOM.render(<Comp />, root);
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual(
'Warning: Unsupported style property background-color. Did you mean backgroundColor?' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
if (__DEV__) {
expect(console.error.calls.count()).toBe(1);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual(
'Warning: Unsupported style property background-color. Did you mean backgroundColor?' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
}
});

it('should warn when updating hyphenated style names', () => {
Expand All @@ -111,7 +113,7 @@ describe('CSSPropertyOperations', () => {
}
}

spyOn(console, 'error');
spyOnDev(console, 'error');
var styles = {
'-ms-transform': 'translate3d(0, 0, 0)',
'-webkit-transform': 'translate3d(0, 0, 0)',
Expand All @@ -120,17 +122,19 @@ describe('CSSPropertyOperations', () => {
ReactDOM.render(<Comp />, root);
ReactDOM.render(<Comp style={styles} />, root);

expectDev(console.error.calls.count()).toBe(2);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual(
'Warning: Unsupported style property -ms-transform. Did you mean msTransform?' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toEqual(
'Warning: Unsupported style property -webkit-transform. Did you mean WebkitTransform?' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
if (__DEV__) {
expect(console.error.calls.count()).toBe(2);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual(
'Warning: Unsupported style property -ms-transform. Did you mean msTransform?' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toEqual(
'Warning: Unsupported style property -webkit-transform. Did you mean WebkitTransform?' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
}
});

it('warns when miscapitalizing vendored style names', () => {
Expand All @@ -150,23 +154,25 @@ describe('CSSPropertyOperations', () => {
}
}

spyOn(console, 'error');
spyOnDev(console, 'error');
var root = document.createElement('div');
ReactDOM.render(<Comp />, root);
// msTransform is correct already and shouldn't warn
expectDev(console.error.calls.count()).toBe(2);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual(
'Warning: Unsupported vendor-prefixed style property oTransform. ' +
'Did you mean OTransform?' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toEqual(
'Warning: Unsupported vendor-prefixed style property webkitTransform. ' +
'Did you mean WebkitTransform?' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
if (__DEV__) {
// msTransform is correct already and shouldn't warn
expect(console.error.calls.count()).toBe(2);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual(
'Warning: Unsupported vendor-prefixed style property oTransform. ' +
'Did you mean OTransform?' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toEqual(
'Warning: Unsupported vendor-prefixed style property webkitTransform. ' +
'Did you mean WebkitTransform?' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
}
});

it('should warn about style having a trailing semicolon', () => {
Expand All @@ -187,22 +193,24 @@ describe('CSSPropertyOperations', () => {
}
}

spyOn(console, 'error');
spyOnDev(console, 'error');
var root = document.createElement('div');
ReactDOM.render(<Comp />, root);
expectDev(console.error.calls.count()).toBe(2);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual(
"Warning: Style property values shouldn't contain a semicolon. " +
'Try "backgroundColor: blue" instead.' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toEqual(
"Warning: Style property values shouldn't contain a semicolon. " +
'Try "color: red" instead.' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
if (__DEV__) {
expect(console.error.calls.count()).toBe(2);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual(
"Warning: Style property values shouldn't contain a semicolon. " +
'Try "backgroundColor: blue" instead.' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toEqual(
"Warning: Style property values shouldn't contain a semicolon. " +
'Try "color: red" instead.' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
}
});

it('should warn about style containing a NaN value', () => {
Expand All @@ -214,16 +222,18 @@ describe('CSSPropertyOperations', () => {
}
}

spyOn(console, 'error');
spyOnDev(console, 'error');
var root = document.createElement('div');
ReactDOM.render(<Comp />, root);

expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual(
'Warning: `NaN` is an invalid value for the `fontSize` css style property.' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
if (__DEV__) {
expect(console.error.calls.count()).toBe(1);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual(
'Warning: `NaN` is an invalid value for the `fontSize` css style property.' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
}
});

it('should not warn when setting CSS custom properties', () => {
Expand All @@ -246,16 +256,18 @@ describe('CSSPropertyOperations', () => {
}
}

spyOn(console, 'error');
spyOnDev(console, 'error');
var root = document.createElement('div');
ReactDOM.render(<Comp />, root);

expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual(
'Warning: `Infinity` is an invalid value for the `fontSize` css style property.' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
if (__DEV__) {
expect(console.error.calls.count()).toBe(1);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual(
'Warning: `Infinity` is an invalid value for the `fontSize` css style property.' +
'\n in div (at **)' +
'\n in Comp (at **)',
);
}
});

it('should not add units to CSS custom properties', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe('DOMPropertyOperations', () => {

it('should not remove attributes for special properties', () => {
var container = document.createElement('div');
spyOn(console, 'error');
spyOnDev(console, 'error');
ReactDOM.render(
<input type="text" value="foo" onChange={function() {}} />,
container,
Expand Down
12 changes: 7 additions & 5 deletions packages/react-dom/src/__tests__/EventPluginHub-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('EventPluginHub', () => {
});

it('should prevent non-function listeners, at dispatch', () => {
spyOn(console, 'error');
spyOnDev(console, 'error');
var node = ReactTestUtils.renderIntoDocument(
<div onClick="not a function" />,
);
Expand All @@ -31,10 +31,12 @@ describe('EventPluginHub', () => {
}).toThrowError(
'Expected `onClick` listener to be a function, instead got a value of `string` type.',
);
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Expected `onClick` listener to be a function, instead got a value of `string` type.',
);
if (__DEV__) {
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'Expected `onClick` listener to be a function, instead got a value of `string` type.',
);
}
});

it('should not prevent null listeners, at dispatch', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,15 @@ describe('ReactBrowserEventEmitter', () => {
putListener(CHILD, ON_CLICK_KEY, recordIDAndReturnFalse.bind(null, CHILD));
putListener(PARENT, ON_CLICK_KEY, recordID.bind(null, PARENT));
putListener(GRANDPARENT, ON_CLICK_KEY, recordID.bind(null, GRANDPARENT));
spyOn(console, 'error');
spyOnDev(console, 'error');
ReactTestUtils.Simulate.click(CHILD);
expect(idCallOrder.length).toBe(3);
expect(idCallOrder[0]).toBe(CHILD);
expect(idCallOrder[1]).toBe(PARENT);
expect(idCallOrder[2]).toBe(GRANDPARENT);
expectDev(console.error.calls.count()).toEqual(0);
if (__DEV__) {
expect(console.error.calls.count()).toEqual(0);
}
});

/**
Expand Down
Loading