没有定义karma + webpack + typescript + mocha require

时间:2017-06-29 02:18:32

标签: phantomjs mocha jsdom karma-mocha karma-webpack

我尝试配置我的环境以在节点上运行测试。 这是我的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;

karma.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
  })
}

TEST1

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);
        })

    })
});

TEST2

import { expect } from 'chai';

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

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

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

的package.json

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

当我从业力中取决于我使用哪个浏览器来显示消息时,我会抛出类似的错误,当我用jsdom或PhantomJS抛出它时,我抛出以下内容

要求未定义o无法找到

查看git,解决问题的唯一答案就是将以下的业力处理器放入其中。

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

这是一样的,我变化多了,但错误还在继续。

introducir la descripción de la imagen aquí

introducir la descripción de la imagen aquí

0 个答案:

没有答案