简体   繁体   English

铬角cli npm运行测试

[英]angular cli npm run test with chrome

I try to run angular cli karma test in Chrome to get a localhost link. 我尝试在Chrome中运行angular cli karma测试以获取localhost链接。 but if i run npm run test it open chrome and close it immediately. 但是,如果我运行npm run test,请打开chrome并立即将其关闭。

karma.config.js: 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. 如何在Chrome中运行npm运行测试。

I try to to get localhost with all my tests so that i can debug it in vs code. 我尝试通过所有测试获得localhost,以便可以在vs代码中对其进行调试。

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. 如果您的问题是此=>“如果我运行npm run test,请打开chrome并立即关闭它”,这是由于此=> singleRun = true。如果为true,则Karma会捕获浏览器,运行测试并退出。 So change that to 所以将其更改为

singleRun: false singleRun:错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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