Skip to content

Commit

Permalink
Update flakey tsconfig test (#40105)
Browse files Browse the repository at this point in the history
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: #39902 (comment)
  • Loading branch information
ijjk committed Aug 30, 2022
1 parent b760c8d commit c89e25e
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions test/development/correct-tsconfig-defaults/index.test.ts
@@ -1,7 +1,5 @@
import { createNext } from 'e2e-utils'
import fs from 'fs'
import { waitFor } from 'next-test-utils'
import path from 'path'
import { check } from 'next-test-utils'
import { NextInstance } from 'test/lib/next-modes/base'

describe('correct tsconfig.json defaults', () => {
Expand All @@ -23,38 +21,46 @@ describe('correct tsconfig.json defaults', () => {
afterAll(() => next.destroy())

it('should add `moduleResolution` when generating tsconfig.json in dev', async () => {
const tsconfigPath = path.join(next.testDir, 'tsconfig.json')
expect(fs.existsSync(tsconfigPath)).toBeFalse()
try {
expect(
await next.readFile('tsconfig.json').catch(() => false)
).toBeFalse()

await next.start()
await waitFor(1000)
await next.stop()
await next.start()

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'))
expect(next.cliOutput).not.toContain('moduleResolution')
const tsconfig = JSON.parse(await next.readFile('tsconfig.json'))
expect(next.cliOutput).not.toContain('moduleResolution')

expect(tsconfig.compilerOptions).toEqual(
expect.objectContaining({ moduleResolution: 'node' })
)
expect(tsconfig.compilerOptions).toEqual(
expect.objectContaining({ moduleResolution: 'node' })
)
} finally {
await next.stop()
}
})

it('should not warn for `moduleResolution` when already present and valid', async () => {
const tsconfigPath = path.join(next.testDir, 'tsconfig.json')
expect(fs.existsSync(tsconfigPath)).toBeTrue()
try {
expect(
await next.readFile('tsconfig.json').catch(() => false)
).toBeTruthy()

await next.start()
await waitFor(1000)
await next.stop()
await next.start()

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(next.cliOutput).not.toContain('moduleResolution')
expect(tsconfig.compilerOptions).toEqual(
expect.objectContaining({ moduleResolution: 'node' })
)
expect(next.cliOutput).not.toContain('moduleResolution')
} finally {
await next.stop()
}
})
})

0 comments on commit c89e25e

Please sign in to comment.