From 12b45166d745e32b195c615565b5ff78d759a975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Thu, 14 Jul 2022 14:58:28 +0200 Subject: [PATCH] add test --- .../integration/create-next-app/index.test.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/integration/create-next-app/index.test.ts b/test/integration/create-next-app/index.test.ts index 2b7ba01131b72f..1bbc3215f9e11f 100644 --- a/test/integration/create-next-app/index.test.ts +++ b/test/integration/create-next-app/index.test.ts @@ -1,6 +1,8 @@ /* eslint-env jest */ +import { execSync } from 'child_process' import execa from 'execa' import fs from 'fs-extra' +import { killApp, launchApp, findPort, waitFor } from 'next-test-utils' import os from 'os' import path from 'path' @@ -482,4 +484,38 @@ describe('create next app', () => { ) }) }) + + it.only('should add `moduleResoution` when generating tsconfig.json', async () => { + await usingTempDir(async (cwd) => { + const projectName = 'tsconfig-generation' + const res = await run([projectName], { cwd }) + expect(res.exitCode).toBe(0) + + const tsconfigPath = path.join(cwd, projectName, 'tsconfig.json') + expect(fs.existsSync(tsconfigPath)).toBeFalse() + + await execSync('pnpm add -D typescript @types/react', { + cwd: path.join(cwd, projectName), + }) + + const indexPath = path.join(cwd, projectName, 'pages', 'index.js') + await fs.rename(indexPath, indexPath.replace('.js', '.tsx')) + + const appPort = await findPort() + const app = await launchApp(path.join(cwd, projectName), appPort) + await killApp(app) + + expect(fs.existsSync(tsconfigPath)).toBeTrue() + + const tsconfig = JSON.parse( + await fs.readFile(path.join(cwd, projectName, 'tsconfig.json'), 'utf8') + ) + + expect(tsconfig.compilerOptions).toEqual( + expect.objectContaining({ + moduleResolution: 'node', + }) + ) + }) + }) })