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'],
},
};
[karma-webpack](https://www.npmjs.com/package/karma-webpack)がインストールされていますか? –
@craig_hはい私はkarma-webpackをインストールしました – Vishal
何らかの理由でwebpackプリプロセッサが適用されていないようです。あなたが私のプロジェクトの1つに使っている簡単なカルマ設定を見て、それがあなたの問題の特定に役立つかどうかを見てみることができます:https://github.com/craigh411/vue-star-rating/blob/master/karma.conf .js –