打字稿-茉莉花-业力

时间:2020-05-14 14:33:23

标签: typescript jasmine karma-runner

我有一个简单的打字稿项目,想做单元测试。 我配置了茉莉花,并且运行正常。 现在我想安装业力并对其进行配置。

测试文件位于spec文件夹下,程序代码位于src文件夹下。 我们有一个简单的单元测试文件(* .spec.ts),带有如下的import语句:

import { IEvento } from '../src/IEvento';
import * as ie     from '../src/InitEvento';

当运行Jasmine时,所有工作都没有问题,但是当我启动业力时,会出现此错误:

An error was thrown in afterAll
  Uncaught ReferenceError: exports is not defined
  ReferenceError: exports is not defined
      at src/IEvento.js:2:23

karma.conf.js

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"],
    // Plugins
    plugins: [
      'karma-typescript-preprocessor',
      'karma-spec-reporter',
      'karma-jasmine',
      'karma-chrome-launcher',
      'karma-jasmine-html-reporter'
    ],
    // list of files / patterns to load in the browser
    files :[
      'src/**/*.ts',
      'spec/**/*.spec.ts'
    ],
    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      '**/*.ts': ['typescript']
    },
    typescriptPrepocessor:{
      options: {
        sourceMap: false, // (optional) Generates corresponding .map file.
        target: 'ES6', // (optional) Specify ECMAScript target version: 'ES3' (default), or 'ES5'
        noImplicitAny: true, // (optional) Warn on expressions and declarations with an implied 'any' type.
        noResolve: true, // (optional) Skip resolution and preprocessing.
        removeComments: true, // (optional) Do not emit comments to output.
        concatenateOutput: false // (optional) Concatenate and emit output to single file. By default true if module option is omited, otherwise false.
      },
      transformPath: function(path){
          return path.replace('/\.ts$','.js');
      }
    },
    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress', 'kjhtml', 'spec'],
    // 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
  })
}

你能帮我吗?

0 个答案:

没有答案