From 1b2d920fe638f3aad704ab8f21d1e4f4099b6d44 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Mon, 13 Nov 2023 14:20:18 +0100 Subject: [PATCH] fix: multi-app project extend root `tsconfig.json` (#11374) --- .../src/schematics/utils/files.ts | 15 +++++++++-- .../ng-schematics/test/src/ng-add.spec.ts | 26 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/packages/ng-schematics/src/schematics/utils/files.ts b/packages/ng-schematics/src/schematics/utils/files.ts index 57af65ea..6828908a 100644 --- a/packages/ng-schematics/src/schematics/utils/files.ts +++ b/packages/ng-schematics/src/schematics/utils/files.ts @@ -111,10 +111,21 @@ function getProjectBaseUrl(project: any, port: number): string { } function getTsConfigPath(project: AngularProject): string { + const filename = 'tsconfig.json'; + if (!project.root) { - return '../tsconfig.json'; + return `../${filename}`; } - return `../tsconfig.app.json`; + + const nested = project.root + .split('/') + .map(() => { + return '../'; + }) + .join(''); + + // Prepend a single `../` as we put the test inside `e2e` folder + return `../${nested}${filename}`; } export function addCommonFiles( diff --git a/packages/ng-schematics/test/src/ng-add.spec.ts b/packages/ng-schematics/test/src/ng-add.spec.ts index 8d6ae058..93cd07e7 100644 --- a/packages/ng-schematics/test/src/ng-add.spec.ts +++ b/packages/ng-schematics/test/src/ng-add.spec.ts @@ -93,6 +93,19 @@ describe('@puppeteer/ng-schematics: ng-add', () => { expect(tree.files).toContain('/e2e/tests/app.test.ts'); expect(options['testRunner']).toBe('node'); }); + it('should create TypeScript files', async () => { + const tree = await buildTestingTree('ng-add', 'single'); + const tsConfigPath = '/e2e/tsconfig.json'; + const tsConfig = tree.readJson(tsConfigPath); + + expect(tree.files).toContain(tsConfigPath); + expect(tsConfig).toMatchObject({ + extends: '../tsconfig.json', + compilerOptions: { + module: 'CommonJS', + }, + }); + }); it('should not create port value', async () => { const tree = await buildTestingTree('ng-add'); @@ -193,6 +206,19 @@ describe('@puppeteer/ng-schematics: ng-add', () => { ); expect(options['testRunner']).toBe('node'); }); + it('should create TypeScript files', async () => { + const tree = await buildTestingTree('ng-add', 'multi'); + const tsConfigPath = getMultiApplicationFile('e2e/tsconfig.json'); + const tsConfig = tree.readJson(tsConfigPath); + + expect(tree.files).toContain(tsConfigPath); + expect(tsConfig).toMatchObject({ + extends: '../../../tsconfig.json', + compilerOptions: { + module: 'CommonJS', + }, + }); + }); it('should not create port value', async () => { const tree = await buildTestingTree('ng-add');