Problem
I am trying to get a few tests working using Karma and Jasmine in a practice Angular project. When I use attempt to run the Karma tests using the Karma start command in the command line, a browser opens (Chrome, in this case), but does not display any tests. It displays only the Karma version, the debug button, and a message indicating Chrome is idle (see pictures below). In the command line, Karma gives the warning
All files matched by "D:/Documents/CSCI_Project/test-app/*.js" were excluded or matched by prior matchers.
It also gives multiple warnings of the form
Pattern "D:/Documents/CSCI_Project/test/test-app/testPractice.spec.js" does not match any file.
The test file contains a basic test designed to always pass. The absolute path of the file is D:\Documents\CSCI_Project\test-app\test\testPractice.spec.ts
Steps Taken
Based on the errors, it seems that the Karma cannot find my test files using the patterns given in "files" part of the configuration file, karma.config.js. However, I have tried numerous patterns, including listing the exact relative path and ensuring that the path shown in the warning for that pattern is the absolute path of the file.
I think that typescript files are automatically converted to javascript files, but I tried using patterns ending in .ts instead of .js, which resulted in the karma warning Unable to determine file type from the file extension, defaulting to js.
At this point, I cannot think of what else the problem could have been. I am not very familiar with Karma, Jasmine, or Angular.
Code/Pictures
karma.conf.js file
// Generated on Sat Feb 06 2021 12:10:57 GMT-0500 (Eastern Standard Time)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'*.js',
'test/**/*.js',
'test/*.js',
'test/testPractice.js',
'test/testPractice.spec.js',
],
// list of files / patterns to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
Chrome window opened by Karma: picture link
Command line with Karma warnings: picture link
test file: testPractice.ts
describe("Practice Test", () =>{
it("Should return true", ()=>{
var test = true;
expect(test).toBe(true);
});
});