2017-06-21 11 views
0

私は私のVueのjsアプリのE2Eテストのセットアップカルマにしようとしていますが、私は、NPMのテストを実行しようとすると、私はこのエラーReferenceError:変数:requireが見つかりません。 [カルマ、WebPACKの]

PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR 
ReferenceError: Can't find variable: require 
at index.js:1 

を取得し、私がテスト の公式VUEのマニュアルを参照して、以下のいhttps://vue-loader.vuejs.org/en/workflow/testing.html

karma.config.js

var webpackConfig = require('../webpack.test.config.js') 

// karma.conf.js 
module.exports = function (config) { 
    config.set({ 
    browsers: ['PhantomJS'], 
    frameworks: ['jasmine'], 
    // this is the entry file for all our tests. 
    files: ['./index.js'], 
    // we will pass the entry file to webpack for bundling. 
    preprocessors: { 
     './test/index.js': ['webpack'] 
    }, 
    // use the webpack config 
    webpack: webpackConfig, 
    // avoid walls of useless text 
    webpackMiddleware: { 
     noInfo: true 
    }, 
    singleRun: true 
    }) 
} 

//index.js referenced in above karma config 
var testsContext = require.context('.', true, /\.spec$/)  
testsContext.keys().forEach(testsContext) 

//webpack.test.config.js 
const webpack = require('webpack'); 
const path = require('path'); 
const projectRoot = path.resolve(__dirname, '../'); 

module.exports = { 

    module: { 

    loaders: [ 
     { 
     test: /\.vue$/, 
     loader: 'vue-loader', 
     }, 
     { 
     test: /\.js$/, 
     loader: 'babel-loader', 
     query: { 
      presets: ['es2015'] 
     }, 
     include: [ 
      projectRoot, 
     ], 
     exclude: /node_modules/, 
     }, 
    ], 
    }, 
    plugins: [ 
    new webpack.ProvidePlugin({ 
     $: "jquery", 
     jQuery: "jquery" 
    }) 
    ], 
    resolve: { 
    extensions: ['.js', '.vue'], 
    }, 
}; 
+0

[karma-webpack](https://www.npmjs.com/package/karma-webpack)がインストールされていますか? –

+0

@craig_hはい私はkarma-webpackをインストールしました – Vishal

+0

何らかの理由でwebpackプリプロセッサが適用されていないようです。あなたが私のプロジェクトの1つに使っている簡単なカルマ設定を見て、それがあなたの問題の特定に役立つかどうかを見てみることができます:https://github.com/craigh411/vue-star-rating/blob/master/karma.conf .js –

答えて

3

[OK]をので、問題は、プリプロセッサでindex.jsのパスを与えている間、私が作った非常に愚かな間違いでした。

パスは./index.jsでしたが、私はtest/index.jsでした。

関連する問題