5

在某些机器上构建 Angular 应用程序需要超过 2*60 秒(Karma 启动的 Chrome 捕获内容的默认超时)。

有没有办法在构建完成后强制 Karma 启动 Chrome?

我的package.json

{
  "dependencies": {
    "@angular/animations": "4.4.4",
    "@angular/common": "4.4.4",
    "@angular/compiler": "4.4.4",
    "@angular/core": "4.4.4",
    "@angular/forms": "4.4.4",
    "@angular/http": "4.4.4",
    "@angular/platform-browser": "4.4.4",
    "@angular/platform-browser-dynamic": "4.4.4",
    "@angular/platform-server": "4.4.4",
    "@angular/router": "4.4.4",
    "rxjs": "5.4.3",
    "ts-md5": "^1.2.2",
    "zone.js": "^0.8.17"
  },
  "devDependencies": {
    "@angular/cli": "1.4.4",
    "@angular/compiler-cli": "4.4.4",
    "@types/jasmine": "2.5.45",
    "@types/node": "~6.0.60",
    "jasmine-core": "^2.8.0",
    "jasmine-spec-reporter": "^4.2.1",
    "karma": "^1.7.1",
    "karma-chrome-launcher": "^2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.3.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^5.1.2",
    "protractor-console-plugin": "^0.1.1",
    "protractor-jasmine2-screenshot-reporter": "^0.4.1",
    "ts-helpers": "1.1.2",
    "ts-node": "^3.3.0",
    "tslint": "^5.7.0",
    "typescript": "2.3.4"
  }
}

karma.conf.js

module.exports = function (config) {
    config.set({
        basePath: '',
        frameworks: ['jasmine', '@angular/cli'],
        plugins: [
            require('karma-jasmine'),
            require('karma-chrome-launcher'),
            require('karma-jasmine-html-reporter'),
            require('karma-coverage-istanbul-reporter'),
            require('@angular/cli/plugins/karma')
        ],
        client: {
            clearContext: false // leave Jasmine Spec Runner output visible in browser
        },
        files: [{
                pattern: './src/test.ts',
                watched: false
            },
            {
                pattern: './src/assets/**',
                watched: false,
                included: false,
                nocache: false,
                served: true
            }
        ],
        preprocessors: {
            './src/test.ts': ['@angular/cli']
        },
        mime: {
            'text/x-typescript': ['ts', 'tsx']
        },
        coverageIstanbulReporter: {
            reports: ['html', 'lcovonly'],
            fixWebpackSourcePaths: true
        },
        angularCli: {
            environment: 'dev'
        },
        reporters: config.angularCli && config.angularCli.codeCoverage ?
            ['progress', 'coverage-istanbul'] :
            ['progress', 'kjhtml'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        autoWatchDelay: 1000,
        browsers: ['Chrome'],
        singleRun: false
    });
};
4

1 回答 1

0

如果我理解正确:

ng serve --open 就是你要找的。

您可以在成功构建后将其链接为npm 启动脚本,或在其他工具中,例如gulpgrunt

于 2018-06-28T14:16:37.770 回答