GeezerVison is showing github.com — Made some incremental progress on Jest tests · react/react@7ce229d
File treeExpand file treeCollapse file tree Open diff view settings packages/react-devtools-shared
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: package.json +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 47 | 47 | "error-stack-parser": "^2.0.2", | 48 | 48 | "eslint": "^6.1.0", | 49 | 49 | "eslint-config-fbjs": "^1.1.1", | | 50 | + "eslint-plugin-babel": "^5.3.0", | 50 | 51 | "eslint-plugin-flowtype": "^2.25.0", | 51 | 52 | "eslint-plugin-jest": "^22.15.0", | 52 | 53 | "eslint-plugin-no-for-of-loops": "^1.0.0", | 53 | | - "eslint-plugin-babel": "^5.3.0", | 54 | 54 | "eslint-plugin-react": "^6.7.1", | 55 | 55 | "eslint-plugin-react-internal": "link:./scripts/eslint-rules", | 56 | 56 | "fbjs-scripts": "^0.8.3", | | 61 | 61 | "google-closure-compiler": "20190301.0.0", | 62 | 62 | "gzip-size": "^3.0.0", | 63 | 63 | "jasmine-check": "^1.0.0-rc.0", | 64 | | - "jest": "^23.1.0", | 65 | | - "jest-diff": "^23.0.1", | | 64 | + "jest": "^23", | | 65 | + "jest-diff": "^23", | 66 | 66 | "jest-snapshot-serializer-raw": "^1.1.0", | 67 | 67 | "minimatch": "^3.0.4", | 68 | 68 | "minimist": "^1.2.0", | | 102 | 102 | "postinstall": "node node_modules/fbjs-scripts/node/check-dev-engines.js package.json && node ./scripts/flow/createFlowConfigs.js", | 103 | 103 | "debug-test": "cross-env NODE_ENV=development node --inspect-brk node_modules/.bin/jest --config ./scripts/jest/config.source.js --runInBand", | 104 | 104 | "test": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.source.js", | | 105 | + "test-devtools": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.devtools.js", | 105 | 106 | "test-persistent": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.source-persistent.js", | 106 | 107 | "debug-test-persistent": "cross-env NODE_ENV=development node --inspect-brk node_modules/.bin/jest --config ./scripts/jest/config.source-persistent.js --runInBand", | 107 | 108 | "test-prod": "cross-env NODE_ENV=production jest --config ./scripts/jest/config.source.js", | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/package.json +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | "@reach/tooltip": "^0.2.2", | 9 | 9 | "clipboard-js": "^0.3.6", | 10 | 10 | "events": "^3.0.0", | | 11 | + "local-storage-fallback": "^4.1.1", | 11 | 12 | "lodash.throttle": "^4.1.1", | 12 | 13 | "memoize-one": "^3.1.1", | 13 | 14 | "react-virtualized-auto-sizer": "^1.0.2" | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/__tests__/bridge-test.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,7 +30,7 @@ describe('Bridge', () => { | 30 | 30 | expect(wall.send).toHaveBeenCalledWith('shutdown'); | 31 | 31 |
| 32 | 32 | // Verify that the Bridge doesn't send messages after shutdown. | 33 | | - spyOn(console, 'warn'); | | 33 | + spyOnDevAndProd(console, 'warn'); | 34 | 34 | wall.send.mockClear(); | 35 | 35 | bridge.send('should not send'); | 36 | 36 | jest.runAllTimers(); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/__tests__/console-test.js +16-14Lines changed: 16 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,23 +13,10 @@ describe('console', () => { | 13 | 13 | let unpatchConsole; | 14 | 14 |
| 15 | 15 | beforeEach(() => { | 16 | | - const Console = require('../backend/console'); | | 16 | + const Console = require('react-devtools-shared/src/backend/console'); | 17 | 17 | patchConsole = Console.patch; | 18 | 18 | unpatchConsole = Console.unpatch; | 19 | 19 |
| 20 | | - const inject = global.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject; | 21 | | - global.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject = internals => { | 22 | | - inject(internals); | 23 | | - | 24 | | - Console.registerRenderer(internals); | 25 | | - }; | 26 | | - | 27 | | - React = require('react'); | 28 | | - ReactDOM = require('react-dom'); | 29 | | - | 30 | | - const utils = require('./utils'); | 31 | | - act = utils.act; | 32 | | - | 33 | 20 | // Patch a fake console so we can verify with tests below. | 34 | 21 | // Patching the real console is too complicated, | 35 | 22 | // because Jest itself has hooks into it as does our test env setup. | @@ -46,7 +33,22 @@ describe('console', () => { | 46 | 33 |
| 47 | 34 | Console.dangerous_setTargetConsoleForTesting(fakeConsole); | 48 | 35 |
| | 36 | + // Note the Console module only patches once, | | 37 | + // so it's important to patch the test console before injection. | 49 | 38 | patchConsole(); | | 39 | + | | 40 | + const inject = global.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject; | | 41 | + global.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject = internals => { | | 42 | + inject(internals); | | 43 | + | | 44 | + Console.registerRenderer(internals); | | 45 | + }; | | 46 | + | | 47 | + React = require('react'); | | 48 | + ReactDOM = require('react-dom'); | | 49 | + | | 50 | + const utils = require('./utils'); | | 51 | + act = utils.act; | 50 | 52 | }); | 51 | 53 |
| 52 | 54 | function normalizeCodeLocInfo(str) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/__tests__/setupEnv.js +10-6Lines changed: 10 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -// @flow | | 1 | +'use strict'; | 2 | 2 |
| 3 | | -import storage from 'local-storage-fallback'; | | 3 | +// Import test renderer and then reset modules for two reasons: | | 4 | +// 1. We don't want test renderer connected to the DevTools hooks. | | 5 | +// 2. This enables us to work around the on-renderer limitation. | | 6 | +// TODO This (or the resetModules below) might be the cause of the hooks erorr in some tests | | 7 | +const ReactTestRenderer = require.requireActual('react-test-renderer'); | 4 | 8 |
| 5 | | -// In case async/await syntax is used in a test. | 6 | | -import 'regenerator-runtime/runtime'; | | 9 | +jest.resetModules(); | | 10 | + | | 11 | +jest.mock('react-test-renderer', () => ReactTestRenderer); | 7 | 12 |
| 8 | 13 | // DevTools stores preferences between sessions in localStorage | 9 | 14 | if (!global.hasOwnProperty('localStorage')) { | 10 | | - global.localStorage = storage; | | 15 | + global.localStorage = require('local-storage-fallback').default; | 11 | 16 | } | 12 | 17 |
| 13 | 18 | // Mimic the global we set with Webpack's DefinePlugin | 14 | 19 | global.__DEV__ = process.env.NODE_ENV !== 'production'; | 15 | | -global.__TEST__ = process.env.NODE_ENV === 'test'; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/__tests__/utils.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -40,7 +40,8 @@ export async function actAsync( | 40 | 40 | }); | 41 | 41 |
| 42 | 42 | if (recursivelyFlush) { | 43 | | - while (jest.getTimerCount() > 0) { | | 43 | + // TODO (Jest v24) Replace with jest.getTimerCount() after we upgrade Jest | | 44 | + while (global.mockGetTimersCount() > 0) { | 44 | 45 | // $FlowFixMe Flow doens't know about "await act()" yet | 45 | 46 | await actDOM(async () => { | 46 | 47 | await actTestRenderer(async () => { | |
Collapse file Copy file name to clipboard +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | + | | 3 | +const baseConfig = require('./config.base'); | | 4 | + | | 5 | +module.exports = Object.assign({}, baseConfig, { | | 6 | + testRegex: 'packages/react-devtools-shared/src/__tests__/[^]+.test.js$', | | 7 | + modulePathIgnorePatterns: [], | | 8 | + snapshotSerializers: [ | | 9 | + require.resolve( | | 10 | + '../../packages/react-devtools-shared/src/__tests__/inspectedElementSerializer.js' | | 11 | + ), | | 12 | + require.resolve( | | 13 | + '../../packages/react-devtools-shared/src/__tests__/storeSerializer.js' | | 14 | + ), | | 15 | + ], | | 16 | + setupFiles: [ | | 17 | + ...baseConfig.setupFiles, | | 18 | + require.resolve('./setupHostConfigs.js'), | | 19 | + require.resolve( | | 20 | + '../../packages/react-devtools-shared/src/__tests__/setupEnv.js' | | 21 | + ), | | 22 | + ], | | 23 | + // TODO (Jest v24) Rename "setupFilesAfterEnv" after Jest upgrade | | 24 | + setupTestFrameworkScriptFile: require.resolve( | | 25 | + '../../packages/react-devtools-shared/src/__tests__/setupTests.js' | | 26 | + ), | | 27 | +}); |
Collapse file Copy file name to clipboardExpand all lines: scripts/jest/preprocessor.js +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -43,7 +43,10 @@ const babelOptions = { | 43 | 43 |
| 44 | 44 | // This optimization is important for extremely performance-sensitive (e.g. React source). | 45 | 45 | // It's okay to disable it for tests. | 46 | | - [require.resolve('@babel/plugin-transform-block-scoping'), {throwIfClosureRequired: false}], | | 46 | + [ | | 47 | + require.resolve('@babel/plugin-transform-block-scoping'), | | 48 | + {throwIfClosureRequired: false}, | | 49 | + ], | 47 | 50 | ], | 48 | 51 | retainLines: true, | 49 | 52 | }; | |
Collapse file Copy file name to clipboardExpand all lines: yarn.lock +15-2Lines changed: 15 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1879,6 +1879,7 @@ array.prototype.find@^2.0.1: | 1879 | 1879 | arrify@^1.0.1: | 1880 | 1880 | version "1.0.1" | 1881 | 1881 | resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d" | | 1882 | + integrity sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0= | 1882 | 1883 |
| 1883 | 1884 | arrify@^2.0.1: | 1884 | 1885 | version "2.0.1" | | 3513 | 3514 | resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.0.tgz#beb437e7022b3b6d49019d088665303ebe9c14ba" | 3514 | 3515 | integrity sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg== | 3515 | 3516 |
| | 3517 | +cookie@^0.3.1: | | 3518 | + version "0.3.1" | | 3519 | + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb" | | 3520 | + integrity sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s= | | 3521 | + | 3516 | 3522 | copy-concurrently@^1.0.0: | 3517 | 3523 | version "1.0.5" | 3518 | 3524 | resolved "https://registry.yarnpkg.com/copy-concurrently/-/copy-concurrently-1.0.5.tgz#92297398cae34937fcafd6ec8139c18051f0b5e0" | @@ -7215,7 +7221,7 @@ jest-config@^23.6.0: | 7215 | 7221 | micromatch "^2.3.11" | 7216 | 7222 | pretty-format "^23.6.0" | 7217 | 7223 |
| 7218 | | -jest-diff@^23.0.1, jest-diff@^23.6.0: | | 7224 | +jest-diff@^23, jest-diff@^23.6.0: | 7219 | 7225 | version "23.6.0" | 7220 | 7226 | resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-23.6.0.tgz#1500f3f16e850bb3d71233408089be099f610c7d" | 7221 | 7227 | integrity sha512-Gz9l5Ov+X3aL5L37IT+8hoCUsof1CVYBb2QEkOupK64XyRR3h+uRpYIm97K7sY8diFxowR8pIGEdyfMKTixo3g== | @@ -7536,7 +7542,7 @@ jest-worker@^24.6.0: | 7536 | 7542 | merge-stream "^1.0.1" | 7537 | 7543 | supports-color "^6.1.0" | 7538 | 7544 |
| 7539 | | -jest@^23.1.0: | | 7545 | +jest@^23: | 7540 | 7546 | version "23.6.0" | 7541 | 7547 | resolved "https://registry.yarnpkg.com/jest/-/jest-23.6.0.tgz#ad5835e923ebf6e19e7a1d7529a432edfee7813d" | 7542 | 7548 | integrity sha512-lWzcd+HSiqeuxyhG+EnZds6iO3Y3ZEnMrfZq/OTGvF/C+Z4fPMCdhWTGSAiO2Oym9rbEXfwddHhh6jqrTF3+Lw== | @@ -7941,6 +7947,13 @@ [email protected], loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.2. | 7941 | 7947 | emojis-list "^2.0.0" | 7942 | 7948 | json5 "^1.0.1" | 7943 | 7949 |
| | 7950 | +local-storage-fallback@^4.1.1: | | 7951 | + version "4.1.1" | | 7952 | + resolved "https://registry.yarnpkg.com/local-storage-fallback/-/local-storage-fallback-4.1.1.tgz#6dc964635c8e9ab6d522d7d88538f465b62bd161" | | 7953 | + integrity sha512-Ka4rem1FOgvIaPMokxXTP8DgW8gjfAQSdJC8TGrplDug7vh3b0PZnY/9euG3O3cIGAvJLp33mMU6MJ13x6S+Pw== | | 7954 | + dependencies: | | 7955 | + cookie "^0.3.1" | | 7956 | + | 7944 | 7957 | locate-path@^2.0.0: | 7945 | 7958 | version "2.0.0" | 7946 | 7959 | resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e" | |
|