正在测试karama、jasmine、webpack-找不到模块'/html';

正在测试karama、jasmine、webpack-找不到模块'/html';,webpack,jasmine,karma-runner,Webpack,Jasmine,Karma Runner,我正在用karma jasmine网页测试Angular 2,我收到错误消息 “结果消息:未捕获错误:找不到模块”。/fetchdata.component.html” 我正在尝试为组件fetchdata.component编写测试规范。 Karma test runner正在抛出上述错误消息 这是我的package.json { "name": "Angular2Spa", "version": "0.0.0", "main": "index.js", "scripts": {

我正在用karma jasmine网页测试Angular 2,我收到错误消息 “结果消息:未捕获错误:找不到模块”。/fetchdata.component.html”

我正在尝试为组件fetchdata.component编写测试规范。 Karma test runner正在抛出上述错误消息

这是我的package.json

{
  "name": "Angular2Spa",
  "version": "0.0.0",
  "main": "index.js",
  "scripts": {
    "build": "webpack",
    "start": "static .",
    "test": "karma start"
  },
  "dependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
    "@angular/platform-browser": "2.0.0",
    "@angular/platform-browser-dynamic": "2.0.0",
    "@angular/platform-server": "2.0.0",
    "@angular/router": "3.0.0",
    "@types/jasmine": "^2.5.41",
    "@types/node": "^6.0.38",
    "angular2-platform-node": "~2.0.10",
    "angular2-universal": "~2.0.10",
    "angular2-universal-polyfills": "~2.0.10",
    "aspnet-prerendering": "^1.0.6",
    "aspnet-webpack": "^1.0.11",
    "bootstrap": "^3.3.7",
    "css": "^2.2.1",
    "css-loader": "^0.25.0",
    "es6-shim": "^0.35.1",
    "expose-loader": "^0.7.1",
    "extract-text-webpack-plugin": "^1.0.1",
    "file-loader": "^0.9.0",
    "isomorphic-fetch": "^2.2.1",
    "jquery": "^2.2.1",
    "preboot": "^4.5.2",
    "raw-loader": "^0.5.1",
    "rxjs": "5.0.0-beta.12",
    "style-loader": "^0.13.0",
    "to-string-loader": "^1.1.5",
    "ts-loader": "^0.8.2",
    "typescript": "^2.0.0",
    "url-loader": "^0.5.7",
    "webpack": "^2.2.1",
    "webpack-externals-plugin": "^1.0.0",
    "webpack-hot-middleware": "^2.16.1",
    "webpack-merge": "^2.6.1",
    "zone.js": "^0.6.21",
    "core-js": "^2.4.1"
  },
  "devDependencies": {
    "awesome-typescript-loader": "3.0.0-beta.10",
    "jasmine-core": "^2.5.2",
    "karma": "^1.4.1",
    "karma-chrome-launcher": "^2.0.0",
    "karma-jasmine": "^1.1.0",
    "karma-webpack": "^2.0.2",
    "@types/node": "^6.0.45",
    "@types/webpack-env": "^1.12.1",
    "@types/jasmine": "2.5.41",
    "angular2-template-loader": "^0.5.0",
    "jasmine": "^2.5.2",
    "karma-sourcemap-loader": "^0.3.7",
    "node-static": "^0.7.9",
    "raw-loader": "^0.5.1",
    "typescript": "^2.0.3",
    "webpack": "^2.1.0-beta.25"
  }
}
这是我的karma.conf.js

// Karma configuration
// Generated on Fri Feb 03 2017 11:35:26 GMT-0600 (Central Standard Time)

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
        { pattern: 'ClientApp/test/main.js', watched: false }
   // { pattern: 'ClientApp/app/components/**/**.spec.ts', watched: false }
    ],


    // list of files to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
        'ClientApp/test/main.js': ['webpack', 'sourcemap']
        //'ClientApp/app/components/**/**.spec.ts': ['webpack', 'sourcemap']
    },

    webpack: require('./webpack.config')({ env: 'test' }),

    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity 


  })
}
这里是main.js

require('../app//app.spec.ts');
app.spec.ts

import 'core-js'; // ES6 + reflect-metadata
// zone.js
import 'zone.js/dist/zone';
import 'zone.js/dist/proxy';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/async-test';
import 'zone.js/dist/jasmine-patch';

// TestBed initialization
import { TestBed } from '@angular/core/testing';
import {
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';

TestBed.initTestEnvironment(
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting()
);

// load all specs in ./src .
const context = (require as any).context('./', true, /\.spec\.ts$/);
context.keys().map(context);
这是我的测试规范fetchdata.component.spec.ts

/////

import { Component } from '@angular/core';
import { TestBed, async } from '@angular/core/testing';

import { fetchComponent} from './fetchdata.component';



describe('EchoPipe', () => {
    let comp: fetchComponent;
    beforeEach(async(() => {
        TestBed.configureTestingModule({
            declarations: [fetchComponent]
        })
        .compileComponents(); 
    }));

    //beforeEach(async(() => {
    //    TestBed.compileComponents();
    //}));

    it('works well', async(() => {
        const fixture = TestBed.createComponent(fetchComponent);
        comp = fixture.componentInstance;
        fixture.detectChanges();
        // const el = fixture.debugElement.nativeElement as HTMLElement;
        expect(comp.currentCount).toEqual(0);
    }));

    it("can have more than one expectation", function () {
        var foo = 0;
        foo += 1;

        expect(foo).toEqual(1);
        expect(true).toEqual(true);
    });

});