Skip to content

Commit

Permalink
Update tests for Turbopack
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Nov 7, 2024
1 parent 9e4c143 commit e856540
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 100 deletions.
54 changes: 38 additions & 16 deletions test/e2e/edge-pages-support/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,44 @@ describe('edge-render-getserversideprops', () => {
if ((global as any).isNextStart) {
it('should not output trace files for edge routes', async () => {
expect(await fs.pathExists(join(next.testDir, '.next/pages'))).toBe(false)
expect(
await fs.pathExists(join(next.testDir, '.next/server/pages/[id].js'))
).toBe(true)
expect(
await fs.pathExists(
join(next.testDir, '.next/server/pages/[id].js.nft.json')
)
).toBe(false)
expect(
await fs.pathExists(join(next.testDir, '.next/server/pages/index.js'))
).toBe(true)
expect(
await fs.pathExists(
join(next.testDir, '.next/server/pages/index.js.nft.json')
)
).toBe(false)
if (process.env.TURBOPACK) {
expect(
await fs.pathExists(
join(
next.testDir,
'.next/server/pages/[id]/middleware-manifest.json'
)
)
).toBe(true)
} else {
expect(
await fs.pathExists(join(next.testDir, '.next/server/pages/[id].js'))
).toBe(true)
expect(
await fs.pathExists(
join(next.testDir, '.next/server/pages/[id].js.nft.json')
)
).toBe(false)
}
if (process.env.TURBOPACK) {
expect(
await fs.pathExists(
join(
next.testDir,
'.next/server/pages/index/middleware-manifest.json'
)
)
).toBe(true)
} else {
expect(
await fs.pathExists(join(next.testDir, '.next/server/pages/index.js'))
).toBe(true)
expect(
await fs.pathExists(
join(next.testDir, '.next/server/pages/index.js.nft.json')
)
).toBe(false)
}
})
}

Expand Down
36 changes: 26 additions & 10 deletions test/e2e/og-api/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,32 @@ describe('og-api', () => {
it('should copy files correctly', async () => {
expect(next.cliOutput).not.toContain('Failed to copy traced files')

expect(
await fs.pathExists(
join(next.testDir, '.next/standalone/.next/server/pages/api/og.js')
)
).toBe(true)
expect(
await fs.pathExists(
join(next.testDir, '.next/standalone/.next/server/edge-chunks')
)
).toBe(true)
if (process.env.TURBOPACK) {
expect(
await fs.pathExists(
join(
next.testDir,
'.next/standalone/.next/server/pages/api/og/middleware-manifest.json'
)
)
).toBe(true)
expect(
await fs.pathExists(
join(next.testDir, '.next/standalone/.next/server/edge/chunks')
)
).toBe(true)
} else {
expect(
await fs.pathExists(
join(next.testDir, '.next/standalone/.next/server/pages/api/og.js')
)
).toBe(true)
expect(
await fs.pathExists(
join(next.testDir, '.next/standalone/.next/server/edge-chunks')
)
).toBe(true)
}
})
}

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/prerender-native-module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('prerender native module', () => {
{
page: '/_app',
tests: [
/webpack-runtime\.js/,
/(webpack-runtime\.js|\[turbopack\]_runtime\.js)/,
/node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/,
isReact18
Expand All @@ -81,7 +81,7 @@ describe('prerender native module', () => {
{
page: '/blog/[slug]',
tests: [
/webpack-runtime\.js/,
/(webpack-runtime\.js|\[turbopack\]_runtime\.js)/,
/node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/,
isReact18
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/prerender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,7 @@ describe('Prerender', () => {
{
page: '/_app',
tests: [
/webpack-runtime\.js/,
/(webpack-runtime\.js|\[turbopack\]_runtime\.js)/,
/node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/,
isReact18
Expand All @@ -2129,7 +2129,7 @@ describe('Prerender', () => {
{
page: '/another',
tests: [
/webpack-runtime\.js/,
/(webpack-runtime\.js|\[turbopack\]_runtime\.js)/,
/chunks\/.*?\.js/,
/node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/,
Expand All @@ -2146,7 +2146,7 @@ describe('Prerender', () => {
{
page: '/blog/[post]',
tests: [
/webpack-runtime\.js/,
/(webpack-runtime\.js|\[turbopack\]_runtime\.js)/,
/chunks\/.*?\.js/,
/node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/,
Expand Down
13 changes: 9 additions & 4 deletions test/e2e/streaming-ssr/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,15 @@ if (isNextProd) {
next.destroy()
})

it('should pass correct nextRuntime values', async () => {
const content = await next.readFile('runtimes.txt')
expect(content.split('\n').sort()).toEqual(['client', 'edge', 'nodejs'])
})
// Relies on the custom webpack config above
;(process.env.TURBOPACK ? it.skip : it)(
'should pass correct nextRuntime values',
async () => {
const content = await next.readFile('runtimes.txt')
// eslint-disable-next-line jest/no-standalone-expect
expect(content.split('\n').sort()).toEqual(['client', 'edge', 'nodejs'])
}
)

it('should generate html response by streaming correctly', async () => {
const html = await renderViaHTTP(next.url, '/')
Expand Down
2 changes: 1 addition & 1 deletion test/integration/dist-dir/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('distDir', () => {
})
await fs.writeFile(nextConfig, origNextConfig)

expect(stderr.length).toBe(0)
expect(stderr).toBeEmpty()
})
}
)
Expand Down
13 changes: 8 additions & 5 deletions test/production/pages-dir/production/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('Production Usage', () => {
{
page: '/_app',
tests: [
/webpack-runtime\.js/,
/(webpack-runtime\.js|\[turbopack\]_runtime\.js)/,
/node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/,
isReact18
Expand All @@ -192,7 +192,7 @@ describe('Production Usage', () => {
{
page: '/client-error',
tests: [
/webpack-runtime\.js/,
/(webpack-runtime\.js|\[turbopack\]_runtime\.js)/,
/chunks\/.*?\.js/,
/node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/,
Expand All @@ -206,7 +206,7 @@ describe('Production Usage', () => {
{
page: '/index',
tests: [
/webpack-runtime\.js/,
/(webpack-runtime\.js|\[turbopack\]_runtime\.js)/,
/chunks\/.*?\.js/,
/node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/,
Expand All @@ -223,7 +223,7 @@ describe('Production Usage', () => {
{
page: '/next-import',
tests: [
/webpack-runtime\.js/,
/(webpack-runtime\.js|\[turbopack\]_runtime\.js)/,
/chunks\/.*?\.js/,
/node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/,
Expand All @@ -242,7 +242,10 @@ describe('Production Usage', () => {
},
{
page: '/api',
tests: [/webpack-runtime\.js/, /\/logo\.module\.css/],
tests: [
/(webpack-runtime\.js|\[turbopack\]_runtime\.js)/,
/\/logo\.module\.css/,
],
notTests: [
/next\/dist\/server\/next\.js/,
/next\/dist\/bin/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,17 @@ describe('required server files', () => {
})
})

it('should warn when "next" is imported directly', async () => {
await renderViaHTTP(appPort, '/gssp')
await check(
() => stderr,
/"next" should not be imported directly, imported in/
)
})
// TODO(mischnic) do we still want to do this?
;(process.env.TURBOPACK ? it.skip : it)(
'should warn when "next" is imported directly',
async () => {
await renderViaHTTP(appPort, '/gssp')
await check(
() => stderr,
/"next" should not be imported directly, imported in/
)
}
)

it('`compress` should be `false` in nextEnv', async () => {
expect(
Expand All @@ -330,18 +334,24 @@ describe('required server files', () => {
).toContain('"cacheMaxMemorySize":0')
})

it('should output middleware correctly', async () => {
expect(
await fs.pathExists(
join(next.testDir, 'standalone/.next/server/edge-runtime-webpack.js')
)
).toBe(true)
expect(
await fs.pathExists(
join(next.testDir, 'standalone/.next/server/middleware.js')
)
).toBe(true)
})
// TODO(mischnic) do these files even exist in turbopack?
;(process.env.TURBOPACK ? it.skip : it)(
'should output middleware correctly',
async () => {
// eslint-disable-next-line jest/no-standalone-expect
expect(
await fs.pathExists(
join(next.testDir, 'standalone/.next/server/edge-runtime-webpack.js')
)
).toBe(true)
// eslint-disable-next-line jest/no-standalone-expect
expect(
await fs.pathExists(
join(next.testDir, 'standalone/.next/server/middleware.js')
)
).toBe(true)
}
)

it('should output required-server-files manifest correctly', async () => {
expect(requiredFilesManifest.version).toBe(1)
Expand Down Expand Up @@ -1293,9 +1303,15 @@ describe('required server files', () => {
expect(res.status).toBe(200)
expect(await res.text()).toContain('index page')

expect(
fs.existsSync(join(standaloneDir, '.next/server/edge-chunks'))
).toBe(true)
if (process.env.TURBOPACK) {
expect(
fs.existsSync(join(standaloneDir, '.next/server/edge/chunks'))
).toBe(true)
} else {
expect(
fs.existsSync(join(standaloneDir, '.next/server/edge-chunks'))
).toBe(true)
}

const resImageResponse = await fetchViaHTTP(
appPort,
Expand Down
Loading

0 comments on commit e856540

Please sign in to comment.