I try to run angular cli karma test in Chrome to get a localhost link. but if i run npm run test it open chrome and close it immediately.
karma.config.js:
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-phantomjs-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('karma-junit-reporter'),
require('@angular/cli/plugins/karma')
],
client: {
clearContext: false
},
files: [{
pattern: './src/test.ts',
watched: false
}],
preprocessors: {
'./src/test.ts': ['@angular/cli']
},
mime: {
'text/x-typescript': ['ts', 'tsx']
},
coverageIstanbulReporter: {
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
angularCli: {
config: './.angular-cli.json',
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'junit', 'coverage-istanbul']
: ['progress', 'junit', 'kjhtml'],
junitReporter: {
outputDir: 'test/target',
outputFile: 'surefire-reports/TEST-karma.xml',
suite: '',
useBrowserName: true
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: [
//'PhantomJS',
'Chrome'
],
singleRun: true
});
};
How can run npm run test in chrome.
I try to to get localhost with all my tests so that i can debug it in vs code.
console output:
10% building modules 2/2 modules 0 active10 02 2018 23:45:02.459:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:9876/
10 02 2018 23:45:02.462:INFO [launcher]: Launching browser Chrome with unlimited concurrency
10 02 2018 23:45:02.468:INFO [launcher]: Starting browser Chrome 10 02 2018 23:45:12.031:INFO [Chrome 64.0.3282 (Windows 10.0.0)]: Connected on socket QFzL8LOUHJtjA405AAAA with id 83404421
Chrome 64.0.3282 (Windows 10.0.0): Executed 28 of 28 SUCCESS (0.976 secs / 0.951 secs)
If your problem is this=> "if i run npm run test it open chrome and close it immediately" That's because of this=> singleRun=true When it is true, Karma captures browsers, runs the tests and exits. So change that to
singleRun: false