File size: 1,812 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
import { createNext } from 'e2e-utils'
import { check } from 'next-test-utils'
import { NextInstance } from 'e2e-utils'
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()
}
})
})
|