rsnext/test/development/correct-tsconfig-defaults/index.test.ts
Steven 8dede2a4f5
chore(test): fix flaky tsconfig.json test (#53132)
This test was [sometimes failing](

https://github.com/vercel/next.js/actions/runs/5649220907/job/15303327768?pr=53130#step:27:230)
because the `tsconfig.json` is [written as an empty
object](a26bac9604/packages/next/src/lib/typescript/writeConfigurationDefaults.ts (L123-L125)).

This PR makes sure the test waits until the tsconfig.json file is
written with the complete contents.
2023-07-24 14:33:55 -07:00

67 lines
1.8 KiB
TypeScript

import { createNext } from 'e2e-utils'
import { check } from 'next-test-utils'
import { NextInstance } from 'test/lib/next-modes/base'
describe('correct tsconfig.json defaults', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {
'pages/index.tsx': 'export default function Page() {}',
},
skipStart: true,
dependencies: {
typescript: 'latest',
'@types/react': 'latest',
'@types/node': 'latest',
},
})
})
afterAll(() => next.destroy())
it('should add `moduleResolution` when generating tsconfig.json in dev', async () => {
try {
expect(
await next.readFile('tsconfig.json').catch(() => false)
).toBeFalse()
await next.start()
let content: string
// wait for tsconfig to be written
await check(async () => {
content = await next.readFile('tsconfig.json')
return content && content !== '{}' ? 'ready' : 'retry'
}, 'ready')
const tsconfig = JSON.parse(content)
expect(next.cliOutput).not.toContain('moduleResolution')
expect(tsconfig.compilerOptions).toEqual(
expect.objectContaining({ moduleResolution: 'node' })
)
} finally {
await next.stop()
}
})
it('should not warn for `moduleResolution` when already present and valid', async () => {
try {
expect(
await next.readFile('tsconfig.json').catch(() => false)
).toBeTruthy()
await next.start()
const tsconfig = JSON.parse(await next.readFile('tsconfig.json'))
expect(tsconfig.compilerOptions).toEqual(
expect.objectContaining({ moduleResolution: 'node' })
)
expect(next.cliOutput).not.toContain('moduleResolution')
} finally {
await next.stop()
}
})
})