diff --git a/packages/ng-schematics/src/schematics/utils/files.ts b/packages/ng-schematics/src/schematics/utils/files.ts index 57af65ea5e6..6828908aab7 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 8d6ae058c00..93cd07e7060 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');