Repository navigation
Closed
Labels
area: @angular-devkit/build-angulardevkit/build-angular:karmafreq1: lowOnly reported by a handful of users who observe it rarelyseverity5: regression
Description
Which @angular/* package(s) are the source of the bug?
Don't known / other
Is this a regression?
Yes
Description
I'm working on an old angular project and the folder structure is a bit different from what's in angular documentation.
After upgrading to Angular 15 karma/jasmine unit tests are failing to run.
Project structure:

Karma config:
module.exports = function (config) {
config.set({
basePath: '..',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-phantomjs-launcher'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('karma-spec-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/testapp'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['spec'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadless'],
singleRun: true,
restartOnFileChange: true
});
};
When I run UTs I get an error:

When running it with debug logging found:

Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Error: Specified patterns: "**/*.spec.ts" did not match any spec files.
Please provide the environment you discovered this bug in (run ng version)
Angular: 15.0.4
Works on angular 14.2.4
Anything else?
No response
Metadata
Metadata
Assignees
Labels
area: @angular-devkit/build-angulardevkit/build-angular:karmafreq1: lowOnly reported by a handful of users who observe it rarelyseverity5: regression
Activity
clydin commentedon Dec 27, 2022
From the debug logging shown above it appears that the
projectSourceRootcontains an additionalwwwdirectory segment. This may indicate that the project as defined within theangular.jsonfile has a misconfiguredrootand/orsourceRootfield. Can you provide the values assigned to each for the project encountering the issue? Based on the directory structure shown, both therootandsourceRootfields should probably be""(or the equivalent,".").mivanyna commentedon Dec 27, 2022
It is and was www for

sourceRoot:And this used to work.
clydin commentedon Dec 27, 2022
In v15, the test files are discovered based on the
includeoption which defaults to["**/*.spec.ts"]and uses thesourceRootas the base directory to search. This change removed the need to use Webpack specific features within thetest.tsfile and provides the capability to more easily control test execution from the command line. The reason this no longer works in this project is that thesourceRootdirectory ofwwwdoes not appear to exist. All paths within theangular.jsonfile are relative to the location of theangular.jsonfile. ChangingsourceRootto""should alleviate the issue.mivanyna commentedon Dec 27, 2022
I'll check tomorrow, will it impact project building as it seems to depend on those values too?
mivanyna commentedon Dec 28, 2022
It works except
excludein Karma config(and files seems to be ignored):Previously I had a logic to exclude integration tests (which ends with 'client.spec.ts') in test.ts:
Now, there is an issue that those tests are included and
excludefilter doesn't work to filter them out.If I'm adding that exclude to
tsconfig.spec.jsongetting errors:Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
.client.spec.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
mivanyna commentedon Jan 3, 2023
@clydin could you please help me with this?
johncrim commentedon Jan 4, 2023
@mivanyna - try moving the exclude to your tsconfig.spec.json (or whatever it may be called).
@clydin - thank you for the pointer. We were also bitten by the fact that we had incorrect
sourceRootpaths in theangular.json- eg"sourceRoot": "libs/util/src"when it should have been"sourceRoot": "libs/util"; this previously wasn't causing any problems, but after upgrading to ng 15, and after the fix you pointed us to in #24471, it was causingError: Specified patterns: "**/*.karma-spec.ts" did not match any spec files.It took me a while to find that cause, I wish I had read your comments above when I was trying to solve that problem.A general approach I use for solving difficult-to-debug project configuration issues is to generate a new workspace and projects using the latest version of angular, customize it to approximate the broken project and get it working, and then diff that project with the broken upgraded project and iterate to find the issue. Then you'll either find the solution or find a repro case that can be shared.
mivanyna commentedon Jan 4, 2023
@johncrim I have specified already that getting another error
fix(@angular-devkit/build-angular): provide an option to `exclude` sp…
fix(@angular-devkit/build-angular): provide an option to `exclude` sp…
fix(@angular-devkit/build-angular): provide an option to `exclude` sp…
fix(@angular-devkit/build-angular): provide an option to `exclude` sp…
fix(@angular-devkit/build-angular): provide an option to `exclude` sp…
clydin commentedon Jan 9, 2023
In the next patch release there will now be an
excludeoption to complement the existingincludeoption. Theexcludeoption supports specifying one or more globs which represent files that should be ignored for testing. This should allow for the use case as described above.mivanyna commentedon Jan 13, 2023
@clydin Why don't take if from karma config?
angular-automatic-lock-bot commentedon Feb 13, 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.