Open Draginfable opened 3 months ago
We are facing the same issue for a monorepo project.
here is the folder structure
workspace |-- projects | |-- scopeA | | |-- lib1 | | | |-- tsconfig.spec.json | | | |-- src | | | |-- lib | | | |-- lib1.component.spec.ts | | |--lib2 | | |-- tsconfig.spec.json | | |-- src | | |-- lib | | |-- lib2.component.spec.ts | |-- app | | |-- tsconfig.spec.json
This is what i found regarding this issue.
When I am running ng test
, it will grab tsconfig.spec.json
from one of the libs folder. And then apply the settings in the tsconfig.spec.json
on all the .spec.ts
files in the whole workspace folder. Because the tsconfig.spec.json
only includes the spec.ts
files in its folder, that's why we are getting File 'projects/my-app/src/app/app.component.spec.ts' is missing from the TypeScript compilation. [plugin angular-compiler]
error
When I am running ng test @scopeA/lib1
, it will grab the tsconfig.spec.json
from projects/scopeA/lib1
. but it will also grab all the .spec.ts
files from all the folders in workspace
folder. like lib1.component.spec.ts
, lib2.component.spec.ts
. since the tsconfig.spec.json
is not including the spec.ts
files from lib2
. it's throwing the same error.
When running ng test
, it should fetch tsconfig options for each library, instead of 1 tsconfig options for all the libraries. The issue is at angular-cli/packages/angular-devkit/build_angular/src/builders/web-test-runner/index.ts
line 45 const options = normalizeOptions(schema);
When running ng test @scopeA/lib1
, the issue is at angular-cli/packages/angular_devkit/build_angular/src/builders/web-test-runner/index.ts
line 52 findTestFiles(options.include, options.exclude, ctx.workspaceRoot)
the folder it should be searching for test files inside ./workspace/projects/scopeA/lib1
instead of ./workspace
. ctx.workspaceRoot
is incorrect here
Hopefully these findings can speed up the fix of this issue.
PS1: I tried to fix the issue, and it was able to pick up the correct tsconfig
and test files. but the build failed. and there is insufficient details on the build failed error. Thus I was not able to dig further.
PS2: if you wanna try out web-test-runner
without waiting for a patch, you can modify the include property in scopeA/lib1/tsconfig.spec.ts
like this
"include": [
"**/*.spec.ts",
"**/*.d.ts",
"../**/*.spec.ts",
"../**/*.d.ts",
"../../**/*.spec.ts",
"../../**/*.d.ts"
]
and run ng test @scopeA/lib1
, it should run the tests against all the test files in projects
folder without the error.
Command
test
Is this a regression?
The previous version in which this bug was not present was
No response
Description
If you create a new angular app with two projects, and try to run the unit tests using web-test-runner, the spec files cannot be located.
Minimal Reproduction
Create a new angular app with two projects.
Use the web-test-runner
npm install @web/test-runner -D
Replace@angular-devkit/build-angular:karma
by@angular-devkit/build-angular:web-test-runner
in angular.jsonRune the unit tests
ng test
Exception or Error
Your Environment
Anything else relevant?
No response