简体   繁体   中英

ng test not working after upgrade to Karma 2.0.0

Yesterday I upgraded Angular from v4.4 to v5.2 and Karma from v1.7.1 to v2.0.0. Since doing this I can't run ng test .

I can run the tests using the karma start myconfigfile.js --single-run and they all pass correctly, but when I try ng test , the browser opens but hangs after displaying 'Karma - starting'. There is no console output.

I've tried both Chrome and ChromeHeadless for the browser but have run out of ideas. Any help would be appreciated.

Config:

module.exports = function (config) {
    config.set({
        basePath: '',
        frameworks: ['jasmine', '@angular/cli'],
        plugins: [
            require('karma-jasmine'),
            require('karma-chrome-launcher'),
            require('karma-coverage-istanbul-reporter'),
            require('karma-jasmine-html-reporter'),
            require('karma-spec-reporter'),
            require('karma-junit-reporter'),
            require('@angular/cli/plugins/karma')
        ],
        client: {
            clearContext: false // leave Jasmine Spec Runner output visible in browser
        },
        files: [
            { pattern: './src/test.ts', watched: false }
        ],
        preprocessors: {
            './src/test.ts': ['@angular/cli']
        },
        mime: {
            'text/x-typescript': ['ts', 'tsx']
        },
        coverageIstanbulReporter: {
            reports: ['html', 'lcovonly', 'cobertura'],
            fixWebpackSourcePaths: true,
            'report-config': {
                cobertura: {
                    file: 'coverage.xml'
                }
            }
        },
        angularCli: {
            environment: 'dev'
        },
        reporters: ['spec', 'kjhtml', 'junit', 'coverage-istanbul'],
        junitReporter: {
            outputDir: '',
            outputFile: 'test-results.xml',
            useBrowserName: false
        },
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: false,
        browsers: ['ChromeHeadless'],
        singleRun: true,
        browserNoActivityTimeout: 60000,
        browserDisconnectTolerance: 5
    });
};

For anyone who comes across this in future, it looks like it was a dependency issue. An npm install sorted it out.

I have been trying same with angular 5,karma 2.0.0, karma-chrome-launcher 2.2.0 on windows 10 machine and wasted entire day to figure it out why chrome is not capturing.

You have to make custom chrome header although documents says only
browsers: ['ChromeHeadless'] would work but its not working.

Please make custom header like this:

    customLaunchers: {
        ChromeHeadlessCustom: {
            base: 'ChromeHeadless', // browser
            flags: [
                '--no-sandbox', // needed to run test  case in windows also
            ],
        },
    }

Then give custom header reference in browser tag:

browsers: ['ChromeHeadlessCustom']

After this its working like charm. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM