From 196679e6fc5de42a1d8e3ab83e506b54f8f23ae0 Mon Sep 17 00:00:00 2001 From: OJ Kwon <1210596+kwonoj@users.noreply.github.com> Date: Tue, 29 Nov 2022 12:10:23 -0800 Subject: [PATCH] test(snapshot): allow snapshot test not invalidate with --turbo --- .../ReactRefreshLogBox-builtins.test.ts | 68 ++- .../ReactRefreshLogBox-scss.test.ts | 13 +- .../acceptance-app/ReactRefreshLogBox.test.ts | 367 +++++++++++++--- .../ReactRefreshLogBoxMisc.test.ts | 13 +- .../ReactRefreshLogBox-app-doc.test.ts | 48 ++- .../ReactRefreshLogBox-builtins.test.ts | 68 ++- .../ReactRefreshLogBox-scss.test.ts | 13 +- .../acceptance/ReactRefreshLogBox.test.ts | 403 ++++++++++++++---- .../acceptance/ReactRefreshLogBoxMisc.test.ts | 13 +- 9 files changed, 843 insertions(+), 163 deletions(-) diff --git a/test/development/acceptance-app/ReactRefreshLogBox-builtins.test.ts b/test/development/acceptance-app/ReactRefreshLogBox-builtins.test.ts index 26c403611a4e1..bbec78cc95de5 100644 --- a/test/development/acceptance-app/ReactRefreshLogBox-builtins.test.ts +++ b/test/development/acceptance-app/ReactRefreshLogBox-builtins.test.ts @@ -2,6 +2,7 @@ import { sandbox } from './helpers' import { createNext, FileRef } from 'e2e-utils' import { NextInstance } from 'test/lib/next-modes/base' import path from 'path' +import { shouldRunTurboDevTest } from 'next-test-utils' // TODO-APP: Investigate snapshot mismatch describe('ReactRefreshLogBox app', () => { @@ -59,7 +60,20 @@ describe('ReactRefreshLogBox app', () => { ` ) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "./node_modules/my-package/index.js:2:0 + Module not found: Can't resolve 'dns' + + Import trace for requested module: + ./index.js + ./app/page.js + + https://nextjs.org/docs/messages/module-not-found" + `) + } await cleanup() }) @@ -83,7 +97,23 @@ describe('ReactRefreshLogBox app', () => { expect(await session.hasRedbox(true)).toBe(true) const source = await session.getRedboxSource() - expect(source).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(source).toMatchSnapshot() + } else { + expect(source).toMatchInlineSnapshot(` + "./index.js:1:0 + Module not found: Can't resolve 'b' + > 1 | import Comp from 'b' + 2 | export default function Oops() { + 3 | return ( + 4 |
+ + Import trace for requested module: + ./app/page.js + + https://nextjs.org/docs/messages/module-not-found" + `) + } await cleanup() }) @@ -108,7 +138,22 @@ describe('ReactRefreshLogBox app', () => { expect(await session.hasRedbox(true)).toBe(true) const source = await session.getRedboxSource() - expect(source).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(source).toMatchSnapshot() + } else { + expect(source).toMatchInlineSnapshot(` + "./app/page.js:2:6 + Module not found: Can't resolve 'b' + 1 | 'use client' + > 2 | import Comp from 'b' + | ^ + 3 | export default function Oops() { + 4 | return ( + 5 |
+ + https://nextjs.org/docs/messages/module-not-found" + `) + } await cleanup() }) @@ -131,7 +176,22 @@ describe('ReactRefreshLogBox app', () => { expect(await session.hasRedbox(true)).toBe(true) const source = await session.getRedboxSource() - expect(source).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(source).toMatchSnapshot() + } else { + expect(source).toMatchInlineSnapshot(` + "./app/page.js:2:10 + Module not found: Can't resolve './non-existent.css' + 1 | 'use client' + > 2 | import './non-existent.css' + | ^ + 3 | export default function Page(props) { + 4 | return

index page

+ 5 | } + + https://nextjs.org/docs/messages/module-not-found" + `) + } await session.patch( 'app/page.js', diff --git a/test/development/acceptance-app/ReactRefreshLogBox-scss.test.ts b/test/development/acceptance-app/ReactRefreshLogBox-scss.test.ts index 14fdad092b47c..507cd808f358b 100644 --- a/test/development/acceptance-app/ReactRefreshLogBox-scss.test.ts +++ b/test/development/acceptance-app/ReactRefreshLogBox-scss.test.ts @@ -3,6 +3,7 @@ import { sandbox } from './helpers' import { createNext, FileRef } from 'e2e-utils' import { NextInstance } from 'test/lib/next-modes/base' import path from 'path' +import { shouldRunTurboDevTest } from 'next-test-utils' // TODO: figure out why snapshots mismatch on GitHub actions // specifically but work in docker and locally @@ -51,13 +52,21 @@ describe.skip('ReactRefreshLogBox app', () => { await session.patch('index.module.scss', `.button { font-size: :5px; }`) expect(await session.hasRedbox(true)).toBe(true) const source = await session.getRedboxSource() - expect(source).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(source).toMatchSnapshot() + } else { + expect(source).toMatchInlineSnapshot() + } // Not local error await session.patch('index.module.scss', `button { font-size: 5px; }`) expect(await session.hasRedbox(true)).toBe(true) const source2 = await session.getRedboxSource() - expect(source2).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(source2).toMatchSnapshot() + } else { + expect(source2).toMatchInlineSnapshot() + } await cleanup() }) diff --git a/test/development/acceptance-app/ReactRefreshLogBox.test.ts b/test/development/acceptance-app/ReactRefreshLogBox.test.ts index b12561077e0ef..f7bd6e2dd6284 100644 --- a/test/development/acceptance-app/ReactRefreshLogBox.test.ts +++ b/test/development/acceptance-app/ReactRefreshLogBox.test.ts @@ -2,7 +2,7 @@ import { sandbox } from './helpers' import { createNext, FileRef } from 'e2e-utils' import { NextInstance } from 'test/lib/next-modes/base' -import { check } from 'next-test-utils' +import { check, shouldRunTurboDevTest } from 'next-test-utils' import path from 'path' describe('ReactRefreshLogBox app', () => { @@ -50,7 +50,21 @@ describe('ReactRefreshLogBox app', () => { await session.evaluate(() => document.querySelector('a').click()) await session.waitForAndOpenRuntimeError() - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "index.js (9:34) @ onClick + + 7 | + 8 | { + > 9 | throw new Error('idk') + | ^ + 10 | }}> + 11 | click me + 12 | " + `) + } await cleanup() }) @@ -84,7 +98,22 @@ describe('ReactRefreshLogBox app', () => { await session.patch('index.js', `export default () =>
{ expect(await session.hasRedbox(true)).toBe(true) if (process.platform === 'win32') { - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot() + } } else { - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot() + } } await session.patch( @@ -229,7 +266,20 @@ describe('ReactRefreshLogBox app', () => { ) await session.waitForAndOpenRuntimeError() - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "child.js (4:16) @ Child + + 2 | // hello + 3 | export default function Child() { + > 4 | throw new Error('oops') + | ^ + 5 | } + 6 | " + `) + } // TODO-APP: re-enable when error recovery doesn't reload the page. /* const didNotReload = */ await session.patch( @@ -326,7 +376,21 @@ describe('ReactRefreshLogBox app', () => { ` ) await session.waitForAndOpenRuntimeError() - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "index.js (6:18) @ ClassDefault.render + + 4 | class ClassDefault extends React.Component { + 5 | render() { + > 6 | throw new Error('nooo'); + | ^ + 7 | return

Default Export

; + 8 | } + 9 | }" + `) + } await cleanup() }) @@ -372,9 +436,27 @@ describe('ReactRefreshLogBox app', () => { await session.waitForAndOpenRuntimeError() if (process.platform === 'win32') { - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot() + } } else { - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "index.js (4:14) @ eval + + 2 | // top offset for snapshot + 3 | import * as React from 'react'; + > 4 | throw new Error('no') + | ^ + 5 | class ClassDefault extends React.Component { + 6 | render() { + 7 | return

Default Export

;" + `) + } } await cleanup() @@ -424,7 +506,20 @@ describe('ReactRefreshLogBox app', () => { // We get an error because Foo didn't import React. Fair. await session.waitForAndOpenRuntimeError() - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "Foo.js (4:10) @ Foo + + 2 | // intentionally skips export + 3 | export default function Foo() { + > 4 | return React.createElement('h1', null, 'Foo'); + | ^ + 5 | } + 6 | " + `) + } // Let's add that to Foo. await session.patch( @@ -477,9 +572,27 @@ describe('ReactRefreshLogBox app', () => { await new Promise((resolve) => setTimeout(resolve, 1000)) await session.waitForAndOpenRuntimeError() if (process.platform === 'win32') { - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot() + } } else { - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "index.js (6:16) @ Error + + 4 | setInterval(() => { + 5 | i++ + > 6 | throw Error('no ' + i) + | ^ + 7 | }, 1000) + 8 | export default function FunctionNamed() { + 9 | return
" + `) + } } // Make a syntax error. @@ -497,12 +610,46 @@ describe('ReactRefreshLogBox app', () => { await new Promise((resolve) => setTimeout(resolve, 1000)) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "./index.js + Error: + x Expected '}', got '' + ,---- + 8 | export default function FunctionNamed() { + : ^ + \`---- + + Caused by: + 0: failed to process input file + 1: error was recoverable, but proceeding would result in wrong codegen + 2: Syntax Error" + `) + } // Test that runtime error does not take over: await new Promise((resolve) => setTimeout(resolve, 2000)) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "./index.js + Error: + x Expected '}', got '' + ,---- + 8 | export default function FunctionNamed() { + : ^ + \`---- + + Caused by: + 0: failed to process input file + 1: error was recoverable, but proceeding would result in wrong codegen + 2: Syntax Error" + `) + } await cleanup() }) @@ -563,7 +710,16 @@ describe('ReactRefreshLogBox app', () => { ) await session.waitForAndOpenRuntimeError() - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "FunctionDefault.js (1:50) @ FunctionDefault + + > 1 | export default function FunctionDefault() { throw new Error('no'); } + | ^" + `) + } expect( await session.evaluate(() => document.querySelector('h2').textContent) ).toBe('error') @@ -631,7 +787,29 @@ describe('ReactRefreshLogBox app', () => { expect(await session.hasRedbox(true)).toBe(true) const source = await session.getRedboxSource() - expect(source).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(source).toMatchSnapshot() + } else { + expect(source).toMatchInlineSnapshot(` + "./index.js + Error: + x Unexpected token. Did you mean \`{'}'}\` or \`}\`? + ,---- + 8 | } + : ^ + \`---- + + x Unexpected eof + ,---- + 9 | + : ^ + \`---- + + Caused by: + 0: failed to process input file + 1: Syntax Error" + `) + } await cleanup() }) @@ -682,7 +860,21 @@ describe('ReactRefreshLogBox app', () => { ) await session.waitForAndOpenRuntimeError() - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "Child.js (5:18) @ ClickCount.render + + 3 | export default class ClickCount extends Component { + 4 | render() { + > 5 | throw new Error() + | ^ + 6 | } + 7 | } + 8 | " + `) + } await session.patch( 'Child.js', @@ -738,7 +930,17 @@ describe('ReactRefreshLogBox app', () => { await session.patch('index.module.css', `button {}`) expect(await session.hasRedbox(true)).toBe(true) const source2 = await session.getRedboxSource() - expect(source2).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(source2).toMatchSnapshot() + } else { + expect(source2).toMatchInlineSnapshot(` + "./index.module.css:1:1 + Syntax error: Selector \\"button\\" is not pure (pure selectors must contain at least one local class or id) + + > 1 | button {} + | ^" + `) + } await cleanup() }) @@ -769,7 +971,11 @@ describe('ReactRefreshLogBox app', () => { await session.waitForAndOpenRuntimeError() const header = await session.getRedboxDescription() - expect(header).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(header).toMatchSnapshot() + } else { + expect(header).toMatchInlineSnapshot(`"Error: end http://nextjs.org"`) + } expect( await session.evaluate( () => @@ -779,18 +985,23 @@ describe('ReactRefreshLogBox app', () => { .length ) ).toBe(1) - expect( - await session.evaluate( - () => - ( - document - .querySelector('body > nextjs-portal') - .shadowRoot.querySelector( - '#nextjs__container_errors_desc a:nth-of-type(1)' - ) as any - ).href + const nextJsPortalContainerErrorsValue = await session.evaluate( + () => + ( + document + .querySelector('body > nextjs-portal') + .shadowRoot.querySelector( + '#nextjs__container_errors_desc a:nth-of-type(1)' + ) as any + ).href + ) + if (!shouldRunTurboDevTest()) { + expect(nextJsPortalContainerErrorsValue).toMatchSnapshot() + } else { + expect(nextJsPortalContainerErrorsValue).toMatchInlineSnapshot( + `"http://nextjs.org/"` ) - ).toMatchSnapshot() + } await session.patch( 'index.js', @@ -815,7 +1026,12 @@ describe('ReactRefreshLogBox app', () => { await session.waitForAndOpenRuntimeError() const header2 = await session.getRedboxDescription() - expect(header2).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(header2).toMatchSnapshot() + } else { + expect(header2).toMatchInlineSnapshot(`"Error: http://nextjs.org start"`) + } + expect( await session.evaluate( () => @@ -861,7 +1077,14 @@ describe('ReactRefreshLogBox app', () => { await session.waitForAndOpenRuntimeError() const header3 = await session.getRedboxDescription() - expect(header3).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(header3).toMatchSnapshot() + } else { + expect(header3).toMatchInlineSnapshot( + `"Error: middle http://nextjs.org end"` + ) + } + expect( await session.evaluate( () => @@ -871,18 +1094,24 @@ describe('ReactRefreshLogBox app', () => { .length ) ).toBe(1) - expect( - await session.evaluate( - () => - ( - document - .querySelector('body > nextjs-portal') - .shadowRoot.querySelector( - '#nextjs__container_errors_desc a:nth-of-type(1)' - ) as any - ).href + const nextJsPortalContainerErrorsValue2 = await session.evaluate( + () => + ( + document + .querySelector('body > nextjs-portal') + .shadowRoot.querySelector( + '#nextjs__container_errors_desc a:nth-of-type(1)' + ) as any + ).href + ) + + if (!shouldRunTurboDevTest()) { + expect(nextJsPortalContainerErrorsValue2).toMatchSnapshot() + } else { + expect(nextJsPortalContainerErrorsValue2).toMatchInlineSnapshot( + `"http://nextjs.org/"` ) - ).toMatchSnapshot() + } await session.patch( 'index.js', @@ -919,30 +1148,38 @@ describe('ReactRefreshLogBox app', () => { .length ) ).toBe(2) - expect( - await session.evaluate( - () => - ( - document - .querySelector('body > nextjs-portal') - .shadowRoot.querySelector( - '#nextjs__container_errors_desc a:nth-of-type(1)' - ) as any - ).href + const nextJsPortalContainerErrorsValue3 = await session.evaluate( + () => + ( + document + .querySelector('body > nextjs-portal') + .shadowRoot.querySelector( + '#nextjs__container_errors_desc a:nth-of-type(1)' + ) as any + ).href + ) + const nextJsPortalContainerErrorsValue4 = await session.evaluate( + () => + ( + document + .querySelector('body > nextjs-portal') + .shadowRoot.querySelector( + '#nextjs__container_errors_desc a:nth-of-type(2)' + ) as any + ).href + ) + + if (!shouldRunTurboDevTest()) { + expect(nextJsPortalContainerErrorsValue3).toMatchSnapshot() + expect(nextJsPortalContainerErrorsValue4).toMatchSnapshot() + } else { + expect(nextJsPortalContainerErrorsValue3).toMatchInlineSnapshot( + `"http://nextjs.org/"` ) - ).toMatchSnapshot() - expect( - await session.evaluate( - () => - ( - document - .querySelector('body > nextjs-portal') - .shadowRoot.querySelector( - '#nextjs__container_errors_desc a:nth-of-type(2)' - ) as any - ).href + expect(nextJsPortalContainerErrorsValue4).toMatchInlineSnapshot( + `"http://example.com/"` ) - ).toMatchSnapshot() + } await cleanup() }) diff --git a/test/development/acceptance-app/ReactRefreshLogBoxMisc.test.ts b/test/development/acceptance-app/ReactRefreshLogBoxMisc.test.ts index f4d6e512c322c..bdc73a48fe0f8 100644 --- a/test/development/acceptance-app/ReactRefreshLogBoxMisc.test.ts +++ b/test/development/acceptance-app/ReactRefreshLogBoxMisc.test.ts @@ -2,6 +2,7 @@ import { sandbox } from './helpers' import { createNext, FileRef } from 'e2e-utils' import { NextInstance } from 'test/lib/next-modes/base' import path from 'path' +import { shouldRunTurboDevTest } from 'next-test-utils' // TODO: re-enable these tests after figuring out what is causing // them to be so unreliable in CI @@ -190,7 +191,11 @@ describe.skip('ReactRefreshLogBox app', () => { ` ) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxDescription()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxDescription()).toMatchSnapshot() + } else { + expect(await session.getRedboxDescription()).toMatchInlineSnapshot() + } await session.patch( 'index.js', @@ -215,7 +220,11 @@ describe.skip('ReactRefreshLogBox app', () => { ` ) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxDescription()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxDescription()).toMatchSnapshot() + } else { + expect(await session.getRedboxDescription()).toMatchInlineSnapshot() + } await cleanup() }) diff --git a/test/development/acceptance/ReactRefreshLogBox-app-doc.test.ts b/test/development/acceptance/ReactRefreshLogBox-app-doc.test.ts index 755ecdb416d2f..426e300a946fe 100644 --- a/test/development/acceptance/ReactRefreshLogBox-app-doc.test.ts +++ b/test/development/acceptance/ReactRefreshLogBox-app-doc.test.ts @@ -1,6 +1,7 @@ import { sandbox } from './helpers' import { createNext } from 'e2e-utils' import { NextInstance } from 'test/lib/next-modes/base' +import { shouldRunTurboDevTest } from 'next-test-utils' describe('ReactRefreshLogBox', () => { let next: NextInstance @@ -20,7 +21,7 @@ describe('ReactRefreshLogBox', () => { [ 'pages/_app.js', ` - + `, ], ]) @@ -50,7 +51,7 @@ describe('ReactRefreshLogBox', () => { [ 'pages/_document.js', ` - + `, ], ]) @@ -107,7 +108,30 @@ describe('ReactRefreshLogBox', () => { ]) ) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "./pages/_app.js + Error: + x Expression expected + ,---- + 3 | return <; + : ^ + \`---- + + x Unexpected token \`jsx name (Component)\`. Expected this, import, async, function, [ for array literal, { for object literal, @ for decorator, function, class, null, true, false, number, bigint, + | string, regexp, \` for template literal, (, or an identifier + ,---- + 3 | return <; + : ^^^^^^^^^ + \`---- + + Caused by: + 0: failed to process input file + 1: Syntax Error" + `) + } await session.patch( 'pages/_app.js', @@ -156,7 +180,23 @@ describe('ReactRefreshLogBox', () => { ]) ) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "./pages/_document.js + Error: + x Unexpected token \`{\`. Expected identifier, string literal, numeric literal or [ for the computed key + ,---- + 4 | class MyDocument extends Document {{ + : ^ + \`---- + + Caused by: + 0: failed to process input file + 1: Syntax Error" + `) + } await session.patch( 'pages/_document.js', diff --git a/test/development/acceptance/ReactRefreshLogBox-builtins.test.ts b/test/development/acceptance/ReactRefreshLogBox-builtins.test.ts index 87a2439ea3add..1aa1d9563262c 100644 --- a/test/development/acceptance/ReactRefreshLogBox-builtins.test.ts +++ b/test/development/acceptance/ReactRefreshLogBox-builtins.test.ts @@ -1,6 +1,7 @@ import { sandbox } from './helpers' import { createNext } from 'e2e-utils' import { NextInstance } from 'test/lib/next-modes/base' +import { shouldRunTurboDevTest } from 'next-test-utils' describe('ReactRefreshLogBox', () => { let next: NextInstance @@ -48,7 +49,20 @@ describe('ReactRefreshLogBox', () => { ` ) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "./node_modules/my-package/index.js:2:0 + Module not found: Can't resolve 'dns' + + Import trace for requested module: + ./index.js + ./pages/index.js + + https://nextjs.org/docs/messages/module-not-found" + `) + } await cleanup() }) @@ -72,7 +86,23 @@ describe('ReactRefreshLogBox', () => { expect(await session.hasRedbox(true)).toBe(true) const source = await session.getRedboxSource() - expect(source).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(source).toMatchSnapshot() + } else { + expect(source).toMatchInlineSnapshot(` + "./index.js:1:0 + Module not found: Can't resolve 'b' + > 1 | import Comp from 'b' + 2 | export default function Oops() { + 3 | return ( + 4 |
+ + Import trace for requested module: + ./pages/index.js + + https://nextjs.org/docs/messages/module-not-found" + `) + } await cleanup() }) @@ -96,7 +126,20 @@ describe('ReactRefreshLogBox', () => { expect(await session.hasRedbox(true)).toBe(true) const source = await session.getRedboxSource() - expect(source).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(source).toMatchSnapshot() + } else { + expect(source).toMatchInlineSnapshot(` + "./pages/index.js:1:0 + Module not found: Can't resolve 'b' + > 1 | import Comp from 'b' + 2 | export default function Oops() { + 3 | return ( + 4 |
+ + https://nextjs.org/docs/messages/module-not-found" + `) + } await cleanup() }) @@ -109,7 +152,7 @@ describe('ReactRefreshLogBox', () => { 'pages/_app.js', ` import './non-existent.css' - + export default function App({ Component, pageProps }) { return } @@ -128,7 +171,22 @@ describe('ReactRefreshLogBox', () => { expect(await session.hasRedbox(true)).toBe(true) const source = await session.getRedboxSource() - expect(source).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(source).toMatchSnapshot() + } else { + expect(source).toMatchInlineSnapshot(` + "./pages/_app.js:2:8 + Module not found: Can't resolve './non-existent.css' + 1 | + > 2 | import './non-existent.css' + | ^ + 3 | + 4 | export default function App({ Component, pageProps }) { + 5 | return + + https://nextjs.org/docs/messages/module-not-found" + `) + } await session.patch( 'pages/_app.js', diff --git a/test/development/acceptance/ReactRefreshLogBox-scss.test.ts b/test/development/acceptance/ReactRefreshLogBox-scss.test.ts index 93fcaf5cba6d1..91fad5b7d9211 100644 --- a/test/development/acceptance/ReactRefreshLogBox-scss.test.ts +++ b/test/development/acceptance/ReactRefreshLogBox-scss.test.ts @@ -2,6 +2,7 @@ import { sandbox } from './helpers' import { createNext } from 'e2e-utils' import { NextInstance } from 'test/lib/next-modes/base' +import { shouldRunTurboDevTest } from 'next-test-utils' // TODO: figure out why snapshots mismatch on GitHub actions // specifically but work in docker and locally @@ -43,13 +44,21 @@ describe.skip('ReactRefreshLogBox', () => { await session.patch('index.module.scss', `.button { font-size: :5px; }`) expect(await session.hasRedbox(true)).toBe(true) const source = await session.getRedboxSource() - expect(source).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(source).toMatchSnapshot() + } else { + expect(source).toMatchInlineSnapshot() + } // Not local error await session.patch('index.module.scss', `button { font-size: 5px; }`) expect(await session.hasRedbox(true)).toBe(true) const source2 = await session.getRedboxSource() - expect(source2).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(source2).toMatchSnapshot() + } else { + expect(source2).toMatchInlineSnapshot() + } await cleanup() }) diff --git a/test/development/acceptance/ReactRefreshLogBox.test.ts b/test/development/acceptance/ReactRefreshLogBox.test.ts index d9aced58dba6f..c6704bbbd38ad 100644 --- a/test/development/acceptance/ReactRefreshLogBox.test.ts +++ b/test/development/acceptance/ReactRefreshLogBox.test.ts @@ -2,7 +2,7 @@ import { sandbox } from './helpers' import { createNext } from 'e2e-utils' import { NextInstance } from 'test/lib/next-modes/base' -import { check } from 'next-test-utils' +import { check, shouldRunTurboDevTest } from 'next-test-utils' describe('ReactRefreshLogBox', () => { let next: NextInstance @@ -24,7 +24,7 @@ describe('ReactRefreshLogBox', () => { export default function Page() { return ( <> - +

index page

{ @@ -40,7 +40,21 @@ describe('ReactRefreshLogBox', () => { await session.evaluate(() => document.querySelector('a').click()) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "index.js (9:34) @ onClick + + 7 | + 8 | { + > 9 | throw new Error('idk') + | ^ + 10 | }}> + 11 | click me + 12 | " + `) + } await cleanup() }) @@ -74,7 +88,22 @@ describe('ReactRefreshLogBox', () => { await session.patch('index.js', `export default () =>
{ expect(await session.hasRedbox(true)).toBe(true) if (process.platform === 'win32') { - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot() + } } else { - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "index.js (8:18) @ eval + + 6 | const increment = useCallback(() => { + 7 | setCount(c => c + 1) + > 8 | throw new Error('oops') + | ^ + 9 | }, [setCount]) + 10 | return ( + 11 |
" + `) + } } await session.patch( @@ -218,7 +265,20 @@ describe('ReactRefreshLogBox', () => { ) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "child.js (4:16) @ Child + + 2 | // hello + 3 | export default function Child() { + > 4 | throw new Error('oops') + | ^ + 5 | } + 6 | " + `) + } const didNotReload = await session.patch( 'child.js', @@ -313,7 +373,21 @@ describe('ReactRefreshLogBox', () => { ` ) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "index.js (6:18) @ ClassDefault.render + + 4 | class ClassDefault extends React.Component { + 5 | render() { + > 6 | throw new Error('nooo'); + | ^ + 7 | return

Default Export

; + 8 | } + 9 | }" + `) + } await cleanup() }) @@ -358,7 +432,21 @@ describe('ReactRefreshLogBox', () => { ) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "index.js (4:14) @ eval + + 2 | // top offset for snapshot + 3 | import * as React from 'react'; + > 4 | throw new Error('no') + | ^ + 5 | class ClassDefault extends React.Component { + 6 | render() { + 7 | return

Default Export

;" + `) + } await cleanup() }) @@ -407,7 +495,20 @@ describe('ReactRefreshLogBox', () => { // We get an error because Foo didn't import React. Fair. expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "Foo.js (4:10) @ Foo + + 2 | // intentionally skips export + 3 | export default function Foo() { + > 4 | return React.createElement('h1', null, 'Foo'); + | ^ + 5 | } + 6 | " + `) + } // Let's add that to Foo. await session.patch( @@ -460,9 +561,27 @@ describe('ReactRefreshLogBox', () => { await new Promise((resolve) => setTimeout(resolve, 1000)) expect(await session.hasRedbox(true)).toBe(true) if (process.platform === 'win32') { - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot() + } } else { - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "index.js (6:16) @ Error + + 4 | setInterval(() => { + 5 | i++ + > 6 | throw Error('no ' + i) + | ^ + 7 | }, 1000) + 8 | export default function FunctionNamed() { + 9 | return
" + `) + } } // Make a syntax error. @@ -480,12 +599,46 @@ describe('ReactRefreshLogBox', () => { await new Promise((resolve) => setTimeout(resolve, 1000)) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "./index.js + Error: + x Expected '}', got '' + ,---- + 8 | export default function FunctionNamed() { + : ^ + \`---- + + Caused by: + 0: failed to process input file + 1: error was recoverable, but proceeding would result in wrong codegen + 2: Syntax Error" + `) + } // Test that runtime error does not take over: await new Promise((resolve) => setTimeout(resolve, 2000)) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "./index.js + Error: + x Expected '}', got '' + ,---- + 8 | export default function FunctionNamed() { + : ^ + \`---- + + Caused by: + 0: failed to process input file + 1: error was recoverable, but proceeding would result in wrong codegen + 2: Syntax Error" + `) + } await cleanup() }) @@ -546,7 +699,16 @@ describe('ReactRefreshLogBox', () => { ) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "FunctionDefault.js (1:50) @ FunctionDefault + + > 1 | export default function FunctionDefault() { throw new Error('no'); } + | ^" + `) + } expect( await session.evaluate(() => document.querySelector('h2').textContent) ).toBe('error') @@ -614,7 +776,29 @@ describe('ReactRefreshLogBox', () => { expect(await session.hasRedbox(true)).toBe(true) const source = await session.getRedboxSource() - expect(source).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(source).toMatchSnapshot() + } else { + expect(source).toMatchInlineSnapshot(` + "./index.js + Error: + x Unexpected token. Did you mean \`{'}'}\` or \`}\`? + ,---- + 8 | } + : ^ + \`---- + + x Unexpected eof + ,---- + 9 | + : ^ + \`---- + + Caused by: + 0: failed to process input file + 1: Syntax Error" + `) + } await cleanup() }) @@ -665,7 +849,21 @@ describe('ReactRefreshLogBox', () => { ) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxSource()).toMatchSnapshot() + } else { + expect(await session.getRedboxSource()).toMatchInlineSnapshot(` + "Child.js (5:18) @ ClickCount.render + + 3 | export default class ClickCount extends Component { + 4 | render() { + > 5 | throw new Error() + | ^ + 6 | } + 7 | } + 8 | " + `) + } await session.patch( 'Child.js', @@ -721,7 +919,17 @@ describe('ReactRefreshLogBox', () => { await session.patch('index.module.css', `button {}`) expect(await session.hasRedbox(true)).toBe(true) const source2 = await session.getRedboxSource() - expect(source2).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(source2).toMatchSnapshot() + } else { + expect(source2).toMatchInlineSnapshot(` + "./index.module.css:1:1 + Syntax error: Selector \\"button\\" is not pure (pure selectors must contain at least one local class or id) + + > 1 | button {} + | ^" + `) + } await cleanup() }) @@ -752,7 +960,11 @@ describe('ReactRefreshLogBox', () => { expect(await session.hasRedbox(true)).toBe(true) const header = await session.getRedboxDescription() - expect(header).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(header).toMatchSnapshot() + } else { + expect(header).toMatchInlineSnapshot(`"Error: end http://nextjs.org"`) + } expect( await session.evaluate( () => @@ -762,18 +974,24 @@ describe('ReactRefreshLogBox', () => { .length ) ).toBe(1) - expect( - await session.evaluate( - () => - ( - document - .querySelector('body > nextjs-portal') - .shadowRoot.querySelector( - '#nextjs__container_errors_desc a:nth-of-type(1)' - ) as any - ).href + const nextJsPortalErrorValue = await session.evaluate( + () => + ( + document + .querySelector('body > nextjs-portal') + .shadowRoot.querySelector( + '#nextjs__container_errors_desc a:nth-of-type(1)' + ) as any + ).href + ) + + if (!shouldRunTurboDevTest()) { + expect(nextJsPortalErrorValue).toMatchSnapshot() + } else { + expect(nextJsPortalErrorValue).toMatchInlineSnapshot( + `"http://nextjs.org/"` ) - ).toMatchSnapshot() + } await session.patch( 'index.js', @@ -798,7 +1016,11 @@ describe('ReactRefreshLogBox', () => { expect(await session.hasRedbox(true)).toBe(true) const header2 = await session.getRedboxDescription() - expect(header2).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(header2).toMatchSnapshot() + } else { + expect(header2).toMatchInlineSnapshot(`"Error: http://nextjs.org start"`) + } expect( await session.evaluate( () => @@ -808,18 +1030,24 @@ describe('ReactRefreshLogBox', () => { .length ) ).toBe(1) - expect( - await session.evaluate( - () => - ( - document - .querySelector('body > nextjs-portal') - .shadowRoot.querySelector( - '#nextjs__container_errors_desc a:nth-of-type(1)' - ) as any - ).href + const nextJsPortalContainerErrorsValue = await session.evaluate( + () => + ( + document + .querySelector('body > nextjs-portal') + .shadowRoot.querySelector( + '#nextjs__container_errors_desc a:nth-of-type(1)' + ) as any + ).href + ) + + if (!shouldRunTurboDevTest()) { + expect(nextJsPortalContainerErrorsValue).toMatchSnapshot() + } else { + expect(nextJsPortalContainerErrorsValue).toMatchInlineSnapshot( + `"http://nextjs.org/"` ) - ).toMatchSnapshot() + } await session.patch( 'index.js', @@ -844,7 +1072,13 @@ describe('ReactRefreshLogBox', () => { expect(await session.hasRedbox(true)).toBe(true) const header3 = await session.getRedboxDescription() - expect(header3).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(header3).toMatchSnapshot() + } else { + expect(header3).toMatchInlineSnapshot( + `"Error: middle http://nextjs.org end"` + ) + } expect( await session.evaluate( () => @@ -854,18 +1088,24 @@ describe('ReactRefreshLogBox', () => { .length ) ).toBe(1) - expect( - await session.evaluate( - () => - ( - document - .querySelector('body > nextjs-portal') - .shadowRoot.querySelector( - '#nextjs__container_errors_desc a:nth-of-type(1)' - ) as any - ).href + const nextJsPortalContainerErrorsValue2 = await session.evaluate( + () => + ( + document + .querySelector('body > nextjs-portal') + .shadowRoot.querySelector( + '#nextjs__container_errors_desc a:nth-of-type(1)' + ) as any + ).href + ) + + if (!shouldRunTurboDevTest()) { + expect(nextJsPortalContainerErrorsValue2).toMatchSnapshot() + } else { + expect(nextJsPortalContainerErrorsValue2).toMatchInlineSnapshot( + `"http://nextjs.org/"` ) - ).toMatchSnapshot() + } await session.patch( 'index.js', @@ -902,30 +1142,39 @@ describe('ReactRefreshLogBox', () => { .length ) ).toBe(2) - expect( - await session.evaluate( - () => - ( - document - .querySelector('body > nextjs-portal') - .shadowRoot.querySelector( - '#nextjs__container_errors_desc a:nth-of-type(1)' - ) as any - ).href + + const nextJsPortalContainerErrorsValue3 = await session.evaluate( + () => + ( + document + .querySelector('body > nextjs-portal') + .shadowRoot.querySelector( + '#nextjs__container_errors_desc a:nth-of-type(1)' + ) as any + ).href + ) + const nextJsPortalContainerErrorsValue4 = await session.evaluate( + () => + ( + document + .querySelector('body > nextjs-portal') + .shadowRoot.querySelector( + '#nextjs__container_errors_desc a:nth-of-type(2)' + ) as any + ).href + ) + + if (!shouldRunTurboDevTest()) { + expect(nextJsPortalContainerErrorsValue3).toMatchSnapshot() + expect(nextJsPortalContainerErrorsValue4).toMatchSnapshot() + } else { + expect(nextJsPortalContainerErrorsValue3).toMatchInlineSnapshot( + `"http://nextjs.org/"` ) - ).toMatchSnapshot() - expect( - await session.evaluate( - () => - ( - document - .querySelector('body > nextjs-portal') - .shadowRoot.querySelector( - '#nextjs__container_errors_desc a:nth-of-type(2)' - ) as any - ).href + expect(nextJsPortalContainerErrorsValue4).toMatchInlineSnapshot( + `"http://example.com/"` ) - ).toMatchSnapshot() + } await cleanup() }) @@ -966,7 +1215,7 @@ describe('ReactRefreshLogBox', () => { 'index.js', ` class Hello {} - + export default () => { throw Hello return ( diff --git a/test/development/acceptance/ReactRefreshLogBoxMisc.test.ts b/test/development/acceptance/ReactRefreshLogBoxMisc.test.ts index 738e7a5f79b92..81f998b0740f2 100644 --- a/test/development/acceptance/ReactRefreshLogBoxMisc.test.ts +++ b/test/development/acceptance/ReactRefreshLogBoxMisc.test.ts @@ -1,6 +1,7 @@ import { sandbox } from './helpers' import { createNext } from 'e2e-utils' import { NextInstance } from 'test/lib/next-modes/base' +import { shouldRunTurboDevTest } from 'next-test-utils' // TODO: re-enable these tests after figuring out what is causing // them to be so unreliable in CI @@ -180,7 +181,11 @@ describe.skip('ReactRefreshLogBox', () => { ` ) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxDescription()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxDescription()).toMatchSnapshot() + } else { + expect(await session.getRedboxDescription()).toMatchInlineSnapshot() + } await session.patch( 'index.js', @@ -205,7 +210,11 @@ describe.skip('ReactRefreshLogBox', () => { ` ) expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxDescription()).toMatchSnapshot() + if (!shouldRunTurboDevTest()) { + expect(await session.getRedboxDescription()).toMatchSnapshot() + } else { + expect(await session.getRedboxDescription()).toMatchInlineSnapshot() + } await cleanup() })