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

Migrate create-next-app and e2e tests to Metadata API. #45819

Merged
merged 13 commits into from
Feb 23, 2023
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function GET(request) {
return new Response('Hello, Next.js!')
}
10 changes: 0 additions & 10 deletions packages/create-next-app/templates/app/js/app/head.js

This file was deleted.

10 changes: 5 additions & 5 deletions packages/create-next-app/templates/app/js/app/layout.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import './globals.css'

export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}

export default function RootLayout({ children }) {
return (
<html lang="en">
{/*
<head /> will contain the components returned by the nearest parent
head.js. Find out more at https://beta.nextjs.org/docs/api-reference/file-conventions/head
*/}
<head />
<body>{children}</body>
</html>
)
Expand Down
5 changes: 0 additions & 5 deletions packages/create-next-app/templates/app/js/pages/api/hello.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function GET(request: Request) {
return new Response('Hello, Next.js!')
}
10 changes: 0 additions & 10 deletions packages/create-next-app/templates/app/ts/app/head.tsx

This file was deleted.

10 changes: 5 additions & 5 deletions packages/create-next-app/templates/app/ts/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import './globals.css'

export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}

export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
{/*
<head /> will contain the components returned by the nearest parent
head.tsx. Find out more at https://beta.nextjs.org/docs/api-reference/file-conventions/head
*/}
<head />
<body>{children}</body>
</html>
)
Expand Down
2 changes: 1 addition & 1 deletion packages/create-next-app/templates/app/ts/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />
/// <reference types="next/navigation-types/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
13 changes: 0 additions & 13 deletions packages/create-next-app/templates/app/ts/pages/api/hello.ts

This file was deleted.

10 changes: 5 additions & 5 deletions test/e2e/app-dir/create-next-app-template/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import './globals.css'

export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}

export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</head>
<body>{children}</body>
</html>
)
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion test/e2e/app-dir/rsc-basic/rsc-basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('app dir - rsc basics', () => {

// should have only 1 DOCTYPE
expect(homeHTML).toMatch(/^<!DOCTYPE html><html/)
// should have default head when there's no head.js provided
// should have default metadata when there's nothing additional provided
expect(homeHTML).toContain('<meta charSet="utf-8"/>')
expect(homeHTML).toContain(
'<meta name="viewport" content="width=device-width, initial-scale=1"/>'
Expand Down
6 changes: 2 additions & 4 deletions test/integration/create-next-app/lib/specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ export const projectSpecification: ProjectSpecification = {
devDeps: [],
files: [
'app/page.js',
'app/head.js',
'app/layout.js',
'pages/api/hello.js',
'app/api/hello/route.js',
'jsconfig.json',
],
},
Expand All @@ -73,9 +72,8 @@ export const projectSpecification: ProjectSpecification = {
devDeps: [],
files: [
'app/page.tsx',
'app/head.tsx',
'app/layout.tsx',
'pages/api/hello.ts',
'app/api/hello/route.ts',
'tsconfig.json',
'next-env.d.ts',
],
Expand Down
33 changes: 22 additions & 11 deletions test/integration/create-next-app/templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import { getPkgPaths } from '../../../test/lib/create-next-install'

const startsWithoutError = async (
appDir: string,
modes = ['default', 'turbo']
modes = ['default', 'turbo'],
usingAppDirectory: boolean = false
) => {
for (const mode of modes) {
appDir = await fs.realpath(appDir)
Expand All @@ -42,7 +43,11 @@ const startsWithoutError = async (

const apiRes = await fetchViaHTTP(appPort, '/api/hello')
expect(apiRes.status).toBe(200)
expect(await apiRes.json()).toEqual({ name: 'John Doe' })
if (usingAppDirectory) {
expect(await apiRes.text()).toEqual('Hello, Next.js!')
} else {
expect(await apiRes.json()).toEqual({ name: 'John Doe' })
}
} finally {
await killApp(app)
}
Expand Down Expand Up @@ -336,7 +341,11 @@ describe('create-next-app --experimental-app-dir', () => {
const exitCode = await spawnExitPromise(childProcess)
expect(exitCode).toBe(0)
shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'ts' })
await startsWithoutError(path.join(cwd, projectName))
await startsWithoutError(
path.join(cwd, projectName),
['default', 'turbo'],
true
)
})
})

Expand All @@ -362,10 +371,11 @@ describe('create-next-app --experimental-app-dir', () => {
expect(exitCode).toBe(0)
shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'js' })
// is landed
await startsWithoutError(path.join(cwd, projectName), [
'default',
'turbo',
])
await startsWithoutError(
path.join(cwd, projectName),
['default', 'turbo'],
true
)
})
})

Expand Down Expand Up @@ -397,10 +407,11 @@ describe('create-next-app --experimental-app-dir', () => {
mode: 'js',
srcDir: true,
})
await startsWithoutError(path.join(cwd, projectName), [
'default',
'turbo',
])
await startsWithoutError(
path.join(cwd, projectName),
['default', 'turbo'],
true
)
})
})
})