Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update flakey tsconfig test #40105

Merged
merged 1 commit into from Aug 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()
}
})
})