Skip to content

Commit a9da887

Browse files
devjiwonchoieps1lon
andcommitted
simplify and add file name to expect know when failed
Co-authored-by: Sebastian "Sebbie" Silbermann <sebastian.silbermann@vercel.com>
1 parent 2e49906 commit a9da887

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

test/development/typescript-plugin/metadata/warn-no-type.test.ts

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import type { PluginLanguageService } from '../test-utils'
2+
3+
import { join } from 'node:path'
24
import {
35
getPluginLanguageService,
46
getTsFiles,
57
NEXT_TS_ERRORS,
68
} from '../test-utils'
7-
import { join } from 'path'
89

910
const fixturesDir = join(__dirname, 'app/warn-no-type')
1011

@@ -21,7 +22,7 @@ describe('typescript-plugin - metadata - warn-no-type', () => {
2122

2223
for (const tsFile of tsFiles) {
2324
const diagnostics = languageService.getSemanticDiagnostics(tsFile)
24-
expect(diagnostics.length).toBe(0)
25+
expect({ diagnostics, tsFile }).toEqual({ diagnostics: [], tsFile })
2526
}
2627
})
2728

@@ -31,7 +32,7 @@ describe('typescript-plugin - metadata - warn-no-type', () => {
3132

3233
for (const tsFile of tsFiles) {
3334
const diagnostics = languageService.getSemanticDiagnostics(tsFile)
34-
expect(diagnostics.length).toBe(0)
35+
expect({ diagnostics, tsFile }).toEqual({ diagnostics: [], tsFile })
3536
}
3637
})
3738

@@ -41,16 +42,18 @@ describe('typescript-plugin - metadata - warn-no-type', () => {
4142

4243
for (const tsFile of tsFiles) {
4344
const diagnostics = languageService.getSemanticDiagnostics(tsFile)
44-
expect(diagnostics.length).toBe(1)
4545

46-
const diagnostic = diagnostics[0]
47-
expect(diagnostic).toMatchObject({
48-
code: NEXT_TS_ERRORS.INVALID_METADATA_EXPORT,
49-
messageText:
50-
'The Next.js "metadata" export should be type of "Metadata" from "next".',
51-
// Use lastIndexOf to match export { ... }
52-
start: diagnostic.file.getFullText().lastIndexOf('metadata'),
53-
length: 'metadata'.length,
46+
expect({ diagnostics, tsFile }).toEqual({
47+
diagnostics: [
48+
expect.objectContaining({
49+
code: NEXT_TS_ERRORS.INVALID_METADATA_EXPORT,
50+
messageText:
51+
'The Next.js "metadata" export should be type of "Metadata" from "next".',
52+
start: diagnostics[0].file.getFullText().lastIndexOf('metadata'),
53+
length: 'metadata'.length,
54+
}),
55+
],
56+
tsFile,
5457
})
5558
}
5659
})
@@ -61,17 +64,21 @@ describe('typescript-plugin - metadata - warn-no-type', () => {
6164

6265
for (const tsFile of tsFiles) {
6366
const diagnostics = languageService.getSemanticDiagnostics(tsFile)
64-
expect(diagnostics.length).toBe(1)
65-
66-
const diagnostic = diagnostics[0]
6767
const type = tsFile.includes('-async-') ? 'Promise<Metadata>' : 'Metadata'
6868

69-
expect(diagnostic).toMatchObject({
70-
code: NEXT_TS_ERRORS.INVALID_METADATA_EXPORT,
71-
messageText: `The Next.js "generateMetadata" export should have a return type of "${type}" from "next".`,
72-
// Use lastIndexOf to match export { ... }
73-
start: diagnostic.file.getFullText().lastIndexOf('generateMetadata'),
74-
length: 'generateMetadata'.length,
69+
expect({ diagnostics, tsFile }).toEqual({
70+
diagnostics: [
71+
expect.objectContaining({
72+
code: NEXT_TS_ERRORS.INVALID_METADATA_EXPORT,
73+
messageText: `The Next.js "generateMetadata" export should have a return type of "${type}" from "next".`,
74+
// Use lastIndexOf to match export { ... }
75+
start: diagnostics[0].file
76+
.getFullText()
77+
.lastIndexOf('generateMetadata'),
78+
length: 'generateMetadata'.length,
79+
}),
80+
],
81+
tsFile,
7582
})
7683
}
7784
})

0 commit comments

Comments
 (0)