Unverified Commit c89e25eb authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update flakey tsconfig test (#40105)

Updates this test to not rely on `waitFor` as the amount of time it takes to write the `tsconfig.json` can vary so we should use `check` instead. 

Fixes: https://github.com/vercel/next.js/pull/39902#issuecomment-1231939162
parent b760c8dd
import { createNext } from 'e2e-utils' import { createNext } from 'e2e-utils'
import fs from 'fs' import { check } from 'next-test-utils'
import { waitFor } from 'next-test-utils'
import path from 'path'
import { NextInstance } from 'test/lib/next-modes/base' import { NextInstance } from 'test/lib/next-modes/base'
describe('correct tsconfig.json defaults', () => { describe('correct tsconfig.json defaults', () => {
...@@ -23,38 +21,46 @@ describe('correct tsconfig.json defaults', () => { ...@@ -23,38 +21,46 @@ describe('correct tsconfig.json defaults', () => {
afterAll(() => next.destroy()) afterAll(() => next.destroy())
it('should add `moduleResolution` when generating tsconfig.json in dev', async () => { it('should add `moduleResolution` when generating tsconfig.json in dev', async () => {
const tsconfigPath = path.join(next.testDir, 'tsconfig.json') try {
expect(fs.existsSync(tsconfigPath)).toBeFalse() expect(
await next.readFile('tsconfig.json').catch(() => false)
).toBeFalse()
await next.start() await next.start()
await waitFor(1000)
await next.stop()
expect(fs.existsSync(tsconfigPath)).toBeTrue() // wait for tsconfig to be written
await check(async () => {
await next.readFile('tsconfig.json')
return 'success'
}, 'success')
const tsconfig = JSON.parse(await next.readFile('tsconfig.json')) const tsconfig = JSON.parse(await next.readFile('tsconfig.json'))
expect(next.cliOutput).not.toContain('moduleResolution') expect(next.cliOutput).not.toContain('moduleResolution')
expect(tsconfig.compilerOptions).toEqual( expect(tsconfig.compilerOptions).toEqual(
expect.objectContaining({ moduleResolution: 'node' }) expect.objectContaining({ moduleResolution: 'node' })
) )
} finally {
await next.stop()
}
}) })
it('should not warn for `moduleResolution` when already present and valid', async () => { it('should not warn for `moduleResolution` when already present and valid', async () => {
const tsconfigPath = path.join(next.testDir, 'tsconfig.json') try {
expect(fs.existsSync(tsconfigPath)).toBeTrue() expect(
await next.readFile('tsconfig.json').catch(() => false)
).toBeTruthy()
await next.start() await next.start()
await waitFor(1000)
await next.stop()
expect(fs.existsSync(tsconfigPath)).toBeTrue() const tsconfig = JSON.parse(await next.readFile('tsconfig.json'))
const tsconfig = JSON.parse(await next.readFile('tsconfig.json')) expect(tsconfig.compilerOptions).toEqual(
expect.objectContaining({ moduleResolution: 'node' })
expect(tsconfig.compilerOptions).toEqual( )
expect.objectContaining({ moduleResolution: 'node' }) expect(next.cliOutput).not.toContain('moduleResolution')
) } finally {
expect(next.cliOutput).not.toContain('moduleResolution') await next.stop()
}
}) })
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment