Repository navigation
Description
Which @angular/* package(s) are the source of the bug?
@angular/cli I believe
Is this a regression?
Yes
Description
Our angular projects use both jest tests and karma tests. To distinguish them while running, we use *.spec.ts for jest tests, and *.karma-spec.ts for karma tests. This was fine up until we upgraded to angular 15 - now there's no longer an obvious way to only load and run files with the *.karma-spec.ts suffix.
Previously we used code like the following in our test.ts file:
declare const require: {
context(path: string, deep?: boolean, filter?: RegExp): {
keys(): string[];
<T>(id: string): T;
};
};
...
// Find all the tests.
const context = require.context('../../', true, /\.karma-spec\.ts$/);
// And load the modules.
context.keys().map(context);This code was removed by the migration, but I don't see a documented config option for the suffix. Any suggestions?
Please provide a link to a minimal reproduction of the bug
[email protected]:johncrim/ng-jest-starter.git
Please provide the exception or error you saw
To reproduce:
git clone [email protected]:johncrim/ng-jest-starter.git
yarn # Installs ng 14 dependencies
yarn test # Runs jest tests
yarn karma:headless # Runs karma testsAt this point, things work as expected. Then update to ng 15*, and try running the tests:
yarn ng update @angular/core@15 @angular/cli@15
yarn test # Still works
yarn karma:headless # Fails with error below
...
./libs/ui-lib/src/lib/ui-lib.component.spec.ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Error: ng-jest-starter\libs\ui-lib\src\lib\ui-lib.component.spec.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
...*Note that the ng update fails on the Update TypeScript compiler 'target' and set 'useDefineForClassFields'. migration. This is irrelevant, but you can add "useDefineForClassFields": false to the tsconfig.base.json file.
Please provide the environment you discovered this bug in (run ng version)
> yarn ng version
Node.js version v19.3.0 detected.
Odd numbered Node.js versions will not enter LTS status and should not be used for production. For more information, please see https://nodejs.org/en/about/releases/.
Angular CLI: 15.0.4
Node: 19.3.0 (Unsupported)
Package Manager: yarn 3.2.4
OS: win32 x64
Angular: 15.0.4
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1500.4
@angular-devkit/build-angular 15.0.4
@angular-devkit/core 15.0.4
@angular-devkit/schematics 15.0.4
@angular/cdk 15.0.3
@schematics/angular 15.0.4
ng-packagr 15.0.3
rxjs 7.5.7
typescript 4.8.4
webpack 5.74.0Anything else?
No response
Activity
clydin commentedon Dec 27, 2022
The
includeoption is now used to determine the set of tests to include and execute. By default this option uses["**/*.spec.ts"]but can be changed to reflect the specific requirements of a project. In this case, changing it to["**/*.karma-spec.ts"]should provide the expected behavior.If you are still encountering issues after adjusting the
includeoption, please let us know.johncrim commentedon Jan 3, 2023
That solves it - thank you for the help @clydin .
chore(dependencies): Upgrade @angular/cli to 15
angular-automatic-lock-bot commentedon Feb 3, 2023
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.