Fixed remaining DevTools broken tests by fixing a hydration/spread bug
Brian Vaughn committed
Aug 27, 2019 at 08:50 UTC
896c993ada2875997a0f090e76992eb3c550d973
4 files changed
+14
-4
package.json
+1
@@ -109,6 +109,7 @@
109
"test-build": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.build.js",
110
"test-build-prod": "cross-env NODE_ENV=production jest --config ./scripts/jest/config.build.js",
111
"test-build-devtools": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.build-devtools.js",
112
+ "debug-test-build-devtools": "cross-env NODE_ENV=development node --inspect-brk node_modules/.bin/jest --config ./scripts/jest/config.build-devtools.js",
113
"test-dom-fixture": "cd fixtures/dom && yarn && yarn prestart && yarn test",
114
"flow": "node ./scripts/tasks/flow.js",
115
"flow-ci": "node ./scripts/tasks/flow-ci.js",
packages/react-devtools-shared/src/__tests__/bridge-test.js
+1
-1
@@ -30,7 +30,7 @@ describe('Bridge', () => {
30
expect(wall.send).toHaveBeenCalledWith('shutdown');
31
32
// Verify that the Bridge doesn't send messages after shutdown.
33
- spyOnDevAndProd(console, 'warn');
33
+ spyOn(console, 'warn');
34
wall.send.mockClear();
35
bridge.send('should not send');
36
jest.runAllTimers();
packages/react-devtools-shared/src/hydration.js
+5
-1
@@ -287,7 +287,11 @@ export function dehydrate(
287
};
288
289
if (typeof data[Symbol.iterator]) {
290
- [...data].forEach(
290
+ // TRICKY
291
+ // Don't use [...spread] syntax for this purpose.
292
+ // This project uses @babel/plugin-transform-spread in "loose" mode which only works with Array values.
293
+ // Other types (e.g. typed arrays, Sets) will not spread correctly.
294
+ Array.from(data).forEach(
295
(item, i) =>
296
(unserializableValue[i] = dehydrate(
297
item,
packages/react-devtools-shared/src/utils.js
+7
-2
@@ -266,14 +266,19 @@ export function shallowDiffers(prev: Object, next: Object): boolean {
266
}
267
268
export function getInObject(object: Object, path: Array<string | number>): any {
269
- return path.reduce((reduced: Object, attr: string | number): any => {
269
+ return path.reduce((reduced: Object, attr: any): any => {
270
if (reduced) {
271
if (hasOwnProperty.call(reduced, attr)) {
272
return reduced[attr];
273
}
274
if (typeof reduced[Symbol.iterator] === 'function') {
275
// Convert iterable to array and return array[index]
276
- return [...reduced][attr];
276
+ //
277
+ // TRICKY
278
+ // Don't use [...spread] syntax for this purpose.
279
+ // This project uses @babel/plugin-transform-spread in "loose" mode which only works with Array values.
280
+ // Other types (e.g. typed arrays, Sets) will not spread correctly.
281
+ return Array.from(reduced)[attr];
282
}
283
}
284