Commit 54a9be44 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig

WIP test

parent c6d2c932
'use client'
import { use } from 'react'
import Link from 'next/link'
import { useRouter } from 'next/navigation'
export default function Page(props) {
const params = use(props.params)
const router = useRouter()
return (
<>
<h1 id={`message-${params.id}`}>Hello from {params.id}</h1>
<Link
href={params.id === '1' ? '/back-forward/2' : '/back-forward/1'}
id="to-other-page"
>
Go to {params.id === '1' ? '2' : '1'}
</Link>
<button onClick={() => router.back()} id="back-button">
Back
</button>
<button onClick={() => router.forward()} id="forward-button">
Forward
</button>
</>
)
}
'use client'
import { useState, useEffect } from 'react'
export function ClientComponent() {
const [val, setVal] = useState('initial')
useEffect(() => {
setVal('[[updated]]')
}, [])
return <span id="val">{val}</span>
}
import { ClientComponent } from './ClientComponent'
export default async function Page() {
return (
<>
<div>
This fixture is to assert where the bootstrap scripts and other required
scripts emit during SSR
</div>
<div>
<ClientComponent />
</div>
</>
)
}
import { use } from 'react'
import '../styles/global.css'
import './style.css'
export const revalidate = 0
export const preferredRegion = 'sfo1'
async function getData() {
return {
world: 'world',
}
}
export default function Root({ children }) {
const { world } = use(getData())
return (
<html className="this-is-the-document-html">
<head>
<title>{`hello ${world}`}</title>
</head>
<body className="this-is-the-document-body">{children}</body>
</html>
)
}
'use client'
import * as buttonStyle from './button.module.css'
export function Button({ children }) {
return (
<button
className={buttonStyle.button}
onClick={() => {
console.log('clicked button!')
}}
>
{children}
</button>
)
}
.button {
background: #000;
color: #fff;
}
import 'e2e-utils'
process.env.NEXT_EXPERIMENTAL_COMPILE = '1'
if ((global as any).isNextStart) {
require('./index.test')
} else {
it('should skip', () => {})
}
This diff is collapsed.
/**
* @type import('next').NextConfig
*/
module.exports = {
env: {
LEGACY_ENV_KEY: '1',
},
experimental: {
clientRouterFilterRedirects: true,
parallelServerCompiles: true,
parallelServerBuildTraces: true,
webpackBuildWorker: true,
// turbopackMinify: false,
},
distDir: process.env.TURBOPACK ? '.next-turbopack' : '.next',
typescript: {
ignoreBuildErrors: true,
},
turbopack: {
moduleIds: 'named',
},
webpack(config) {
config.optimization.moduleIds = 'named'
// config.optimization.minimize = false
return config
},
}
hello world
\ No newline at end of file
;(window._script_order = window._script_order || []).push(1)
console.log(window._script_order)
;(window._script_order = window._script_order || []).push(2)
console.log(window._script_order)
;(window._script_order = window._script_order || []).push(3)
console.log(window._script_order)
;(window._script_order = window._script_order || []).push(4)
console.log(window._script_order)
import { nextTestSetup } from 'e2e-utils'
import fs from 'fs-extra'
import os from 'os'
import path from 'path'
import {
findPort,
initNextServerScript,
killApp,
fetchViaHTTP,
} from 'next-test-utils'
if (!(globalThis as any).isNextStart) {
it('should skip for non-next start', () => {})
} else {
describe('output: standalone with getStaticProps', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipStart: true,
dependencies: {
swr: 'latest',
nanoid: '4.0.1',
},
})
if (skipped) {
return
}
beforeAll(async () => {
await next.patchFile(
'next.config.js',
(await next.readFile('next.config.js')).replace('// output', 'output')
)
await next.patchFile(
'pages/gsp.js',
`
import useSWR from 'swr'
console.log(useSWR)
export default function Home() {
return <h1>Hello</h1>
}
export async function getStaticProps() {
return {
props: {
foo: "bar",
},
};
}
`
)
await next.start()
})
it('should work correctly with output standalone', async () => {
const tmpFolder = path.join(os.tmpdir(), 'next-standalone-' + Date.now())
await fs.move(path.join(next.testDir, '.next/standalone'), tmpFolder)
let server: any
try {
const testServer = path.join(tmpFolder, 'server.js')
const appPort = await findPort()
server = await initNextServerScript(
testServer,
/- Local:/,
{
...process.env,
PORT: appPort.toString(),
},
undefined,
{
cwd: tmpFolder,
}
)
const res = await fetchViaHTTP(appPort, '/gsp')
expect(res.status).toBe(200)
} finally {
if (server) await killApp(server)
await fs.remove(tmpFolder)
}
})
})
}
import { nextTestSetup } from 'e2e-utils'
import fs from 'fs-extra'
import os from 'os'
import path from 'path'
import {
findPort,
initNextServerScript,
killApp,
fetchViaHTTP,
} from 'next-test-utils'
if (!(globalThis as any).isNextStart) {
it('should skip for non-next start', () => {})
} else {
describe('output: standalone with app dir', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipStart: true,
dependencies: {
nanoid: '4.0.1',
},
})
if (skipped) {
return
}
beforeAll(async () => {
await next.patchFile(
'next.config.js',
(await next.readFile('next.config.js')).replace('// output', 'output')
)
await next.start()
})
it('should handle trace files correctly for route groups (nodejs only)', async () => {
expect(next.cliOutput).not.toContain('Failed to copy traced files')
const serverDirPath = path.join(
next.testDir,
'.next/standalone/.next/server'
)
for (const page of [
'(newroot)/dashboard/another',
'(newroot)/dashboard/project/[projectId]',
'(rootonly)/dashboard/changelog',
]) {
const pagePath = path.join(serverDirPath, 'app', page)
expect(
await fs.pathExists(path.join(pagePath, 'page.js.nft.json'))
).toBe(true)
const files = (
await fs.readJSON(path.join(pagePath, 'page.js.nft.json'))
).files as string[]
for (const file of files) {
expect(await fs.pathExists(path.join(pagePath, file))).toBe(true)
}
}
})
it('should work correctly with output standalone', async () => {
const tmpFolder = path.join(os.tmpdir(), 'next-standalone-' + Date.now())
await fs.move(path.join(next.testDir, '.next/standalone'), tmpFolder)
let server: any
try {
const testServer = path.join(tmpFolder, 'server.js')
const appPort = await findPort()
server = await initNextServerScript(
testServer,
/- Local:/,
{
...process.env,
PORT: appPort.toString(),
},
undefined,
{
cwd: tmpFolder,
}
)
for (const testPath of [
'/',
'/api/hello',
'/blog/first',
'/dashboard',
'/dashboard/another',
'/dashboard/changelog',
'/dashboard/deployments/breakdown',
'/dashboard/deployments/123',
'/dashboard/hello',
'/dashboard/project/123',
'/catch-all/first',
]) {
const res = await fetchViaHTTP(appPort, testPath)
expect(res.status).toBe(200)
}
} finally {
if (server) await killApp(server)
await fs.remove(tmpFolder)
}
})
})
}
import { createNext } from 'e2e-utils'
import { NextInstance } from 'e2e-utils'
import { check } from 'next-test-utils'
describe('useReportWebVitals hook', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: __dirname,
skipStart: true,
env: {},
dependencies: {
nanoid: '4.0.1',
},
})
await next.start()
})
afterAll(() => next.destroy())
// Analytics events are only sent in production
it('should send web-vitals', async () => {
await next.fetch('/report-web-vitals')
let eventsCount = 0
const browser = await next.browser('/report-web-vitals', {
beforePageLoad: (page) => {
page.route('https://example.vercel.sh/vitals', (route) => {
eventsCount += 1
route.fulfill()
})
},
})
// Refresh will trigger CLS and LCP. When page loads FCP and TTFB will trigger:
await browser.refresh()
// After interaction LCP and FID will trigger
await browser.elementById('btn').click()
// Make sure all registered events in performance-relayer has fired
await check(async () => {
expect(eventsCount).toBeGreaterThanOrEqual(6)
return 'success'
}, 'success')
})
})
'use client'
import * as buttonStyle from './button.module.css'
export function Button({ children }) {
return (
<button
className={buttonStyle.button}
onClick={() => {
console.log('clicked button!')
}}
>
{children}
</button>
)
}
import 'e2e-utils'
process.env.NEXT_EXPERIMENTAL_COMPILE = '1'
if ((global as any).isNextStart) {
require('./index.test')
} else {
it('should skip', () => {})
}
This diff is collapsed.
/**
* @type import('next').NextConfig
*/
module.exports = {
env: {
LEGACY_ENV_KEY: '1',
},
experimental: {
clientRouterFilterRedirects: true,
parallelServerCompiles: true,
parallelServerBuildTraces: true,
webpackBuildWorker: true,
turbopackMinify: false,
},
distDir: process.env.TURBOPACK ? '.next-turbopack' : '.next',
typescript: {
ignoreBuildErrors: true,
},
turbopack: {
moduleIds: 'named',
},
webpack(config) {
config.optimization.moduleIds = 'named'
config.optimization.minimize = false
return config
},
}
// import { useRouter } from 'next/router'
export default function Page(props) {
return (
<>
<p>hello from ssr</p>
{/* <p id="query">{JSON.stringify(useRouter().query)}</p> */}
</>
)
}
export function getServerSideProps() {
return {
props: {},
}
}
hello world
\ No newline at end of file
;(window._script_order = window._script_order || []).push(1)
console.log(window._script_order)
;(window._script_order = window._script_order || []).push(2)
console.log(window._script_order)
;(window._script_order = window._script_order || []).push(3)
console.log(window._script_order)
;(window._script_order = window._script_order || []).push(4)
console.log(window._script_order)
import { nextTestSetup } from 'e2e-utils'
import fs from 'fs-extra'
import os from 'os'
import path from 'path'
import {
findPort,
initNextServerScript,
killApp,
fetchViaHTTP,
} from 'next-test-utils'
if (!(globalThis as any).isNextStart) {
it('should skip for non-next start', () => {})
} else {
describe('output: standalone with getStaticProps', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipStart: true,
dependencies: {
swr: 'latest',
nanoid: '4.0.1',
},
})
if (skipped) {
return
}
beforeAll(async () => {
await next.patchFile(
'next.config.js',
(await next.readFile('next.config.js')).replace('// output', 'output')
)
await next.patchFile(
'pages/gsp.js',
`
import useSWR from 'swr'
console.log(useSWR)
export default function Home() {
return <h1>Hello</h1>
}
export async function getStaticProps() {
return {
props: {
foo: "bar",
},
};
}
`
)
await next.start()
})
it('should work correctly with output standalone', async () => {
const tmpFolder = path.join(os.tmpdir(), 'next-standalone-' + Date.now())
await fs.move(path.join(next.testDir, '.next/standalone'), tmpFolder)
let server: any
try {
const testServer = path.join(tmpFolder, 'server.js')
const appPort = await findPort()
server = await initNextServerScript(
testServer,
/- Local:/,
{
...process.env,
PORT: appPort.toString(),
},
undefined,
{
cwd: tmpFolder,
}
)
const res = await fetchViaHTTP(appPort, '/gsp')
expect(res.status).toBe(200)
} finally {
if (server) await killApp(server)
await fs.remove(tmpFolder)
}
})
})
}
import { nextTestSetup } from 'e2e-utils'
import fs from 'fs-extra'
import os from 'os'
import path from 'path'
import {
findPort,
initNextServerScript,
killApp,
fetchViaHTTP,
} from 'next-test-utils'
if (!(globalThis as any).isNextStart) {
it('should skip for non-next start', () => {})
} else {
describe('output: standalone with app dir', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipStart: true,
dependencies: {
nanoid: '4.0.1',
},
})
if (skipped) {
return
}
beforeAll(async () => {
await next.patchFile(
'next.config.js',
(await next.readFile('next.config.js')).replace('// output', 'output')
)
await next.start()
})
it('should handle trace files correctly for route groups (nodejs only)', async () => {
expect(next.cliOutput).not.toContain('Failed to copy traced files')
const serverDirPath = path.join(
next.testDir,
'.next/standalone/.next/server'
)
for (const page of [
'(newroot)/dashboard/another',
'(newroot)/dashboard/project/[projectId]',
'(rootonly)/dashboard/changelog',
]) {
const pagePath = path.join(serverDirPath, 'app', page)
expect(
await fs.pathExists(path.join(pagePath, 'page.js.nft.json'))
).toBe(true)
const files = (
await fs.readJSON(path.join(pagePath, 'page.js.nft.json'))
).files as string[]
for (const file of files) {
expect(await fs.pathExists(path.join(pagePath, file))).toBe(true)
}
}
})
it('should work correctly with output standalone', async () => {
const tmpFolder = path.join(os.tmpdir(), 'next-standalone-' + Date.now())
await fs.move(path.join(next.testDir, '.next/standalone'), tmpFolder)
let server: any
try {
const testServer = path.join(tmpFolder, 'server.js')
const appPort = await findPort()
server = await initNextServerScript(
testServer,
/- Local:/,
{
...process.env,
PORT: appPort.toString(),
},
undefined,
{
cwd: tmpFolder,
}
)
for (const testPath of [
'/',
'/api/hello',
'/blog/first',
'/dashboard',
'/dashboard/another',
'/dashboard/changelog',
'/dashboard/deployments/breakdown',
'/dashboard/deployments/123',
'/dashboard/hello',
'/dashboard/project/123',
'/catch-all/first',
]) {
const res = await fetchViaHTTP(appPort, testPath)
expect(res.status).toBe(200)
}
} finally {
if (server) await killApp(server)
await fs.remove(tmpFolder)
}
})
})
}
import { createNext } from 'e2e-utils'
import { NextInstance } from 'e2e-utils'
import { check } from 'next-test-utils'
describe('useReportWebVitals hook', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: __dirname,
skipStart: true,
env: {},
dependencies: {
nanoid: '4.0.1',
},
})
await next.start()
})
afterAll(() => next.destroy())
// Analytics events are only sent in production
it('should send web-vitals', async () => {
await next.fetch('/report-web-vitals')
let eventsCount = 0
const browser = await next.browser('/report-web-vitals', {
beforePageLoad: (page) => {
page.route('https://example.vercel.sh/vitals', (route) => {
eventsCount += 1
route.fulfill()
})
},
})
// Refresh will trigger CLS and LCP. When page loads FCP and TTFB will trigger:
await browser.refresh()
// After interaction LCP and FID will trigger
await browser.elementById('btn').click()
// Make sure all registered events in performance-relayer has fired
await check(async () => {
expect(eventsCount).toBeGreaterThanOrEqual(6)
return 'success'
}, 'success')
})
})
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