From b9c874f25e40d1bf1a167cbfed31dce146734aa6 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 30 Aug 2022 10:17:13 -0700 Subject: [PATCH] Update flakey tsconfig test --- .../correct-tsconfig-defaults/index.test.ts | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/test/development/correct-tsconfig-defaults/index.test.ts b/test/development/correct-tsconfig-defaults/index.test.ts index 70b8b51fee62..45ce6c521dec 100644 --- a/test/development/correct-tsconfig-defaults/index.test.ts +++ b/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', () => { @@ -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() + } }) })