2

我尝试配置我的环境以在节点上运行测试。 这是我的 webpack.config.test.js

const serverConfig = {
      module: {
        loaders: [
          {test: /\.tsx?$/, loader: 'ts-loader' }
        ]
      },
        target: 'node',

      externals:[nodeExternals()],

      resolve: {
           extensions: ['.ts', '.tsx', '.js']
      }
};

module.exports = serverConfig;

业力.config.js

// Karma configuration
// Generated on Tue Jun 27 2017 07:20:43 GMT-0500 (Hora est. Pacífico, Sudamérica)
const webpackConfig=require('./config/webpack/webpack.test');
module.exports = function(config) {
  config.set({

    basePath: '',

    frameworks: ['mocha','es6-shim'],

    plugins:[
        require("karma-es6-shim"),

      'karma-webpack',
      'karma-jsdom-launcher',
      'karma-mocha',
      'karma-spec-reporter',
      'karma-jsdom-launcher',
      'karma-coverage',
      'karma-chrome-launcher',
       "karma-phantomjs-launcher",
       'karma-htmlfile-reporter'

    ],

    files: [
      'test/**/*.spec.ts'
    ],

    coverageReporter: {
        webpackMiddleware: {
            stats: "errors-only"
        },
      dir: 'build/coverage/',
      reporters: [
          { type: 'html' },
          { type: 'text' },
          { type: 'text-summary' }
      ]
    },
    // list of files to exclude
    exclude: [
    ],


    preprocessors: {
      'test/**/*.spec.ts':["webpack","coverage"]
    },

    webpack:webpackConfig,

    reporters: ['spec','progress','html'],

    htmlReporter: {
      outputFile: 'tests/units.html',

      // Optional 
      pageTitle: 'Unit Tests',
      subPageTitle: 'A sample project description',
      groupSuites: true,
      useCompactStyle: true,
      useLegacyStyle: true
    },

    // web server port
    port: 9876,



    colors: true,

    autoWatch: true,

    browsers: ['PhantomJS'],

    singleRun: false,

    concurrency: Infinity
  })
}

测试1

import { DBCONFIG } from './../src/config/db.config';
import { CONEXION } from './../src/config/database/mongo';
import { expect } from 'chai';


describe("#DATABASE",()=>{
    it("Esta conectado",()=>{
        CONEXION("hola",DBCONFIG.MONGO_URL_LOCAL)
        .then(()=>{
                        expect(1).to.be("1");
        })
        .catch((e)=>{
            expect(1).to.be(e);
        })

    })
});

测试2

import { expect } from 'chai';

describe("#User",()=>{

    it("use2r",()=>{
            expect(1).to.equal("1");
    })
})

当我使用 mocha-webpack 运行 mocha + webpack 时,测试运行没有问题。

包.json

"test-server": "mocha-webpack --timeout 1000 --webpack-config config/webpack/webpack.test.js test/**/*.spec.ts",
"test":"karma start"

当我根据我用来显示消息的浏览器从业力执行此操作时,我会抛出类似的错误,当我使用 jsdom 或 PhantomJS 抛出它时,我会抛出以下内容

要求未定义 o 找不到

在 git 中查看,解决问题的唯一答案是将 karma 的处理器放入以下内容。

  'test/**/*.spec.ts':["webpack","coverage"]

这是相同的方式,我已经改变了,但错误仍在继续。

水图像介绍

水图像介绍

4

0 回答 0