Unverified Commit c1c3675f authored by Leah's avatar Leah Committed by GitHub

refactor tests for readability (#51051)

You'll probably want to disable whitespace in the diff

## Description

This allows for better editor support by using `describe` or functions called `describe` with the same syntax instead of custom names.

Changes:
- `nextTestSetup` can be used instead of `createNextDescribe` keeping the same behaviour but being called inside a `describe` "block" (not applied everywhere)
- `getSnapshotTestDescribe` replaced with a custom `describe.each`
- `sandbox` helper function for `acceptance`/`acceptance-app` merged into a single shared one
- `outdent` to remove the indent from inline files in tests which helps with consistent snapshots
parent c30f21fa
......@@ -169,6 +169,7 @@
"npm-run-all": "4.1.5",
"nprogress": "0.2.0",
"open": "9.0.0",
"outdent": "0.8.0",
"pixrem": "5.0.0",
"playwright-chromium": "1.28.1",
"plop": "3.0.5",
......
......@@ -128,6 +128,7 @@ importers:
npm-run-all: 4.1.5
nprogress: 0.2.0
open: 9.0.0
outdent: 0.8.0
pixrem: 5.0.0
playwright-chromium: 1.28.1
plop: 3.0.5
......@@ -295,6 +296,7 @@ importers:
npm-run-all: 4.1.5
nprogress: 0.2.0
open: 9.0.0
outdent: 0.8.0
pixrem: 5.0.0
playwright-chromium: 1.28.1
plop: 3.0.5
......@@ -18878,6 +18880,10 @@ packages:
os-tmpdir: 1.0.2
dev: true
/outdent/0.8.0:
resolution: {integrity: sha512-KiOAIsdpUTcAXuykya5fnVVT+/5uS0Q1mrkRHcF89tpieSmY33O/tmc54CqwA+bfhbtEfZUNLHaPUiB9X3jt1A==}
dev: true
/p-cancelable/0.3.0:
resolution: {integrity: sha512-RVbZPLso8+jFeq1MfNvgXtCRED2raz/dKpacfTNxsx6pLEpEomM7gah6VeHSYV3+vo0OAi4MkArtQcWWXuQoyw==}
engines: {node: '>=4'}
......
/* eslint-env jest */
import { sandbox } from './helpers'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { sandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { outdent } from 'outdent'
describe('ReactRefresh app', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
afterAll(() => next.destroy())
test('can edit a component without losing state', async () => {
const { session, cleanup } = await sandbox(next)
await session.patch(
'index.js',
`
outdent`
import { useCallback, useState } from 'react'
export default function Index() {
const [count, setCount] = useState(0)
......@@ -43,7 +38,7 @@ describe('ReactRefresh app', () => {
).toBe('1')
await session.patch(
'index.js',
`
outdent`
import { useCallback, useState } from 'react'
export default function Index() {
const [count, setCount] = useState(0)
......@@ -72,7 +67,7 @@ describe('ReactRefresh app', () => {
await session.write(
'NudgeOverview.js',
`
outdent`
import * as React from 'react';
import { foo } from './routes';
......@@ -88,7 +83,7 @@ describe('ReactRefresh app', () => {
await session.write(
'SurveyOverview.js',
`
outdent`
const SurveyOverview = () => {
return 100;
};
......@@ -99,7 +94,7 @@ describe('ReactRefresh app', () => {
await session.write(
'Milestones.js',
`
outdent`
import React from 'react';
import { fragment } from './DashboardPage';
......@@ -115,7 +110,7 @@ describe('ReactRefresh app', () => {
await session.write(
'DashboardPage.js',
`
outdent`
import React from 'react';
import Milestones from './Milestones';
......@@ -140,7 +135,7 @@ describe('ReactRefresh app', () => {
await session.write(
'routes.js',
`
outdent`
import DashboardPage from './DashboardPage';
export const foo = {};
......@@ -154,7 +149,7 @@ describe('ReactRefresh app', () => {
await session.patch(
'index.js',
`
outdent`
import * as React from 'react';
import DashboardPage from './routes';
......@@ -173,7 +168,7 @@ describe('ReactRefresh app', () => {
let didFullRefresh = !(await session.patch(
'SurveyOverview.js',
`
outdent`
const SurveyOverview = () => {
return 200;
};
......@@ -189,7 +184,7 @@ describe('ReactRefresh app', () => {
didFullRefresh = !(await session.patch(
'index.js',
`
outdent`
import * as React from 'react';
import DashboardPage from './routes';
......@@ -209,7 +204,7 @@ describe('ReactRefresh app', () => {
didFullRefresh = !(await session.patch(
'SurveyOverview.js',
`
outdent`
const SurveyOverview = () => {
return 300;
};
......
import { sandbox } from './helpers'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { sandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { getSnapshotTestDescribe } from 'next-test-utils'
import { describeVariants as describe } from 'next-test-utils'
import { outdent } from 'outdent'
// TODO-APP: Investigate snapshot mismatch
for (const variant of ['default', 'turbo']) {
getSnapshotTestDescribe(variant)(`ReactRefreshLogBox app ${variant}`, () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: new FileRef(
path.join(__dirname, 'fixtures', 'default-template')
),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
})
afterAll(() => next.destroy())
// Module trace is only available with webpack 5
test('Node.js builtins', async () => {
const { session, cleanup } = await sandbox(
next,
new Map([
[
'node_modules/my-package/index.js',
`
const dns = require('dns')
module.exports = dns
`,
],
[
'node_modules/my-package/package.json',
`
{
"name": "my-package",
"version": "0.0.1"
}
`,
],
])
)
await session.patch(
'index.js',
`
import pkg from 'my-package'
export default function Hello() {
return (pkg ? <h1>Package loaded</h1> : <h1>Package did not load</h1>)
}
`
)
expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource()).toMatchSnapshot()
await cleanup()
})
test('Module not found', async () => {
const { session, cleanup } = await sandbox(next)
await session.patch(
'index.js',
`import Comp from 'b'
export default function Oops() {
return (
<div>
<Comp>lol</Comp>
</div>
)
}
`
)
expect(await session.hasRedbox(true)).toBe(true)
const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()
await cleanup()
})
test('Module not found empty import trace', async () => {
const { session, cleanup } = await sandbox(next)
await session.patch(
'app/page.js',
`'use client'
import Comp from 'b'
export default function Oops() {
return (
<div>
<Comp>lol</Comp>
</div>
)
}
`
)
expect(await session.hasRedbox(true)).toBe(true)
const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()
await cleanup()
})
test('Module not found missing global CSS', async () => {
const { session, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
`'use client'
import './non-existent.css'
describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
// Module trace is only available with webpack 5
test('Node.js builtins', async () => {
const { session, cleanup } = await sandbox(
next,
new Map([
[
'node_modules/my-package/index.js',
outdent`
const dns = require('dns')
module.exports = dns
`,
],
[
'node_modules/my-package/package.json',
outdent`
{
"name": "my-package",
"version": "0.0.1"
}
`,
],
])
)
await session.patch(
'index.js',
outdent`
import pkg from 'my-package'
export default function Hello() {
return (pkg ? <h1>Package loaded</h1> : <h1>Package did not load</h1>)
}
`
)
expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource()).toMatchSnapshot()
await cleanup()
})
test('Module not found', async () => {
const { session, cleanup } = await sandbox(next)
await session.patch(
'index.js',
outdent`
import Comp from 'b'
export default function Oops() {
return (
<div>
<Comp>lol</Comp>
</div>
)
}
`
)
expect(await session.hasRedbox(true)).toBe(true)
const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()
await cleanup()
})
test('Module not found empty import trace', async () => {
const { session, cleanup } = await sandbox(next)
await session.patch(
'app/page.js',
outdent`
'use client'
import Comp from 'b'
export default function Oops() {
return (
<div>
<Comp>lol</Comp>
</div>
)
}
`
)
expect(await session.hasRedbox(true)).toBe(true)
const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()
await cleanup()
})
test('Module not found missing global CSS', async () => {
const { session, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
outdent`
'use client'
import './non-existent.css'
export default function Page(props) {
return <p>index page</p>
}
`,
],
])
)
expect(await session.hasRedbox(true)).toBe(true)
const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()
await session.patch(
'app/page.js',
outdent`
'use client'
export default function Page(props) {
return <p>index page</p>
}
`,
],
])
)
expect(await session.hasRedbox(true)).toBe(true)
const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()
await session.patch(
'app/page.js',
`'use client'
export default function Page(props) {
return <p>index page</p>
}
`
)
expect(await session.hasRedbox(false)).toBe(false)
expect(
await session.evaluate(() => document.documentElement.innerHTML)
).toContain('index page')
await cleanup()
})
`
)
expect(await session.hasRedbox(false)).toBe(false)
expect(
await session.evaluate(() => document.documentElement.innerHTML)
).toContain('index page')
await cleanup()
})
}
})
/* eslint-env jest */
import { sandbox } from './helpers'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { sandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { outdent } from 'outdent'
describe('ReactRefreshLogBox app', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true,
dependencies: {
sass: 'latest',
react: 'latest',
'react-dom': 'latest',
},
})
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
sass: 'latest',
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
afterAll(() => next.destroy())
test('scss syntax errors', async () => {
const { session, cleanup } = await sandbox(next)
......@@ -26,7 +21,7 @@ describe('ReactRefreshLogBox app', () => {
await session.write('index.module.scss', `.button { font-size: 5px; }`)
await session.patch(
'index.js',
`
outdent`
import './index.module.scss';
export default () => {
return (
......
import { sandbox } from './helpers'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { sandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { outdent } from 'outdent'
// TODO: re-enable these tests after figuring out what is causing
// them to be so unreliable in CI
describe.skip('ReactRefreshLogBox app', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
afterAll(() => next.destroy())
test('<Link> with multiple children', async () => {
const { session, cleanup } = await sandbox(next)
await session.patch(
'index.js',
`
outdent`
import Link from 'next/link'
export default function Index() {
......@@ -64,7 +59,7 @@ describe.skip('ReactRefreshLogBox app', () => {
await session.patch(
'index.js',
`
outdent`
import Link from 'next/link'
export default function Hello() {
......@@ -80,7 +75,7 @@ describe.skip('ReactRefreshLogBox app', () => {
await session.patch(
'index.js',
`
outdent`
import Link from 'next/link'
export default function Hello() {
......@@ -92,7 +87,7 @@ describe.skip('ReactRefreshLogBox app', () => {
await session.patch(
'index.js',
`
outdent`
import Link from 'next/link'
export default function Hello() {
......@@ -116,7 +111,7 @@ describe.skip('ReactRefreshLogBox app', () => {
await session.patch(
'index.js',
`
outdent`
import Link from 'next/link'
export default function Hello() {
......@@ -140,7 +135,7 @@ describe.skip('ReactRefreshLogBox app', () => {
await session.patch(
'index.js',
`
outdent`
import Link from 'next/link'
export default function Hello() {
......@@ -164,7 +159,7 @@ describe.skip('ReactRefreshLogBox app', () => {
await session.patch(
'index.js',
`
outdent`
import Link from 'next/link'
export default function Hello() {
......@@ -189,7 +184,7 @@ describe.skip('ReactRefreshLogBox app', () => {
await session.patch(
'index.js',
`
outdent`
import Link from 'next/link'
export default function Hello() {
......@@ -220,7 +215,8 @@ describe.skip('ReactRefreshLogBox app', () => {
await session.patch(
'app/page.js',
`'use client'
outdent`
'use client'
import myLibrary from 'my-non-existent-library'
export async function getStaticProps() {
return {
......
import { createNext, FileRef } from 'e2e-utils'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { NextInstance } from 'test/lib/next-modes/base'
import { sandbox } from './helpers'
import { sandbox } from 'development-sandbox'
import { outdent } from 'outdent'
describe('ReactRefreshModule app', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
afterAll(() => next.destroy())
it('should allow any variable names', async () => {
const { session, cleanup } = await sandbox(next, new Map([]))
......@@ -33,11 +28,13 @@ describe('ReactRefreshModule app', () => {
for await (const variable of variables) {
await session.patch(
'app/page.js',
`'use client'
import { default as ${variable} } from 'next/link'
export default function Page() {
return null
}`
outdent`
'use client'
import { default as ${variable} } from 'next/link'
export default function Page() {
return null
}
`
)
expect(await session.hasRedbox(false)).toBe(false)
expect(next.cliOutput).not.toContain(
......
/* eslint-env jest */
import { sandbox } from './helpers'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { sandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { check } from 'next-test-utils'
import { outdent } from 'outdent'
describe('ReactRefreshRegression app', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true,
dependencies: {
'styled-components': '5.1.0',
'@next/mdx': 'canary',
'@mdx-js/loader': '0.18.0',
react: 'latest',
'react-dom': 'latest',
},
})
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
'styled-components': '5.1.0',
'@next/mdx': 'canary',
'@mdx-js/loader': '0.18.0',
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
afterAll(() => next.destroy())
// https://github.com/vercel/next.js/issues/12422
// TODO-APP: port to app directory
......@@ -29,7 +24,7 @@ describe('ReactRefreshRegression app', () => {
const files = new Map()
files.set(
'pages/_document.js',
`
outdent`
import Document from 'next/document'
import { ServerStyleSheet } from 'styled-components'
......@@ -67,7 +62,7 @@ describe('ReactRefreshRegression app', () => {
// We start here.
await session.patch(
'index.js',
`
outdent`
import React from 'react'
import styled from 'styled-components'
......@@ -92,7 +87,8 @@ describe('ReactRefreshRegression app', () => {
await session.patch(
'app/page.js',
`'use client'
outdent`
'use client'
import { useCallback, useState } from 'react'
export default function Index() {
......@@ -118,7 +114,8 @@ describe('ReactRefreshRegression app', () => {
await session.patch(
'app/page.js',
`'use client'
outdent`
'use client'
import { useCallback, useState } from 'react'
export default function Index() {
......@@ -151,7 +148,7 @@ describe('ReactRefreshRegression app', () => {
await session.patch(
'app/page.js',
`
outdent`
export const revalidate = 0
import Component from '../index'
......@@ -162,7 +159,8 @@ describe('ReactRefreshRegression app', () => {
)
await session.patch(
'index.js',
`'use client'
outdent`
'use client'
import { useCallback, useState } from 'react'
export default function Index() {
......@@ -192,7 +190,8 @@ describe('ReactRefreshRegression app', () => {
await session.patch(
'index.js',
`'use client'
outdent`
'use client'
import { useCallback, useState } from 'react'
export default function Index() {
......@@ -229,7 +228,7 @@ describe('ReactRefreshRegression app', () => {
await session.patch(
'app/page.js',
`
outdent`
export const config = {}
import Component from '../index'
......@@ -241,7 +240,8 @@ describe('ReactRefreshRegression app', () => {
await session.patch(
'index.js',
`'use client'
outdent`
'use client'
import { useCallback, useState } from 'react'
export const config = {}
......@@ -316,8 +316,10 @@ describe('ReactRefreshRegression app', () => {
await session.patch(
'app/page.js',
`'use client'
export default function Page() { throw new Error('boom'); }`
outdent`
'use client'
export default function Page() { throw new Error('boom'); }
`
)
expect(await session.hasRedbox(true)).toBe(true)
......@@ -337,7 +339,7 @@ describe('ReactRefreshRegression app', () => {
const files = new Map()
files.set(
'next.config.js',
`
outdent`
const withMDX = require("@next/mdx")({
extension: /\\.mdx?$/,
});
......@@ -350,12 +352,13 @@ describe('ReactRefreshRegression app', () => {
files.set('app/content.mdx', `Hello World!`)
files.set(
'app/page.js',
`'use client'
import MDX from './content.mdx'
export default function Page() {
return <div id="content"><MDX /></div>
}
`
outdent`
'use client'
import MDX from './content.mdx'
export default function Page() {
return <div id="content"><MDX /></div>
}
`
)
const { session, cleanup } = await sandbox(next, files)
......
/* eslint-env jest */
import { sandbox } from './helpers'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { sandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { outdent } from 'outdent'
describe('ReactRefreshRequire app', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
afterAll(() => next.destroy())
// https://github.com/facebook/metro/blob/b651e535cd0fc5df6c0803b9aa647d664cb9a6c3/packages/metro/src/lib/polyfills/__tests__/require-test.js#L989-L1048
test('re-runs accepted modules', async () => {
......@@ -87,12 +82,12 @@ describe('ReactRefreshRequire app', () => {
await session.write(
'./foo.js',
`
window.log.push('init FooV1');
require('./bar');
outdent`
window.log.push('init FooV1');
require('./bar');
// Exporting a component marks it as auto-accepting.
export default function Foo() {};
// Exporting a component marks it as auto-accepting.
export default function Foo() {};
`
)
......@@ -144,10 +139,10 @@ describe('ReactRefreshRequire app', () => {
await session.evaluate(() => ((window as any).log = []))
await session.patch(
'./bar.js',
`
window.log.push('init BarV3');
// Exporting a component marks it as auto-accepting.
export default function Bar() {};
outdent`
window.log.push('init BarV3');
// Exporting a component marks it as auto-accepting.
export default function Bar() {};
`
)
expect(await session.evaluate(() => (window as any).log)).toEqual([
......@@ -165,9 +160,9 @@ describe('ReactRefreshRequire app', () => {
await session.evaluate(() => ((window as any).log = []))
await session.patch(
'./bar.js',
`
window.log.push('init BarV4');
export default function Bar() {};
outdent`
window.log.push('init BarV4');
export default function Bar() {};
`
)
expect(await session.evaluate(() => (window as any).log)).toEqual([
......@@ -203,34 +198,34 @@ describe('ReactRefreshRequire app', () => {
await session.write(
'root.js',
`
window.log.push('init RootV1');
outdent`
window.log.push('init RootV1');
import './middleA';
import './middleB';
import './middleC';
import './middleA';
import './middleB';
import './middleC';
export default function Root() {};
export default function Root() {};
`
)
await session.write(
'middleA.js',
`
log.push('init MiddleAV1');
outdent`
log.push('init MiddleAV1');
import './leaf';
import './leaf';
export default function MiddleA() {};
export default function MiddleA() {};
`
)
await session.write(
'middleB.js',
`
log.push('init MiddleBV1');
outdent`
log.push('init MiddleBV1');
import './leaf';
import './leaf';
export default function MiddleB() {};
export default function MiddleB() {};
`
)
// This one doesn't import leaf and also doesn't export a component (so it
......@@ -290,12 +285,12 @@ describe('ReactRefreshRequire app', () => {
await session.evaluate(() => ((window as any).log = []))
await session.patch(
'middleB.js',
`
log.push('init MiddleBV2');
outdent`
log.push('init MiddleBV2');
import './leaf';
import './leaf';
export default function MiddleB() {};
export default function MiddleB() {};
`
)
expect(await session.evaluate(() => (window as any).log)).toEqual([
......
......@@ -4,9 +4,9 @@ exports[`ReactRefreshLogBox app default Module not found 1`] = `
"./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>
2 | export default function Oops() {
3 | return (
4 | <div>
https://nextjs.org/docs/messages/module-not-found
......@@ -15,33 +15,31 @@ Import trace for requested module:
`;
exports[`ReactRefreshLogBox app default Module not found empty import trace 1`] = `
"./app/page.js (2:6)
"./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>
> 2 | import Comp from 'b'
3 | export default function Oops() {
4 | return (
5 | <div>
https://nextjs.org/docs/messages/module-not-found"
`;
exports[`ReactRefreshLogBox app default Module not found missing global CSS 1`] = `
"./app/page.js:2:10
"./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 | }
> 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"
`;
exports[`ReactRefreshLogBox app default Node.js builtins 1`] = `
"./node_modules/my-package/index.js (2:0)
"./node_modules/my-package/index.js (1:0)
Module not found: Can't resolve 'dns'
https://nextjs.org/docs/messages/module-not-found
......
......@@ -22,15 +22,15 @@ Import trace for requested module:
`;
exports[`ReactRefreshLogBox app default Should not show __webpack_exports__ when exporting anonymous arrow function 1`] = `
"index.js (4:16) @ default
2 | export default () => {
3 | if (typeof window !== 'undefined') {
> 4 | throw new Error('test')
| ^
5 | }
6 |
7 | return null"
"index.js (3:10) @ default
1 | export default () => {
2 | if (typeof window !== 'undefined') {
> 3 | throw new Error('test')
| ^
4 | }
5 |
6 | return null"
`;
exports[`ReactRefreshLogBox app default boundaries 1`] = `
......@@ -41,15 +41,14 @@ exports[`ReactRefreshLogBox app default boundaries 1`] = `
`;
exports[`ReactRefreshLogBox app default conversion to class component (1) 1`] = `
"Child.js (5:18) @ ClickCount.render
3 | export default class ClickCount extends Component {
4 | render() {
> 5 | throw new Error()
| ^
6 | }
7 | }
8 | "
"Child.js (4:10) @ ClickCount.render
2 | export default class ClickCount extends Component {
3 | render() {
> 4 | throw new Error()
| ^
5 | }
6 | }"
`;
exports[`ReactRefreshLogBox app default css syntax errors 1`] = `
......@@ -77,25 +76,25 @@ exports[`ReactRefreshLogBox app default logbox: anchors links in error messages
exports[`ReactRefreshLogBox app default logbox: anchors links in error messages 9`] = `"http://example.com/"`;
exports[`ReactRefreshLogBox app default module init error not shown 1`] = `
"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 <h1>Default Export</h1>;"
"index.js (3:6) @ eval
1 | // top offset for snapshot
2 | import * as React from 'react';
> 3 | throw new Error('no')
| ^
4 | class ClassDefault extends React.Component {
5 | render() {
6 | return <h1>Default Export</h1>;"
`;
exports[`ReactRefreshLogBox app default should strip whitespace correctly with newline 1`] = `
"index.js (9:34) @ onClick
"index.js (8:26) @ onClick
7 |
8 | <a onClick={() => {
> 9 | throw new Error('idk')
6 |
7 | <a onClick={() => {
> 8 | throw new Error('idk')
| ^
10 | }}>
11 | click me
12 | </a>"
9 | }}>
10 | click me
11 | </a>"
`;
import { createNextDescribe, FileRef } from 'e2e-utils'
import { FileRef, nextTestSetup } from 'e2e-utils'
import { check, hasRedbox, waitFor, retry } from 'next-test-utils'
import path from 'path'
createNextDescribe(
'Error overlay - RSC build errors',
{
describe('Error overlay - RSC build errors', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'app-hmr-changes')),
dependencies: {
'@next/mdx': 'canary',
......@@ -18,48 +17,47 @@ createNextDescribe(
'image-size': '^1.0.2',
autoprefixer: '^10.4.13',
},
},
({ next }) => {
it('should handle successive HMR changes with errors correctly', async () => {
const browser = await retry(
() => next.browser('/2020/develop-preview-test'),
1000,
500
)
})
await check(
() => browser.eval('document.documentElement.innerHTML'),
/A few years ago I tweeted/
)
it('should handle successive HMR changes with errors correctly', async () => {
const browser = await retry(
() => next.browser('/2020/develop-preview-test'),
1000,
500
)
const pagePath = 'app/(post)/2020/develop-preview-test/page.mdx'
const originalPage = await next.readFile(pagePath)
await check(
() => browser.eval('document.documentElement.innerHTML'),
/A few years ago I tweeted/
)
const break1 = originalPage.replace('break 1', '<Figure>')
const pagePath = 'app/(post)/2020/develop-preview-test/page.mdx'
const originalPage = await next.readFile(pagePath)
await next.patchFile(pagePath, break1)
const break2 = break1.replace('{/* break point 2 */}', '<Figure />')
const break1 = originalPage.replace('break 1', '<Figure>')
await next.patchFile(pagePath, break2)
await next.patchFile(pagePath, break1)
for (let i = 0; i < 5; i++) {
await next.patchFile(pagePath, break2.replace('break 3', '<Hello />'))
const break2 = break1.replace('{/* break point 2 */}', '<Figure />')
await next.patchFile(pagePath, break2)
expect(await hasRedbox(browser, true)).toBe(true)
await next.patchFile(pagePath, break2)
await next.patchFile(pagePath, break1)
await waitFor(100)
for (let i = 0; i < 5; i++) {
await next.patchFile(pagePath, break2.replace('break 3', '<Hello />'))
await next.patchFile(pagePath, originalPage)
expect(await hasRedbox(browser, false)).toBe(false)
}
await next.patchFile(pagePath, break2)
expect(await hasRedbox(browser, true)).toBe(true)
await check(
() => browser.eval('document.documentElement.innerHTML'),
/A few years ago I tweeted/
)
})
}
)
await next.patchFile(pagePath, break1)
await waitFor(100)
await next.patchFile(pagePath, originalPage)
expect(await hasRedbox(browser, false)).toBe(false)
}
await check(
() => browser.eval('document.documentElement.innerHTML'),
/A few years ago I tweeted/
)
})
})
/* eslint-env jest */
import { sandbox } from './helpers'
import { createNextDescribe, FileRef } from 'e2e-utils'
import { sandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { outdent } from 'outdent'
createNextDescribe(
'Component Stack in error overlay',
{
describe('Component Stack in error overlay', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
},
({ next }) => {
it('should show a component stack on hydration error', async () => {
const { cleanup, session } = await sandbox(
next,
new Map([
[
'app/component.js',
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Component() {
return (
<div>
<p>{isClient ? "client" : "server"}</p>
</div>
);
}
`,
],
[
'app/page.js',
`
import Component from './component'
export default function Mismatch() {
return (
<main>
<Component />
</main>
);
}
`,
],
])
)
})
await session.waitForAndOpenRuntimeError()
it('should show a component stack on hydration error', async () => {
const { cleanup, session } = await sandbox(
next,
new Map([
[
'app/component.js',
outdent`
'use client'
const isClient = typeof window !== 'undefined'
export default function Component() {
return (
<div>
<p>{isClient ? "client" : "server"}</p>
</div>
);
}
`,
],
[
'app/page.js',
outdent`
import Component from './component'
export default function Mismatch() {
return (
<main>
<Component />
</main>
);
}
`,
],
])
)
expect(await session.getRedboxComponentStack()).toMatchInlineSnapshot(`
await session.waitForAndOpenRuntimeError()
expect(await session.getRedboxComponentStack()).toMatchInlineSnapshot(`
"p
div
Component
main"
`)
await cleanup()
})
}
)
await cleanup()
})
})
/* eslint-env jest */
import { sandbox } from './helpers'
import { createNextDescribe } from 'e2e-utils'
import { sandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { outdent } from 'outdent'
createNextDescribe(
'dynamic = "error" in devmode',
{
files: path.join(__dirname, 'fixtures', 'default-template'),
describe('dynamic = "error" in devmode', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true,
},
({ next }) => {
it('should show error overlay when dynamic is forced', async () => {
const { session, cleanup } = await sandbox(next, undefined, '/server')
// dynamic = "error" and force dynamic
await session.patch(
'app/server/page.js',
`
})
it('should show error overlay when dynamic is forced', async () => {
const { session, cleanup } = await sandbox(next, undefined, '/server')
// dynamic = "error" and force dynamic
await session.patch(
'app/server/page.js',
outdent`
import { cookies } from 'next/headers';
import Component from '../../index'
......@@ -28,15 +28,14 @@ createNextDescribe(
export const dynamic = "error"
`
)
await session.hasRedbox(true)
console.log(await session.getRedboxDescription())
expect(await session.getRedboxDescription()).toBe(
`Error: Page with \`dynamic = "error"\` couldn't be rendered statically because it used \`cookies\`.`
)
await cleanup()
})
}
)
)
await session.hasRedbox(true)
console.log(await session.getRedboxDescription())
expect(await session.getRedboxDescription()).toBe(
`Error: Page with \`dynamic = "error"\` couldn't be rendered statically because it used \`cookies\`.`
)
await cleanup()
})
})
import { check } from 'next-test-utils'
import { createNextDescribe, FileRef } from 'e2e-utils'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { sandbox } from './helpers'
import { sandbox } from 'development-sandbox'
import { outdent } from 'outdent'
async function clickSourceFile(browser: any) {
await browser.waitForElementByCss(
......@@ -24,136 +25,140 @@ async function clickImportTraceFiles(browser: any) {
}
}
createNextDescribe(
'Error overlay - editor links',
{
describe('Error overlay - editor links', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
},
({ next }) => {
it('should be possible to open source file on build error', async () => {
let editorRequestsCount = 0
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
`
})
it('should be possible to open source file on build error', async () => {
let editorRequestsCount = 0
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
outdent`
import Component from '../index'
export default function Page() {
return <Component />
}
`,
],
]),
undefined,
{
beforePageLoad(page) {
page.route('**/__nextjs_launch-editor**', (route) => {
editorRequestsCount += 1
route.fulfill()
})
},
}
)
],
]),
undefined,
{
beforePageLoad(page) {
page.route('**/__nextjs_launch-editor**', (route) => {
editorRequestsCount += 1
route.fulfill()
})
},
}
)
await session.patch(
'index.js',
`import { useState } from 'react'
export default () => 'hello world'`
)
await session.patch(
'index.js',
outdent`
import { useState } from 'react'
export default () => 'hello world'
`
)
expect(await session.hasRedbox(true)).toBe(true)
await clickSourceFile(browser)
await check(() => editorRequestsCount, /1/)
expect(await session.hasRedbox(true)).toBe(true)
await clickSourceFile(browser)
await check(() => editorRequestsCount, /1/)
await cleanup()
})
await cleanup()
})
it('should be possible to open import trace files on RSC parse error', async () => {
let editorRequestsCount = 0
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
`
import Component from '../index'
export default function Page() {
return <Component />
}
`,
],
['mod1.js', "import './mod2.js'"],
['mod2.js', '{{{{{'],
]),
undefined,
{
beforePageLoad(page) {
page.route('**/__nextjs_launch-editor**', (route) => {
editorRequestsCount += 1
route.fulfill()
})
},
}
)
it('should be possible to open import trace files on RSC parse error', async () => {
let editorRequestsCount = 0
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
outdent`
import Component from '../index'
export default function Page() {
return <Component />
}
`,
],
['mod1.js', "import './mod2.js'"],
['mod2.js', '{{{{{'],
]),
undefined,
{
beforePageLoad(page) {
page.route('**/__nextjs_launch-editor**', (route) => {
editorRequestsCount += 1
route.fulfill()
})
},
}
)
await session.patch(
'index.js',
`import './mod1'
export default () => 'hello world'`
)
await session.patch(
'index.js',
outdent`
import './mod1'
export default () => 'hello world'
`
)
expect(await session.hasRedbox(true)).toBe(true)
await clickImportTraceFiles(browser)
await check(() => editorRequestsCount, /4/)
expect(await session.hasRedbox(true)).toBe(true)
await clickImportTraceFiles(browser)
await check(() => editorRequestsCount, /4/)
await cleanup()
})
await cleanup()
})
it('should be possible to open import trace files on module not found error', async () => {
let editorRequestsCount = 0
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
`
import Component from '../index'
export default function Page() {
return <Component />
}
`,
],
['mod1.js', "import './mod2.js'"],
['mod2.js', 'import "boom"'],
]),
undefined,
{
beforePageLoad(page) {
page.route('**/__nextjs_launch-editor**', (route) => {
editorRequestsCount += 1
route.fulfill()
})
},
}
)
it('should be possible to open import trace files on module not found error', async () => {
let editorRequestsCount = 0
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
outdent`
import Component from '../index'
export default function Page() {
return <Component />
}
`,
],
['mod1.js', "import './mod2.js'"],
['mod2.js', 'import "boom"'],
]),
undefined,
{
beforePageLoad(page) {
page.route('**/__nextjs_launch-editor**', (route) => {
editorRequestsCount += 1
route.fulfill()
})
},
}
)
await session.patch(
'index.js',
`import './mod1'
export default () => 'hello world'`
)
await session.patch(
'index.js',
outdent`
import './mod1'
export default () => 'hello world'
`
)
expect(await session.hasRedbox(true)).toBe(true)
await clickImportTraceFiles(browser)
await check(() => editorRequestsCount, /3/)
expect(await session.hasRedbox(true)).toBe(true)
await clickImportTraceFiles(browser)
await check(() => editorRequestsCount, /3/)
await cleanup()
})
}
)
await cleanup()
})
})
import { createNextDescribe, FileRef } from 'e2e-utils'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { sandbox } from './helpers'
import { sandbox } from 'development-sandbox'
import { outdent } from 'outdent'
createNextDescribe(
'Error overlay - error message urls',
{
describe('Error overlay - error message urls', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
},
({ next }) => {
it('should be possible to click url in build error', async () => {
const { session, browser, cleanup } = await sandbox(next)
})
const content = await next.readFile('app/page.js')
it('should be possible to click url in build error', async () => {
const { session, browser, cleanup } = await sandbox(next)
await session.patch(
'app/page.js',
content + '\nexport function getServerSideProps() {}'
)
const content = await next.readFile('app/page.js')
expect(await session.hasRedbox(true)).toBe(true)
await session.patch(
'app/page.js',
content + '\nexport function getServerSideProps() {}'
)
const link = await browser.elementByCss('[data-nextjs-terminal] a')
const text = await link.text()
const href = await link.getAttribute('href')
expect(text).toEqual(
'https://nextjs.org/docs/app/building-your-application/data-fetching'
)
expect(href).toEqual(
'https://nextjs.org/docs/app/building-your-application/data-fetching'
)
expect(await session.hasRedbox(true)).toBe(true)
await cleanup()
})
const link = await browser.elementByCss('[data-nextjs-terminal] a')
const text = await link.text()
const href = await link.getAttribute('href')
expect(text).toEqual(
'https://nextjs.org/docs/app/building-your-application/data-fetching'
)
expect(href).toEqual(
'https://nextjs.org/docs/app/building-your-application/data-fetching'
)
it('should be possible to click url in runtime error', async () => {
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
`'use client'
await cleanup()
})
it('should be possible to click url in runtime error', async () => {
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
outdent`
'use client'
export default function Page() {
return typeof window === 'undefined' ? 'HELLO' : 'WORLD'
}
`,
],
])
)
`,
],
])
)
await session.waitForAndOpenRuntimeError()
await session.waitForAndOpenRuntimeError()
const link = await browser.elementByCss(
'#nextjs__container_errors_desc a'
)
const text = await link.text()
const href = await link.getAttribute('href')
expect(text).toEqual(
'https://nextjs.org/docs/messages/react-hydration-error'
)
expect(href).toEqual(
'https://nextjs.org/docs/messages/react-hydration-error'
)
const link = await browser.elementByCss('#nextjs__container_errors_desc a')
const text = await link.text()
const href = await link.getAttribute('href')
expect(text).toEqual(
'https://nextjs.org/docs/messages/react-hydration-error'
)
expect(href).toEqual(
'https://nextjs.org/docs/messages/react-hydration-error'
)
await cleanup()
})
}
)
await cleanup()
})
})
/* eslint-env jest */
import { sandbox } from './helpers'
import { createNextDescribe, FileRef } from 'e2e-utils'
import { sandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { outdent } from 'outdent'
createNextDescribe(
'Error Overlay invalid imports',
{
describe('Error Overlay invalid imports', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
......@@ -14,25 +14,25 @@ createNextDescribe(
'client-only': 'latest',
},
skipStart: true,
},
({ next }) => {
it('should show error when using styled-jsx in server component', async () => {
const { session, cleanup } = await sandbox(
next,
new Map([
[
'app/comp1.js',
`
import { Comp2 } from './comp2'
export function Comp1() {
return <Comp2 />
}
})
it('should show error when using styled-jsx in server component', async () => {
const { session, cleanup } = await sandbox(
next,
new Map([
[
'app/comp1.js',
outdent`
import { Comp2 } from './comp2'
export function Comp1() {
return <Comp2 />
}
`,
],
[
'app/comp2.js',
`
],
[
'app/comp2.js',
outdent`
export function Comp2() {
return (
<div>
......@@ -44,29 +44,29 @@ createNextDescribe(
</div>
)
}
`,
],
[
'app/page.js',
`'use client'
import { Comp1 } from './comp1'
export default function Page() {
return <Comp1 />
}
],
[
'app/page.js',
outdent`
'use client'
import { Comp1 } from './comp1'
export default function Page() {
return <Comp1 />
}
`,
],
])
)
],
])
)
const pageFile = 'app/page.js'
const content = await next.readFile(pageFile)
const withoutUseClient = content.replace("'use client'", '')
await session.patch(pageFile, withoutUseClient)
const pageFile = 'app/page.js'
const content = await next.readFile(pageFile)
const withoutUseClient = content.replace("'use client'", '')
await session.patch(pageFile, withoutUseClient)
expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./app/comp2.js
'client-only' cannot be imported from a Server Component module. It should only be used from a Client Component.
......@@ -78,70 +78,70 @@ createNextDescribe(
./app/page.js"
`)
await cleanup()
})
await cleanup()
})
it('should show error when external package imports client-only in server component', async () => {
const { session, cleanup } = await sandbox(
next,
new Map([
[
'node_modules/client-only-package/index.js',
`
it('should show error when external package imports client-only in server component', async () => {
const { session, cleanup } = await sandbox(
next,
new Map([
[
'node_modules/client-only-package/index.js',
outdent`
require("client-only")
`,
],
[
'node_modules/client-only-package/package.json',
`
],
[
'node_modules/client-only-package/package.json',
outdent`
{
"name": "client-only-package",
"main": "index.js"
}
`,
],
[
'app/comp1.js',
`
import { Comp2 } from './comp2'
export function Comp1() {
return <Comp2 />
}
],
[
'app/comp1.js',
outdent`
import { Comp2 } from './comp2'
export function Comp1() {
return <Comp2 />
}
`,
],
[
'app/comp2.js',
`
],
[
'app/comp2.js',
outdent`
import "client-only-package"
export function Comp2() {
return (
<div>Hello world</div>
)
}
`,
],
[
'app/page.js',
`'use client'
import { Comp1 } from './comp1'
export default function Page() {
return <Comp1 />
}
],
[
'app/page.js',
outdent`
'use client'
import { Comp1 } from './comp1'
export default function Page() {
return <Comp1 />
}
`,
],
])
)
],
])
)
const pageFile = 'app/page.js'
const content = await next.readFile(pageFile)
const withoutUseClient = content.replace("'use client'", '')
await session.patch(pageFile, withoutUseClient)
const pageFile = 'app/page.js'
const content = await next.readFile(pageFile)
const withoutUseClient = content.replace("'use client'", '')
await session.patch(pageFile, withoutUseClient)
expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./app/comp2.js
'client-only' cannot be imported from a Server Component module. It should only be used from a Client Component.
......@@ -153,68 +153,68 @@ createNextDescribe(
./app/page.js"
`)
await cleanup()
})
await cleanup()
})
it('should show error when external package imports server-only in client component', async () => {
const { session, cleanup } = await sandbox(
next,
new Map([
[
'node_modules/server-only-package/index.js',
`
it('should show error when external package imports server-only in client component', async () => {
const { session, cleanup } = await sandbox(
next,
new Map([
[
'node_modules/server-only-package/index.js',
outdent`
require("server-only")
`,
],
[
'node_modules/server-only-package/package.json',
`
],
[
'node_modules/server-only-package/package.json',
outdent`
{
"name": "server-only-package",
"main": "index.js"
}
`,
],
[
'app/comp1.js',
`
import { Comp2 } from './comp2'
export function Comp1() {
return <Comp2 />
}
],
[
'app/comp1.js',
outdent`
import { Comp2 } from './comp2'
export function Comp1() {
return <Comp2 />
}
`,
],
[
'app/comp2.js',
`
],
[
'app/comp2.js',
outdent`
import 'server-only-package'
export function Comp2() {
return (
<div>Hello world</div>
)
}
`,
],
[
'app/page.js',
`import { Comp1 } from './comp1'
export default function Page() {
return <Comp1 />
}
],
[
'app/page.js',
outdent`
import { Comp1 } from './comp1'
export default function Page() {
return <Comp1 />
}
`,
],
])
)
],
])
)
const file = 'app/page.js'
const content = await next.readFile(file)
await session.patch(file, "'use client'\n" + content)
const file = 'app/page.js'
const content = await next.readFile(file)
await session.patch(file, "'use client'\n" + content)
expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./app/comp2.js
'server-only' cannot be imported from a Client Component module. It should only be used from a Server Component.
......@@ -226,7 +226,6 @@ createNextDescribe(
./app/page.js"
`)
await cleanup()
})
}
)
await cleanup()
})
})
/* eslint-env jest */
import { sandbox } from './helpers'
import { createNextDescribe, FileRef } from 'e2e-utils'
import { sandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { outdent } from 'outdent'
describe.skip('should skip for now', () => {
createNextDescribe(
'Error Overlay version staleness',
{
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
describe.skip('Error Overlay version staleness', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
({ next }) => {
it('should show version staleness in runtime error', async () => {
// Set next to outdated version
const nextPackageJson = JSON.parse(
await next.readFile('node_modules/next/package.json')
)
nextPackageJson.version = '1.0.0'
const { browser, session, cleanup } = await sandbox(
next,
new Map([
['node_modules/next/package.json', JSON.stringify(nextPackageJson)],
])
)
await session.patch(
'app/page.js',
`
skipStart: true,
})
it('should show version staleness in runtime error', async () => {
// Set next to outdated version
const nextPackageJson = JSON.parse(
await next.readFile('node_modules/next/package.json')
)
nextPackageJson.version = '1.0.0'
const { browser, session, cleanup } = await sandbox(
next,
new Map([
['node_modules/next/package.json', JSON.stringify(nextPackageJson)],
])
)
await session.patch(
'app/page.js',
outdent`
"use client"
import Component from '../index'
export default function Page() {
setTimeout(() => {
throw new Error("runtime error")
}, 0)
return null
}
import Component from '../index'
export default function Page() {
setTimeout(() => {
throw new Error("runtime error")
}, 0)
return null
}
`
)
await session.waitForAndOpenRuntimeError()
expect(
await browser
.waitForElementByCss('.nextjs-container-build-error-version-status')
.text()
).toMatchInlineSnapshot(`"Next.js (1.0.0) is outdated (learn more)"`)
await cleanup()
})
it('should show version staleness in render error', async () => {
// Set next to outdated version
const nextPackageJson = JSON.parse(
await next.readFile('node_modules/next/package.json')
)
nextPackageJson.version = '2.0.0'
const { browser, session, cleanup } = await sandbox(
next,
new Map([
['node_modules/next/package.json', JSON.stringify(nextPackageJson)],
])
)
await session.patch(
'app/page.js',
`
export default function Page() {
throw new Error("render error")
return null
}
)
await session.waitForAndOpenRuntimeError()
expect(
await browser
.waitForElementByCss('.nextjs-container-build-error-version-status')
.text()
).toMatchInlineSnapshot(`"Next.js (1.0.0) is outdated (learn more)"`)
await cleanup()
})
it('should show version staleness in render error', async () => {
// Set next to outdated version
const nextPackageJson = JSON.parse(
await next.readFile('node_modules/next/package.json')
)
nextPackageJson.version = '2.0.0'
const { browser, session, cleanup } = await sandbox(
next,
new Map([
['node_modules/next/package.json', JSON.stringify(nextPackageJson)],
])
)
await session.patch(
'app/page.js',
outdent`
export default function Page() {
throw new Error("render error")
return null
}
`
)
expect(
await browser
.waitForElementByCss('.nextjs-container-build-error-version-status')
.text()
).toMatchInlineSnapshot(`"Next.js (2.0.0) is outdated (learn more)"`)
await cleanup()
})
it('should show version staleness in build error', async () => {
// Set next to outdated version
const nextPackageJson = JSON.parse(
await next.readFile('node_modules/next/package.json')
)
nextPackageJson.version = '3.0.0'
const { browser, session, cleanup } = await sandbox(
next,
new Map([
['node_modules/next/package.json', JSON.stringify(nextPackageJson)],
])
)
await session.patch(
'app/page.js',
`
)
expect(
await browser
.waitForElementByCss('.nextjs-container-build-error-version-status')
.text()
).toMatchInlineSnapshot(`"Next.js (2.0.0) is outdated (learn more)"`)
await cleanup()
})
it('should show version staleness in build error', async () => {
// Set next to outdated version
const nextPackageJson = JSON.parse(
await next.readFile('node_modules/next/package.json')
)
nextPackageJson.version = '3.0.0'
const { browser, session, cleanup } = await sandbox(
next,
new Map([
['node_modules/next/package.json', JSON.stringify(nextPackageJson)],
])
)
await session.patch(
'app/page.js',
outdent`
{{{
`
)
expect(
await browser
.waitForElementByCss('.nextjs-container-build-error-version-status')
.text()
).toMatchInlineSnapshot(`"Next.js (3.0.0) is outdated (learn more)"`)
await cleanup()
})
}
)
)
expect(
await browser
.waitForElementByCss('.nextjs-container-build-error-version-status')
.text()
).toMatchInlineSnapshot(`"Next.js (3.0.0) is outdated (learn more)"`)
await cleanup()
})
})
/* eslint-env jest */
import { sandbox } from './helpers'
import { createNext } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { sandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
// TODO: figure out why snapshots mismatch on GitHub actions
// specifically but work in docker and locally
describe.skip('ReactRefreshLogBox', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {},
skipStart: true,
dependencies: {
sass: 'latest',
},
})
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true,
dependencies: {
sass: 'latest',
},
})
afterAll(() => next.destroy())
test('scss syntax errors', async () => {
const { session, cleanup } = await sandbox(next)
......
import { createNext } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { sandbox } from './helpers'
import { FileRef, nextTestSetup } from 'e2e-utils'
import { sandbox } from 'development-sandbox'
import path from 'path'
describe('ReactRefreshModule', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {},
skipStart: true,
})
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true,
})
afterAll(() => next.destroy())
it('should allow any variable names', async () => {
const { session, cleanup } = await sandbox(next, new Map([]))
const { session, cleanup } = await sandbox(next)
expect(await session.hasRedbox(false)).toBe(false)
const variables = [
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment