Skip to content

Commit 0625d0d

Browse files
authored
[ts-next-plugin] test: add metadata warn no type test (#78505)
### Why? This PR initiates the migration of manual testing of the Next.js TypeScript plugin to an automated language service plugin test. It replaced the existing metadata `missing-type-warning` fixture with the `warn-no-type` test (naming for consistency, such as future `error-on-client`). ### Testing Plan This PR adds the tests and fixtures for the metadata plugin to **warn when no type is provided** for metadata config exports (`metadata` and `generateMetadata`). 1. The fixtures are tested into two categories: 1) "**has type**": expects no warning, and 2) "**no type**": expects a warning. 2. For "has type", the types are from `next` or custom. 3. Each section consists of inline exports and separate exports (`export { ... }`). 4. For the fixtures of `generateMetadata`, it is divided into a function, an arrow function, and a function expression divided with sync and async. <details><summary>Structure Details</summary> <p> #### `metadata` ``` . ├── has-type/ │ ├── export-inline/ │ │ ├── from-next │ │ └── from-others │ └── export-separate/ │ ├── from-next │ └── from-others └── no-type/ ├── export-inline └── export-separate ``` #### `gerenateMetadata` ``` . ├── has-type/ │ ├── export-inline/ │ │ ├── from-next/ │ │ │ ├── async/ │ │ │ │ ├── arrow-function │ │ │ │ ├── function-declaration │ │ │ │ └── function-expression │ │ │ └── sync/ │ │ │ ├── arrow-function │ │ │ ├── function-declaration │ │ │ └── function-expression │ │ └── from-others/ │ │ ├── async/ │ │ │ └── ... │ │ └── sync/ │ │ └── ... │ └── export-separate/ │ ├── from-next/ │ │ ├── async/ │ │ │ └── ... │ │ └── sync/ │ │ └── ... │ └── from-others/ │ ├── async/ │ │ └── ... │ └── sync/ │ └── ... └── no-type/ ├── export-inline/ │ ├── async/ │ │ └── ... │ └── sync/ │ └── ... └── export-separate/ ├── async/ │ └── ... └── sync/ └── ... ``` </p> </details> ### Follow Up The metadata currently has one more feature: an error when using metadata exports within Client Components.
1 parent 34c5d41 commit 0625d0d

File tree

89 files changed

+1335
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1335
-16
lines changed

packages/next/src/server/typescript/rules/metadata.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const metadata = {
9595
file: source,
9696
category: ts.DiagnosticCategory.Warning,
9797
code: NEXT_TS_ERRORS.INVALID_METADATA_EXPORT,
98-
messageText: `The "generateMetadata" export should have a return type of ${isAsync ? '"Promise<Metadata>"' : '"Metadata"'} from "next".`,
98+
messageText: `The Next.js "generateMetadata" export should have a return type of ${isAsync ? '"Promise<Metadata>"' : '"Metadata"'} from "next".`,
9999
start: node.name.getStart(),
100100
length: node.name.getWidth(),
101101
},
@@ -135,7 +135,7 @@ const metadata = {
135135
file: source,
136136
category: ts.DiagnosticCategory.Warning,
137137
code: NEXT_TS_ERRORS.INVALID_METADATA_EXPORT,
138-
messageText: `The "generateMetadata" export should have a return type of ${isAsync ? '"Promise<Metadata>"' : '"Metadata"'} from "next".`,
138+
messageText: `The Next.js "generateMetadata" export should have a return type of ${isAsync ? '"Promise<Metadata>"' : '"Metadata"'} from "next".`,
139139
start: declaration.name.getStart(),
140140
length: declaration.name.getWidth(),
141141
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!tsconfig.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Metadata } from 'next'
2+
3+
export default function Layout({ children }: { children: React.ReactNode }) {
4+
return <>{children}</>
5+
}
6+
7+
export const generateMetadata = async (): Promise<Metadata> => {
8+
return {
9+
title: 'Generate Metadata',
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Metadata } from 'next'
2+
3+
export default function Page() {
4+
return <p>hello world</p>
5+
}
6+
7+
export const generateMetadata = async (): Promise<Metadata> => {
8+
return {
9+
title: 'Generate Metadata',
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Metadata } from 'next'
2+
3+
export default function Layout({ children }: { children: React.ReactNode }) {
4+
return <>{children}</>
5+
}
6+
7+
export const generateMetadata = async function (): Promise<Metadata> {
8+
return {
9+
title: 'Generate Metadata',
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Metadata } from 'next'
2+
3+
export default function Page() {
4+
return <p>hello world</p>
5+
}
6+
7+
export const generateMetadata = async function (): Promise<Metadata> {
8+
return {
9+
title: 'Generate Metadata',
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Metadata } from 'next'
2+
3+
export default function Layout({ children }: { children: React.ReactNode }) {
4+
return <>{children}</>
5+
}
6+
7+
export async function generateMetadata(): Promise<Metadata> {
8+
return {
9+
title: 'Generate Metadata',
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Metadata } from 'next'
2+
3+
export default function Page() {
4+
return <p>hello world</p>
5+
}
6+
7+
export async function generateMetadata(): Promise<Metadata> {
8+
return {
9+
title: 'Generate Metadata',
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Metadata } from 'next'
2+
3+
export default function Layout({ children }: { children: React.ReactNode }) {
4+
return <>{children}</>
5+
}
6+
7+
export const generateMetadata = (): Metadata => {
8+
return {
9+
title: 'Generate Metadata',
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Metadata } from 'next'
2+
3+
export default function Page() {
4+
return <p>hello world</p>
5+
}
6+
7+
export const generateMetadata = (): Metadata => {
8+
return {
9+
title: 'Generate Metadata',
10+
}
11+
}

0 commit comments

Comments
 (0)