Skip to content

Commit 896c993

Browse files
author
Brian Vaughn
committed
Fixed remaining DevTools broken tests by fixing a hydration/spread bug
1 parent e3cc42b commit 896c993

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"test-build": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.build.js",
110110
"test-build-prod": "cross-env NODE_ENV=production jest --config ./scripts/jest/config.build.js",
111111
"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",
112113
"test-dom-fixture": "cd fixtures/dom && yarn && yarn prestart && yarn test",
113114
"flow": "node ./scripts/tasks/flow.js",
114115
"flow-ci": "node ./scripts/tasks/flow-ci.js",

packages/react-devtools-shared/src/__tests__/bridge-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('Bridge', () => {
3030
expect(wall.send).toHaveBeenCalledWith('shutdown');
3131

3232
// Verify that the Bridge doesn't send messages after shutdown.
33-
spyOnDevAndProd(console, 'warn');
33+
spyOn(console, 'warn');
3434
wall.send.mockClear();
3535
bridge.send('should not send');
3636
jest.runAllTimers();

packages/react-devtools-shared/src/hydration.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,11 @@ export function dehydrate(
287287
};
288288

289289
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(
291295
(item, i) =>
292296
(unserializableValue[i] = dehydrate(
293297
item,

packages/react-devtools-shared/src/utils.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,19 @@ export function shallowDiffers(prev: Object, next: Object): boolean {
266266
}
267267

268268
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 => {
270270
if (reduced) {
271271
if (hasOwnProperty.call(reduced, attr)) {
272272
return reduced[attr];
273273
}
274274
if (typeof reduced[Symbol.iterator] === 'function') {
275275
// 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];
277282
}
278283
}
279284

0 commit comments

Comments
 (0)