Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turbopack test updates #60662

Merged
merged 17 commits into from
Jan 15, 2024
104 changes: 65 additions & 39 deletions test/development/acceptance-app/ReactRefreshLogBox-builtins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,28 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)
expect(await session.hasRedbox()).toBe(true)
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./node_modules/my-package/index.js:1:12
Module not found: Can't resolve 'dns'
if (process.env.TURBOPACK) {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./node_modules/my-package/index.js:1:12
Module not found: Can't resolve 'dns'
> 1 | const dns = require('dns')
| ^^^^^^^^^^^^^^
2 | module.exports = dns

https://nextjs.org/docs/messages/module-not-found"
`)
} else {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./node_modules/my-package/index.js:1:12
Module not found: Can't resolve 'dns'

https://nextjs.org/docs/messages/module-not-found
https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./index.js
./app/page.js"
`)
Import trace for requested module:
./index.js
./app/page.js"
`)
}

await cleanup()
})
Expand All @@ -84,19 +96,33 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
expect(await session.hasRedbox()).toBe(true)

const source = await session.getRedboxSource()
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 | <div>
if (process.env.TURBOPACK) {
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 | <div>

https://nextjs.org/docs/messages/module-not-found"
`)
} 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 | <div>

https://nextjs.org/docs/messages/module-not-found
https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./app/page.js"
`)
Import trace for requested module:
./app/page.js"
`)
}

await cleanup()
})
Expand Down Expand Up @@ -137,16 +163,16 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`)
} else {
expect(source).toMatchInlineSnapshot(`
"./app/page.js:2:0
Module not found: Can't resolve 'b'
1 | 'use client'
> 2 | import Comp from 'b'
3 | export default function Oops() {
4 | return (
5 | <div>

https://nextjs.org/docs/messages/module-not-found"
`)
"./app/page.js:2:0
Module not found: Can't resolve 'b'
1 | 'use client'
> 2 | import Comp from 'b'
3 | export default function Oops() {
4 | return (
5 | <div>

https://nextjs.org/docs/messages/module-not-found"
`)
}

await cleanup()
Expand Down Expand Up @@ -186,16 +212,16 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`)
} else {
expect(source).toMatchInlineSnapshot(`
"./app/page.js:2:0
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 <p>index page</p>
5 | }

https://nextjs.org/docs/messages/module-not-found"
`)
"./app/page.js:2:0
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 <p>index page</p>
5 | }

https://nextjs.org/docs/messages/module-not-found"
`)
}
await session.patch(
'app/page.js',
Expand Down
119 changes: 104 additions & 15 deletions test/development/acceptance/ReactRefreshLogBox-app-doc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,59 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
])
)
expect(await session.hasRedbox()).toBe(true)
expect(
next.normalizeTestDirContent(await session.getRedboxSource())
).toMatchInlineSnapshot(
next.normalizeSnapshot(`
const source = next.normalizeTestDirContent(await session.getRedboxSource())
if (process.env.TURBOPACK) {
expect(source).toMatchInlineSnapshot(
next.normalizeSnapshot(`"./pages/_app.js:2:11
Parsing ecmascript source code failed
1 | function MyApp({ Component, pageProps }) {
> 2 | return <<Component {...pageProps} />;
| ^^^^^^^^^
3 | }
4 | export default MyApp

Expression expected"`),
`
"./pages/_app.js:2:11
Parsing ecmascript source code failed
1 | function MyApp({ Component, pageProps }) {
> 2 | return <<Component {...pageProps} />;
| ^^^^^^^^^
3 | }
4 | export default MyApp

Expression expected"
`
)
} else {
expect(source).toMatchInlineSnapshot(
next.normalizeSnapshot(`"./pages/_app.js
Error:
x Expression expected
,-[TEST_DIR/pages/_app.js:1:1]
1 | function MyApp({ Component, pageProps }) {
2 | return <<Component {...pageProps} />;
: ^
3 | }
4 | export default MyApp
\`----

x Expression expected
,-[TEST_DIR/pages/_app.js:1:1]
1 | function MyApp({ Component, pageProps }) {
2 | return <<Component {...pageProps} />;
: ^^^^^^^^^
3 | }
4 | export default MyApp
\`----

Caused by:
Syntax Error"`),
`
"./pages/_app.js
Error:
x Expression expected
,-[TEST_DIR/pages/_app.js:1:1]
,-[1:1]
1 | function MyApp({ Component, pageProps }) {
2 | return <<Component {...pageProps} />;
: ^
Expand All @@ -106,7 +151,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
\`----

x Expression expected
,-[TEST_DIR/pages/_app.js:1:1]
,-[1:1]
1 | function MyApp({ Component, pageProps }) {
2 | return <<Component {...pageProps} />;
: ^^^^^^^^^
Expand All @@ -116,8 +161,9 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {

Caused by:
Syntax Error"
`)
)
`
)
}

await session.patch(
'pages/_app.js',
Expand Down Expand Up @@ -166,14 +212,56 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
])
)
expect(await session.hasRedbox()).toBe(true)
expect(
next.normalizeTestDirContent(await session.getRedboxSource())
).toMatchInlineSnapshot(
next.normalizeSnapshot(`
const source = next.normalizeTestDirContent(await session.getRedboxSource())
if (process.env.TURBOPACK) {
expect(source).toMatchInlineSnapshot(
next.normalizeSnapshot(`"./pages/_document.js:3:35
Parsing ecmascript source code failed
1 | import Document, { Html, Head, Main, NextScript } from 'next/document'
2 |
> 3 | class MyDocument extends Document {{
| ^
4 | static async getInitialProps(ctx) {
5 | const initialProps = await Document.getInitialProps(ctx)
6 | return { ...initialProps }

Unexpected token \`{\`. Expected identifier, string literal, numeric literal or [ for the computed key"`),
`
"./pages/_document.js:3:35
Parsing ecmascript source code failed
1 | import Document, { Html, Head, Main, NextScript } from 'next/document'
2 |
> 3 | class MyDocument extends Document {{
| ^
4 | static async getInitialProps(ctx) {
5 | const initialProps = await Document.getInitialProps(ctx)
6 | return { ...initialProps }

Unexpected token \`{\`. Expected identifier, string literal, numeric literal or [ for the computed key"
`
)
} else {
expect(source).toMatchInlineSnapshot(
next.normalizeSnapshot(`"./pages/_document.js
Error:
x Unexpected token \`{\`. Expected identifier, string literal, numeric literal or [ for the computed key
,-[TEST_DIR/pages/_document.js:1:1]
1 | import Document, { Html, Head, Main, NextScript } from 'next/document'
2 |
3 | class MyDocument extends Document {{
: ^
4 | static async getInitialProps(ctx) {
5 | const initialProps = await Document.getInitialProps(ctx)
6 | return { ...initialProps }
\`----

Caused by:
Syntax Error"`),
`
"./pages/_document.js
Error:
x Unexpected token \`{\`. Expected identifier, string literal, numeric literal or [ for the computed key
,-[TEST_DIR/pages/_document.js:1:1]
,-[1:1]
1 | import Document, { Html, Head, Main, NextScript } from 'next/document'
2 |
3 | class MyDocument extends Document {{
Expand All @@ -185,8 +273,9 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {

Caused by:
Syntax Error"
`)
)
`
)
}

await session.patch(
'pages/_document.js',
Expand Down
Loading
Loading