From d89657bc8f60e9d00e3f73d5bda262fdcb651cdc Mon Sep 17 00:00:00 2001 From: Luna Ruan Date: Thu, 19 May 2022 07:52:30 -0700 Subject: [PATCH] [DevTools] Use Inline Snapshots for storeStressTestSync (#24583) Change storeStressTestSync to use inline snapshots instead of a snapshot file. We want to do this because some tests are gated and not called in regression tests, and if snapshot tests are not called when there is a corresponding .snap file, that test will fail. Arguably inline snapshots are a better pattern anyway, so enforcing this in DevTools tests IMO makes sense --- .../storeStressSync-test.js.snap | 493 ------------------ .../src/__tests__/storeStressSync-test.js | 460 +++++++++++++++- 2 files changed, 454 insertions(+), 499 deletions(-) delete mode 100644 packages/react-devtools-shared/src/__tests__/__snapshots__/storeStressSync-test.js.snap diff --git a/packages/react-devtools-shared/src/__tests__/__snapshots__/storeStressSync-test.js.snap b/packages/react-devtools-shared/src/__tests__/__snapshots__/storeStressSync-test.js.snap deleted file mode 100644 index 76ce00a109..0000000000 --- a/packages/react-devtools-shared/src/__tests__/__snapshots__/storeStressSync-test.js.snap +++ /dev/null @@ -1,493 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense (Legacy Mode) 1`] = ` -[root] - ▾ - - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense (Legacy Mode) 2`] = ` -[root] - ▾ - - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense (Legacy Mode) 3`] = ` -[root] - ▾ - - ▾ - - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense (Legacy Mode) 4`] = ` -[root] - ▾ - - ▾ - - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense (Legacy Mode) 5`] = ` -[root] - ▾ - - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense (Legacy Mode) 6`] = ` -[root] - ▾ - - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense (Legacy Mode) 7`] = ` -[root] - ▾ - - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense (Legacy Mode) 8`] = ` -[root] - ▾ - - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense (Legacy Mode) 9`] = ` -[root] - ▾ - - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense (Legacy Mode) 10`] = ` -[root] - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense (Legacy Mode) 11`] = ` -[root] - ▾ - - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense (Legacy Mode) 12`] = ` -[root] - ▾ - - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 1`] = ` -[root] - ▾ - - ▾ - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 2`] = ` -[root] - ▾ - - ▾ - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 3`] = ` -[root] - ▾ - - ▾ - ▾ - - - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 4`] = ` -[root] - ▾ - - ▾ - ▾ - - - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 5`] = ` -[root] - ▾ - - ▾ - ▾ - - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 6`] = ` -[root] - ▾ - - ▾ - ▾ - - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 7`] = ` -[root] - ▾ - - ▾ - ▾ - - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 8`] = ` -[root] - ▾ - - ▾ - ▾ - - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 9`] = ` -[root] - ▾ - - ▾ - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 10`] = ` -[root] - ▾ - - ▾ - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 11`] = ` -[root] - ▾ - - ▾ - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 12`] = ` -[root] - ▾ - - ▾ - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 13`] = ` -[root] - ▾ - - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 14`] = ` -[root] - ▾ - - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 15`] = ` -[root] - ▾ - - ▾ - - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 16`] = ` -[root] - ▾ - - ▾ - - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 17`] = ` -[root] - ▾ - - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 18`] = ` -[root] - ▾ - - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 19`] = ` -[root] - ▾ - - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 20`] = ` -[root] - ▾ - - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 21`] = ` -[root] - ▾ - - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 22`] = ` -[root] - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 23`] = ` -[root] - ▾ - - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test for Suspense without type change (Legacy Mode) 24`] = ` -[root] - ▾ - - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test with different tree operations (Legacy Mode): 1: abcde 1`] = ` -[root] - ▾ - - - - - -`; - -exports[`StoreStress (Legacy Mode) should handle a stress test with different tree operations (Legacy Mode): 2: abxde 1`] = ` -[root] - ▾ - - - ▾ - - - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 1`] = ` -[root] - ▾ - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 2`] = ` -[root] - ▾ - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 3`] = ` -[root] - ▾ - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 4`] = ` -[root] - ▾ - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 5`] = ` -[root] - ▾ - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 6`] = ` -[root] - ▾ - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 7`] = ` -[root] - ▾ - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 8`] = ` -[root] - ▾ - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 9`] = ` -[root] - ▾ - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 10`] = ` -[root] - ▾ - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 11`] = ` -[root] - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 12`] = ` -[root] - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 13`] = ` -[root] - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 14`] = ` -[root] - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 15`] = ` -[root] - ▾ - - -`; - -exports[`StoreStress (Legacy Mode) should handle stress test with reordering (Legacy Mode) 16`] = ` -[root] - ▾ - - -`; diff --git a/packages/react-devtools-shared/src/__tests__/storeStressSync-test.js b/packages/react-devtools-shared/src/__tests__/storeStressSync-test.js index 7e85a34bc0..6c7f6a9381 100644 --- a/packages/react-devtools-shared/src/__tests__/storeStressSync-test.js +++ b/packages/react-devtools-shared/src/__tests__/storeStressSync-test.js @@ -62,7 +62,15 @@ describe('StoreStress (Legacy Mode)', () => { // 1. Render a normal version of [a, b, c, d, e]. let container = document.createElement('div'); act(() => legacyRender({[a, b, c, d, e]}, container)); - expect(store).toMatchSnapshot('1: abcde'); + expect(store).toMatchInlineSnapshot(` + [root] + ▾ + + + + + + `); expect(container.textContent).toMatch('abcde'); const snapshotForABCDE = print(store); @@ -71,7 +79,16 @@ describe('StoreStress (Legacy Mode)', () => { act(() => { setShowX(true); }); - expect(store).toMatchSnapshot('2: abxde'); + expect(store).toMatchInlineSnapshot(` + [root] + ▾ + + + ▾ + + + + `); expect(container.textContent).toMatch('abxde'); const snapshotForABXDE = print(store); @@ -208,6 +225,95 @@ describe('StoreStress (Legacy Mode)', () => { [c, a], ]; + const stepsSnapshot = [ + ` + [root] + ▾ + + `, + ` + [root] + ▾ + + `, + ` + [root] + ▾ + + `, + ` + [root] + ▾ + + `, + ` + [root] + ▾ + + `, + ` + [root] + ▾ + + `, + ` + [root] + ▾ + + `, + ` + [root] + ▾ + + `, + ` + [root] + ▾ + + `, + ` + [root] + ▾ + + `, + ` + [root] + ▾ + + + `, + ` + [root] + ▾ + + + `, + ` + [root] + ▾ + + + `, + ` + [root] + ▾ + + + `, + ` + [root] + ▾ + + + `, + ` + [root] + ▾ + + + `, + ]; + const Root = ({children}) => { return children; }; @@ -218,7 +324,7 @@ describe('StoreStress (Legacy Mode)', () => { for (let i = 0; i < steps.length; i++) { act(() => legacyRender({steps[i]}, container)); // We snapshot each step once so it doesn't regress. - expect(store).toMatchSnapshot(); + expect(store).toMatchInlineSnapshot(stepsSnapshot[i]); snapshots.push(print(store)); act(() => ReactDOM.unmountComponentAtNode(container)); expect(print(store)).toBe(''); @@ -305,6 +411,112 @@ describe('StoreStress (Legacy Mode)', () => { a, ]; + const stepsSnapshot = [ + ` + [root] + ▾ + + ▾ + + + `, + ` + [root] + ▾ + + ▾ + + + `, + ` + [root] + ▾ + + ▾ + + + + + `, + ` + [root] + ▾ + + ▾ + + + + + `, + ` + [root] + ▾ + + ▾ + + + + `, + ` + [root] + ▾ + + ▾ + + + + `, + ` + [root] + ▾ + + ▾ + + + + `, + ` + [root] + ▾ + + ▾ + + + + `, + ` + [root] + ▾ + + ▾ + + + `, + ` + [root] + ▾ + + + + `, + ` + [root] + ▾ + + ▾ + + + `, + ` + [root] + ▾ + + ▾ + + + `, + ]; + const Never = () => { throw new Promise(() => {}); }; @@ -329,7 +541,7 @@ describe('StoreStress (Legacy Mode)', () => { ), ); // We snapshot each step once so it doesn't regress. - expect(store).toMatchSnapshot(); + expect(store).toMatchInlineSnapshot(stepsSnapshot[i]); snapshots.push(print(store)); act(() => ReactDOM.unmountComponentAtNode(container)); expect(print(store)).toBe(''); @@ -699,6 +911,242 @@ describe('StoreStress (Legacy Mode)', () => { a, ]; + const stepsSnapshot = [ + ` + [root] + ▾ + + ▾ + ▾ + + + + `, + ` + [root] + ▾ + + ▾ + ▾ + + + + `, + ` + [root] + ▾ + + ▾ + ▾ + + + + + + `, + ` + [root] + ▾ + + ▾ + ▾ + + + + + + `, + ` + [root] + ▾ + + ▾ + ▾ + + + + + `, + ` + [root] + ▾ + + ▾ + ▾ + + + + + `, + ` + [root] + ▾ + + ▾ + ▾ + + + + + `, + ` + [root] + ▾ + + ▾ + ▾ + + + + + `, + ` + [root] + ▾ + + ▾ + ▾ + + + + `, + ` + [root] + ▾ + + ▾ + ▾ + + + `, + ` + [root] + ▾ + + ▾ + ▾ + + + + `, + ` + [root] + ▾ + + ▾ + ▾ + + + + `, + ]; + + const stepsSnapshotTwo = [ + ` + [root] + ▾ + + ▾ + + + `, + ` + [root] + ▾ + + ▾ + + + `, + ` + [root] + ▾ + + ▾ + + + + + `, + ` + [root] + ▾ + + ▾ + + + + + `, + ` + [root] + ▾ + + ▾ + + + + `, + ` + [root] + ▾ + + ▾ + + + + `, + ` + [root] + ▾ + + ▾ + + + + `, + ` + [root] + ▾ + + ▾ + + + + `, + ` + [root] + ▾ + + ▾ + + + `, + ` + [root] + ▾ + + + + `, + ` + [root] + ▾ + + ▾ + + + `, + ` + [root] + ▾ + + ▾ + + + `, + ]; + const Never = () => { throw new Promise(() => {}); }; @@ -743,7 +1191,7 @@ describe('StoreStress (Legacy Mode)', () => { ), ); // We snapshot each step once so it doesn't regress. - expect(store).toMatchSnapshot(); + expect(store).toMatchInlineSnapshot(stepsSnapshot[i]); snapshots.push(print(store)); act(() => ReactDOM.unmountComponentAtNode(container)); expect(print(store)).toBe(''); @@ -769,7 +1217,7 @@ describe('StoreStress (Legacy Mode)', () => { ), ); // We snapshot each step once so it doesn't regress. - expect(store).toMatchSnapshot(); + expect(store).toMatchInlineSnapshot(stepsSnapshotTwo[i]); fallbackSnapshots.push(print(store)); act(() => ReactDOM.unmountComponentAtNode(container)); expect(print(store)).toBe('');