From 66779942358e6faf43f6311e5c59fced3e793e46 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 20 Jun 2022 07:10:37 +0000 Subject: [PATCH] fix(@angular-devkit/build-angular): fix incorrect glob cwd in karma when using `--include` option Previously, we amended the project source root to the source root which resulted in an invalid path. Closes #23396 --- .../build_angular/src/builders/karma/index.ts | 10 ++-------- tests/legacy-cli/e2e/tests/test/test-include-glob.ts | 5 +++++ 2 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 tests/legacy-cli/e2e/tests/test/test-include-glob.ts diff --git a/packages/angular_devkit/build_angular/src/builders/karma/index.ts b/packages/angular_devkit/build_angular/src/builders/karma/index.ts index 06db2f6e23df..db58042a8406 100644 --- a/packages/angular_devkit/build_angular/src/builders/karma/index.ts +++ b/packages/angular_devkit/build_angular/src/builders/karma/index.ts @@ -118,14 +118,8 @@ export function execute( } const projectMetadata = await context.getProjectMetadata(projectName); - const projectRoot = path.join( - context.workspaceRoot, - (projectMetadata.root as string | undefined) ?? '', - ); - const projectSourceRoot = path.join( - projectRoot, - (projectMetadata.sourceRoot as string | undefined) ?? '', - ); + const sourceRoot = (projectMetadata.sourceRoot ?? projectMetadata.root ?? '') as string; + const projectSourceRoot = path.join(context.workspaceRoot, sourceRoot); const files = await findTests(options.include, context.workspaceRoot, projectSourceRoot); // early exit, no reason to start karma diff --git a/tests/legacy-cli/e2e/tests/test/test-include-glob.ts b/tests/legacy-cli/e2e/tests/test/test-include-glob.ts new file mode 100644 index 000000000000..5dc55edbf8c7 --- /dev/null +++ b/tests/legacy-cli/e2e/tests/test/test-include-glob.ts @@ -0,0 +1,5 @@ +import { ng } from '../../utils/process'; + +export default async function () { + await ng('test', '--no-watch', `--include='**/*.spec.ts'`); +}