0
我有一個應用程序設置與業力&摩卡&通過伊斯坦布爾報告單元測試。從文件更改commad行/ npm腳本運行業力
NPM腳本:
"test": "cross-env BABEL_ENV=test karma start tests/karma.conf.js --single-run",
我想要做的是有一個腳本開發,將觀看試驗&應用程序文件的更改,並在運行需要重新運行測試。
我試着用--auto-watch
更換--single-run
:
"test:watch": "cross-env BABEL_ENV=test karma start tests/karma.conf.js --auto-watch",
但再連續運行 - 只要一個輪測試完成後,它開始了。
karma.conf.js:
var webpackConfig = require('../build/webpack.conf.test');
module.exports = function (config) {
config.set({
browsers: ['PhantomJS'],
frameworks: ['mocha', 'sinon-chai', 'phantomjs-shim'],
reporters: ['spec', 'coverage'],
files: ['./index.js'],
preprocessors: {
'./index.js': ['webpack', 'sourcemap'],
},
webpack: webpackConfig,
webpackMiddleware: {
noInfo: true
},
coverageReporter: {
dir: './coverage',
reporters: [
{ type: 'lcov', subdir: '.' },
{ type: 'text' }
]
}
});
};
webpack.conf.test.js
var path = require('path');
var webpack = require('webpack');
var vueLoaderConfig = require('./vue-loader.conf.js');
var eslintFormatter = require('eslint-friendly-formatter');
var HtmlWebpackPlugin = require('html-webpack-plugin');
function resolve(dir) {
return path.join(__dirname, '..', dir);
}
module.exports = {
devtool: '#inline-source-map',
output: {
path: path.resolve(__dirname, '../dist/js'),
filename: 'build.js',
publicPath: '/ntx/js/'
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'@': resolve('src')
}
},
resolveLoader: {
alias: {
'scss-loader': 'sass-loader'
}
},
plugins: [
new webpack.DefinePlugin({
'process.env': { NODE_ENV: '"testing"' }
})
],
// use inline sourcemap for karma-sourcemap-loader
module: {
rules: [
{ test: /\.css$/, use: ['vue-style-loader', { loader: 'css-loader', options: { minimize: false, sourceMap: false } }] },
{ test: /\.postcss$/, use: ['vue-style-loader', { loader: 'css-loader', options: { minimize: false, sourceMap: false } }] },
{ test: /\.less$/, use: ['vue-style-loader', { loader: 'css-loader', options: { minimize: false, sourceMap: false } }, { loader: 'less-loader', options: { sourceMap: false } }] },
{ test: /\.sass$/, use: ['vue-style-loader', { loader: 'css-loader', options: { minimize: false, sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false, indentedSyntax: true } }] },
{ test: /\.scss$/, use: ['vue-style-loader', { loader: 'css-loader', options: { minimize: false, sourceMap: false } }, { loader: 'scss-loader', options: { sourceMap: false } }] },
{ test: /\.stylus$/, use: ['vue-style-loader', { loader: 'css-loader', options: { minimize: false, sourceMap: false } }, { loader: 'stylus-loader', options: { sourceMap: false } }] },
{ test: /\.styl$/, use: ['vue-style-loader', { loader: 'css-loader', options: { minimize: false, sourceMap: false } }, { loader: 'stylus-loader', options: { sourceMap: false } }] },
{ test: /\.(js|vue)$/,
loader: 'eslint-loader',
enforce: 'pre',
include: [resolve('src'), resolve('test')],
options: {
formatter: eslintFormatter
}
}, {
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
css: ['vue-style-loader', { loader: 'css-loader', options: { minimize: false, souremap: false } }],
postcss: ['vue-style-loader', { loader: 'css-loader', options: { minimize: false, souremap: false } }],
less: ['vue-style-loader', { loader: 'css-loader', options: { minimize: false, souremap: false } }, { loader: 'less-loader', options: { sourceMap: false } }],
sass: ['vue-style-loader', { loader: 'css-loader', options: { minimize: false, souremap: false } }, { loader: 'sass-loader', options: { sourceMap: false, indentedSyntax: true } }],
scss: ['vue-style-loader', { loader: 'css-loader', options: { minimize: false, souremap: false } }, { loader: 'scss-loader', options: { sourceMap: false } }],
stylus: ['vue-style-loader', { loader: 'css-loader', options: { minimize: false, souremap: false } }, { loader: 'stylus-loader', options: { sourceMap: false } }],
styl: ['vue-style-loader', { loader: 'css-loader', options: { minimize: false, souremap: false } }, { loader: 'stylus-loader', options: { sourceMap: false } }],
},
transformToRequire: {
video: 'src',
source: 'src',
img: 'src',
image: 'xlink:href'
}
}
}, {
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test')]
}, {
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: path.posix.join('./dist/img', 'img/[name].[hash:7].[ext]')
}
}
]
}
};
有沒有辦法做我正在尋找?
這與單純拋棄'-single-run'有相同的問題:它不會等待任何文件的更改,它會在完成一次運行後立即重複測試套件。我希望它只在文件更改時重新運行。 – ebbishop
你使用的是業力配置文件嗎? – 2017-08-09 16:00:08
是的 - 我不相信我第一次沒有把它放在!添加。 – ebbishop