Skip to content

Commit

Permalink
chore: upgrade to jest 24 (#15778)
Browse files Browse the repository at this point in the history
* chore: upgrade to jest 24

* download react-is from npm manually
  • Loading branch information
SimenB authored and Sunil Pai committed Oct 3, 2019
1 parent 5943b1d commit e09097a
Show file tree
Hide file tree
Showing 13 changed files with 781 additions and 681 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@
"google-closure-compiler": "20190301.0.0",
"gzip-size": "^3.0.0",
"jasmine-check": "^1.0.0-rc.0",
"jest": "^23",
"jest-diff": "^23",
"jest": "^24.9.0",
"jest-diff": "^24.9.0",
"jest-snapshot-serializer-raw": "^1.1.0",
"minimatch": "^3.0.4",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"ncp": "^2.0.0",
"object-assign": "^4.1.1",
"pacote": "^9.5.6",
"prettier": "1.13.7",
"prop-types": "^15.6.2",
"random-seed": "^0.3.0",
Expand Down Expand Up @@ -100,7 +101,7 @@
"lint": "node ./scripts/tasks/eslint.js",
"lint-build": "node ./scripts/rollup/validate/index.js",
"extract-errors": "yarn build --type=dev --extract-errors",
"postinstall": "node node_modules/fbjs-scripts/node/check-dev-engines.js package.json && node ./scripts/flow/createFlowConfigs.js",
"postinstall": "node node_modules/fbjs-scripts/node/check-dev-engines.js package.json && node ./scripts/flow/createFlowConfigs.js && node ./scripts/yarn/downloadReactIsForPrettyFormat.js",
"debug-test": "cross-env NODE_ENV=development node --inspect-brk node_modules/.bin/jest --config ./scripts/jest/config.source.js --runInBand",
"test": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.source.js",
"test-persistent": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.source-persistent.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-mock-scheduler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"homepage": "https://reactjs.org/",
"peerDependencies": {
"jest": "^23.0.1",
"jest": "^23.0.1 || ^24.0.0",
"scheduler": "^0.15.0"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"homepage": "https://reactjs.org/",
"peerDependencies": {
"jest": "^23.0.1",
"jest": "^23.0.1 || ^24.0.0",
"react": "^16.0.0",
"react-test-renderer": "^16.0.0"
},
Expand Down
1 change: 0 additions & 1 deletion packages/react-devtools-extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"archiver": "^3.0.0",
"babel-core": "^7.0.0-bridge",
"babel-eslint": "^9.0.0",
"babel-jest": "^24.7.1",
"babel-loader": "^8.0.4",
"chrome-launch": "^1.1.4",
"child-process-promise": "^2.2.1",
Expand Down
1 change: 0 additions & 1 deletion packages/react-devtools-inline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@babel/preset-react": "^7.0.0",
"babel-core": "^7.0.0-bridge",
"babel-eslint": "^9.0.0",
"babel-jest": "^24.7.1",
"babel-loader": "^8.0.4",
"cross-env": "^3.1.4",
"css-loader": "^1.0.1",
Expand Down
5 changes: 2 additions & 3 deletions packages/react-devtools-shared/src/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function act(callback: Function): void {
});

// Flush Bridge operations
while (global.mockGetTimersCount() > 0) {
while (jest.getTimerCount() > 0) {
actDOM(() => {
actTestRenderer(() => {
jest.runAllTimers();
Expand All @@ -49,8 +49,7 @@ export async function actAsync(
});

if (recursivelyFlush) {
// TODO (Jest v24) Replace with jest.getTimerCount() after we upgrade Jest
while (global.mockGetTimersCount() > 0) {
while (jest.getTimerCount() > 0) {
// $FlowFixMe Flow doens't know about "await act()" yet
await actDOM(async () => {
await actTestRenderer(async () => {
Expand Down
1 change: 0 additions & 1 deletion packages/react-devtools-shell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"@babel/preset-react": "^7.0.0",
"babel-core": "^7.0.0-bridge",
"babel-eslint": "^9.0.0",
"babel-jest": "^24.7.1",
"babel-loader": "^8.0.4",
"cross-env": "^3.1.4",
"css-loader": "^1.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('ReactTestRendererAsync', () => {

expect(() =>
expect(Scheduler).toFlushAndYieldThrough(['foo', 'baz']),
).toThrow('Expected value to equal:');
).toThrow('// deep equality');
});

it('toFlushAndYield', () => {
Expand All @@ -181,7 +181,7 @@ describe('ReactTestRendererAsync', () => {
);

expect(() => expect(Scheduler).toFlushWithoutYielding()).toThrowError(
'Expected value to equal:',
'// deep equality',
);

renderer.update(
Expand All @@ -193,7 +193,7 @@ describe('ReactTestRendererAsync', () => {
);

expect(() => expect(Scheduler).toFlushAndYield(['foo', 'baz'])).toThrow(
'Expected value to equal:',
'// deep equality',
);
});

Expand Down Expand Up @@ -254,7 +254,7 @@ describe('ReactTestRendererAsync', () => {

ReactTestRenderer.create(<App />);
expect(() => expect(Scheduler).toHaveYielded(['A', 'B'])).toThrow(
'Expected value to equal:',
'// deep equality',
);
});

Expand Down
2 changes: 1 addition & 1 deletion scripts/jest/config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
'.*': require.resolve('./preprocessor.js'),
},
setupFiles: [require.resolve('./setupEnvironment.js')],
setupTestFrameworkScriptFile: require.resolve('./setupTests.js'),
setupFilesAfterEnv: [require.resolve('./setupTests.js')],
// Only include files directly in __tests__, not in nested folders.
testRegex: '/__tests__/[^/]*(\\.js|\\.coffee|[^d]\\.ts)$',
moduleFileExtensions: ['js', 'json', 'node', 'coffee', 'ts'],
Expand Down
9 changes: 5 additions & 4 deletions scripts/jest/config.build-devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ module.exports = Object.assign({}, baseConfig, {
'../../packages/react-devtools-shared/src/__tests__/setupEnv.js'
),
],
// TODO (Jest v24) Rename "setupFilesAfterEnv" after Jest upgrade
setupTestFrameworkScriptFile: require.resolve(
'../../packages/react-devtools-shared/src/__tests__/setupTests.js'
),
setupFilesAfterEnv: [
require.resolve(
'../../packages/react-devtools-shared/src/__tests__/setupTests.js'
),
],
});
3 changes: 3 additions & 0 deletions scripts/jest/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ module.exports = {
if (filePath.match(/\.ts$/) && !filePath.match(/\.d\.ts$/)) {
return tsPreprocessor.compile(src, filePath);
}
if (filePath.match(/\.json$/)) {
return src;
}
if (!filePath.match(/\/third_party\//)) {
// for test files, we also apply the async-await transform, but we want to
// make sure we don't accidentally apply that transform to product code.
Expand Down
30 changes: 30 additions & 0 deletions scripts/yarn/downloadReactIsForPrettyFormat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const path = require('path');
const pacote = require('pacote');
const rimraf = require('rimraf');
const prettyFormatPkg = require('pretty-format/package.json');
const prettyFormatPkgPath = require.resolve('pretty-format/package.json');

const reactIsDependencyVersion = prettyFormatPkg.dependencies['react-is'];

if (!reactIsDependencyVersion) {
throw new Error('Unable to find `react-is` dependency in `pretty-format`');
}

const prettyFormatNodeModulesReactIsDir = path.join(
path.dirname(prettyFormatPkgPath),
'node_modules/react-is'
);

rimraf.sync(prettyFormatNodeModulesReactIsDir);

pacote
.extract(
`react-is@${reactIsDependencyVersion}`,
prettyFormatNodeModulesReactIsDir
)
.catch(error => {
console.error(error);
process.exitCode = 1;
});
Loading

0 comments on commit e09097a

Please sign in to comment.