7

我有以下开发设置:

  • Angular2(带打字稿)
  • 用于打包的 webpack
  • Karma 作为 Jasmine 测试的测试运行器
  • 调用 Karma 的 Gulp

Karma 配置如下:

var webpackConfig = require('./webpack.config');
webpackConfig.entry = {};

module.exports = function(config) {
config.set({
    basePath: '',

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

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

    reporters: [],
    coverageReporter: {},
    port: 9876,
    action: 'run',
    colors: true,
    logLevel: config.LOG_INFO, // LOG_DEBUG | LOG_INFO | LOG_WARN | LOG_ERROR
    autoWatch: false,
    autoWatchBatchDelay: 300,
    singleRun: true,

    files: [ { pattern: './spec-bundle.js', watched: false } ],
    exclude: [],
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
        './spec-bundle.js': ['webpack']
    },

    webpack: webpackConfig,

    // https://webpack.github.io/docs/webpack-dev-middleware.html
    webpackMiddleware: {
        noInfo: true,
        stats: 'errors-only'
    },

    plugins: [
        'karma-coverage',
        'karma-jasmine',
        'karma-phantomjs-launcher',
        'karma-teamcity-reporter',
        'karma-webpack'
    ]
});
}

Webpack 配置如下:

var webpack = require('webpack');

module.exports = {
entry: {
    main: './src/run.ts'
},
target: 'web', // 'web' | 'node'
output: {
    filename: '[name].js',
    pathinfo: true
},
devtool: 'source-map',
resolve: {
    extensions: ['', '.ts', '.js']
},
resolveLoader: {
    modulesDirectories: ['node_modules']
},
module: {
    loaders: [
        { test: /\.ts$/, loader: 'ts-loader' },
        // fastclick contains AMD and CJS loader logic - disable AMD so CJS is used
        { test: require.resolve('fastclick'), loader: 'imports?define=>false' }
    ],
    postLoaders: [
        { test: /\.ts$/, exclude: /(node_modules|spec)\//, loader: 'istanbul-instrumenter' }
    ]
},
stats: {
    colors: true,
    errorDetails: true,
    modules: false,
    reasons: true   // add information about the reasons why modules are included
}
};

ts 配置如下:

"compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "moduleResolution": "node",
    "noEmitHelpers": true,
    "module": "commonjs",
    "outDir": "../dist/app",
    "sourceMap": true
},
"buildOnSave": false,
"compileOnSave": false
}    

(/node_modules 与 /src 处于同一级别,而 tsconfig.json 位于 /src 文件夹中)。

因此,我有一个 /src/typings 文件夹,其中包含用于 lodash、fastclick 等的各种 *.d.ts 文件。当我调用 Karma 时,每个定义都会收到以下消息:

WARNING in ./src/typings/lodash/lodash.d.ts
Module build failed: Error: Typescript emitted no output for /Users/jbrighton/src/teammember-client/src/typings/lodash/lodash.d.ts
at Object.loader (/Users/jbrighton/src/teammember-client/node_modules/ts-loader/index.js:456:15)
 @ ./src \.ts

Jasmine 测试成功运行(并且非测试构建运行良好)但是是什么导致了这些消息以及如何防止它们?

4

0 回答 0