带有Typescript结果的Karma + Mocha“无法找到变量:require`或`Empty test suite`

时间:2015-10-27 11:44:04

标签: typescript karma-runner karma-mocha typescript1.6

我的Karma配置:

module.exports = function (config) {
    config.set({
        basePath: '.',
        frameworks: ['mocha', 'chai'],
        files: ['test/**/*-test.js'],
        exclude: [],
        preprocessors: {
            '**/*.ts': ['typescript']
        },
        reporters: ['progress'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['PhantomJS'],
        singleRun: false,
        concurrency: Infinity,
        plugins: [ 'karma-*' ],
        client: {
            mocha: { ui: 'bdd' }
        },
        typescriptPreprocessor: {
            options: {
                sourceMap: false,
                target: 'es5',
                module: 'commonjs',
                removeComments: true
            },
            transformPath: function(path) {
                return path.replace(/\.ts$/, '.js');
            }
        }
    })
};

和测试文件

// test/app-test.ts
import chai = require('chai');

var expect = chai.expect;

describe('test', () => {
    it('should work', () => {
        expect(true).should.be.true;
    });
});

结果是

  

空的测试套件。

当我将files: ['test/**/*-test.js'],更改为files: ['test/**/*-test.ts'],时,结果为:

  

无法找到变量:require

完整来源位于:https://github.com/Ridermansb/webpackKarmaAngularTypescriptStarter

1 个答案:

答案 0 :(得分:0)

  1. typings
  2. 中遗失karma.config.js
  3. 我使用bdd样式,因此测试应为true.should.be.true
  4. 无需在测试中要求柴。
  5. 修正了提交0a4a20c7558579f8c6910a6054e872f87ec97203