mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat: support run single test
This commit is contained in:
parent
c6b8de3541
commit
057049c15a
@ -26,6 +26,7 @@
|
||||
"test": "karma start test/unit/karma.conf.js --single-run",
|
||||
"test:coverage": "open test/unit/coverage/lcov-report/index.html",
|
||||
"test:watch": "karma start test/unit/karma.conf.js",
|
||||
"test:single": "node ./test/unit/selector.js",
|
||||
"release": "npm run bootstrap && sh build/release.sh"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -2,7 +2,8 @@ const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
|
||||
|
||||
const webpackConfig = {
|
||||
function getWebpackConfig(testFileName) {
|
||||
return {
|
||||
output: {
|
||||
path: path.resolve(process.cwd(), 'dist'),
|
||||
publicPath: '/dist/',
|
||||
@ -24,14 +25,16 @@ const webpackConfig = {
|
||||
preserveWhitespace: false
|
||||
}
|
||||
}
|
||||
}),
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
TEST_FILE: `"${testFileName}"`
|
||||
}
|
||||
})
|
||||
],
|
||||
stats: 'errors-only',
|
||||
resolve: {
|
||||
modules: [
|
||||
path.resolve(process.cwd(), 'node_modules'),
|
||||
'node_modules'
|
||||
],
|
||||
modules: [path.resolve(process.cwd(), 'node_modules'), 'node_modules'],
|
||||
extensions: ['.js', '.json', '.vue'],
|
||||
alias: {
|
||||
src: path.resolve(process.cwd(), 'src'),
|
||||
@ -55,15 +58,12 @@ const webpackConfig = {
|
||||
},
|
||||
{
|
||||
test: /\.(css|pcss)$/,
|
||||
use: [
|
||||
'style-loader',
|
||||
'css-loader',
|
||||
'postcss-loader'
|
||||
]
|
||||
use: ['style-loader', 'css-loader', 'postcss-loader']
|
||||
},
|
||||
{
|
||||
test: /\.(gif|png|jpe?g)(\?\S*)?$/,
|
||||
use: [{
|
||||
use: [
|
||||
{
|
||||
loader: 'url-loader',
|
||||
options: {
|
||||
query: {
|
||||
@ -71,27 +71,27 @@ const webpackConfig = {
|
||||
name: 'static/[name].[hash:7].[ext]'
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.vue$/,
|
||||
use: [{
|
||||
use: [
|
||||
{
|
||||
loader: 'vue-loader',
|
||||
options: {
|
||||
loaders: {
|
||||
css: [
|
||||
'style-loader',
|
||||
'css-loader',
|
||||
'postcss-loader'
|
||||
],
|
||||
css: ['style-loader', 'css-loader', 'postcss-loader'],
|
||||
js: ['isparta-loader']
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
devtool: '#inline-source-map'
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = webpackConfig;
|
||||
module.exports = getWebpackConfig;
|
||||
|
@ -1,5 +1,13 @@
|
||||
require('packages/vant-css/src/index.css');
|
||||
|
||||
// require all test files (files that ends with .spec.js)
|
||||
// 读取配置文件,判断运行单个测试文件还是所有测试文件
|
||||
const testsReq = require.context('./specs', true, /\.spec$/);
|
||||
testsReq.keys().forEach(testsReq);
|
||||
if (process.env.TEST_FILE) {
|
||||
testsReq.keys().forEach((file) => {
|
||||
if (file.indexOf(process.env.TEST_FILE) !== -1) {
|
||||
testsReq(file);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
testsReq.keys().forEach(testsReq);
|
||||
}
|
@ -4,7 +4,7 @@ require('babel-core/register')({
|
||||
presets: [require('babel-preset-env')]
|
||||
});
|
||||
|
||||
var webpackConfig = require('./get-webpack-conf');
|
||||
var getWebpackConfig = require('./get-webpack-conf');
|
||||
var travis = process.env.TRAVIS;
|
||||
|
||||
module.exports = function(config) {
|
||||
@ -16,7 +16,7 @@ module.exports = function(config) {
|
||||
preprocessors: {
|
||||
'./index.js': ['webpack', 'sourcemap']
|
||||
},
|
||||
webpack: webpackConfig,
|
||||
webpack: getWebpackConfig(getTestFileName()),
|
||||
webpackMiddleware: {
|
||||
noInfo: true
|
||||
},
|
||||
@ -30,3 +30,8 @@ module.exports = function(config) {
|
||||
singleRun: false
|
||||
});
|
||||
};
|
||||
|
||||
function getTestFileName() {
|
||||
const flagIndex = process.argv.indexOf('--file');
|
||||
return flagIndex !== -1 ? process.argv[flagIndex + 1] : '';
|
||||
}
|
||||
|
19
test/unit/selector.js
Normal file
19
test/unit/selector.js
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 运行单个测试文件
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const inquirer = require('inquirer');
|
||||
const path = require('path');
|
||||
const shell = require('shelljs');
|
||||
const files = fs.readdirSync(path.resolve(__dirname, './specs'));
|
||||
|
||||
inquirer.prompt([{
|
||||
type: 'list',
|
||||
name: 'select',
|
||||
message: '请选择要运行的测试文件:',
|
||||
choices: files
|
||||
}], (result) => {
|
||||
const file = result.select.replace('.spec.js', '');
|
||||
shell.exec('karma start test/unit/karma.conf.js --color alway --file ' + file);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user