Angular CLI karma测试未运行

时间:2017-03-15 19:11:39

标签: javascript angularjs node.js karma-runner angular-cli

我有一个Angular2项目,使用Angular Cli 1.0.0.rc2

创建

当我运行func()时,项目构建(没有错误!),karma启动chrome并显示

“Karma v1.4.1 - 已连接”和

“Chrome 56.0.2924(Mac OS X 10.12.3)闲置”

不久之后,我在控制台中收到错误说 ng test

有趣的是,调用启动测试的You need to include some adapter that implements __karma__.start method!实际上正在运行(通过console.log('test')确认)并且它有一个test.ts调用。

任何人都可以提供帮助吗?

我正在使用Node 6.10.0和NPM 3.10.10。

作为参考,这是karma调用的__karma__.start()文件,除了test.ts之外我没有更改任何内容:

console.log()

import 'zone.js/dist/long-stack-trace-zone'; import 'zone.js/dist/proxy.js'; import 'zone.js/dist/sync-test'; import 'zone.js/dist/jasmine-patch'; import 'zone.js/dist/async-test'; import 'zone.js/dist/fake-async-test'; import { getTestBed } from '@angular/core/testing'; import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. declare var __karma__: any; declare var require: any; // Prevent Karma from running prematurely. __karma__.loaded = function () {}; // First, initialize the Angular testing environment. getTestBed().initTestEnvironment( BrowserDynamicTestingModule, platformBrowserDynamicTesting() ); // Then we find all the tests. let context = require.context('./', true, /\.spec\.ts$/); // And load the modules. context.keys().map(context); // Finally, start Karma to run the tests. __karma__.start(); console.log('test started');

karma.conf.js

编辑1

从根文件夹运行Karma,下面的文件夹结构如下所示:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('@angular/cli/plugins/karma'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter')
    ],
    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' ],
      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,
    browsers: ['Chrome'],
    singleRun: false
  });
};

编辑2

我使用标准配置创建了一个新的空白项目,并且在运行<-- root -- src/ -- karma.conf.js -- .angular-cli.json -- package.json -- protractor.conf.js -- tsconfig.json -- tslint.json -- typings.json -- app/ -- index.html -- main.ts -- polyfills.ts -- test.ts <--- this is called by karma -- tsconfig.app.json -- tsconfig.spec.json -- classes/ -- components/ -- some-component/ -- some.component.ts -- some.component.spec.ts -- some.component.html -- some.component.css -- confjs/ -- guards/ -- interfaces/ -- models/ -- routes/ -- services/ 时,它已成功运行,其中包含了角度cli为ng test提供的3个规范

由于我没有改变任何有关业力,测试文件或其他任何内容的配置,问题是为什么我的实际项目中的测试不运行?

至少应运行app.component.ts的规范,因为该文件与我的测试项目位于同一位置。业力可能存在无法找到其他规范文件的问题,但应该至少运行。

编辑3

我还注意到在升级到Angular CLI rc2之后,不再执行console.log()消息。

编辑4

我终于弄清楚如何从业力中获取更多信息:D可悲的是,它似乎没有显示出更多,比我已经知道的更多。除了我可以看到app.component.ts文件夹似乎没有被观看。只有appsrc/test.ts秒显然不包含任何测试文件或规格。

这是日志(我最后手动退出):

src/assets/

0 个答案:

没有答案
相关问题