gpt4 book ai didi

reactjs - 缓慢的 Karma 单元测试

转载 作者:行者123 更新时间:2023-12-03 14:27:32 24 4
gpt4 key购买 nike

我使用 Jasmine 和 Karma 为一个小型应用程序编写了单元测试。Karma 在这些测试中运行缓慢。

这是我的 karma 配置:

var unitTestReportOutputDir = 'unit-test-report';

module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
reporters: ['dots'],
port: 9876,
colors: false,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
autoWatchBatchDelay: 300,
exclude: ['./test/data/*.js'],
files: [
'tests.webpack.js'],

preprocessors: {
'tests.webpack.js': ['webpack']
},
webpack: require('./webpack.config.js'),

webpackMiddleware: {
noInfo: true
},
htmlReporter: {
outputDir: unitTestReportOutputDir, // where to put the reports
focusOnFailures: true, // reports show failures on start
namedFiles: true, // name files instead of creating sub-directories
pageTitle: 'Unit Test Report', // page title for reports; browser info by default
urlFriendlyName: false, // simply replaces spaces with _ for files/dirs
reportName: 'test-summary', // report summary filename; browser info by default
// experimental
preserveDescribeNesting: false, // folded suites stay folded
foldAll: false, // reports start folded (only with preserveDescribeNesting)
}
});

}

这是我的 webpack.config.js:

var ExtractTextPlugin = require('extract-text-webpack-plugin');
var webpack = require('webpack');
var UglifyJsPlugin = require('uglify-js-plugin');
const path = require('path');

module.exports = {

devtool: 'inline-source-map',
entry: ['./src/index.js'],
output: {path: path.resolve(__dirname, "builds"), filename: 'bundle.js'},
module: {
rules: [
{
test: /\.jsx?$/,
use: [
{
loader: 'babel-loader'
}
]
},
{
test: /\.sass$/,
exclude: '/node_modules/',
use: ExtractTextPlugin.extract({
fallback: "style-loader",
loader: "css-loader!sass-loader"
})
}
]
},
resolve: {
extensions: ['.js', '.jsx', '.sass']
},
plugins: [
new ExtractTextPlugin({
filename: "stylesheets/style.css",
disable: false,
allChunks: true
}),
new webpack.ProvidePlugin({
"$": "jquery",
"jQuery": "jquery",
"window.jQuery": "jquery"
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
})
]

};

你们通常会做什么来加快 Karma 运行单元测试的速度?

我把代码放在:https://github.com/zainulfranciscus/karma-test每当我更新测试时,karma 都会花费 1 分 15 秒来启动,并花费 33 秒来运行测试。有 35 个单元测试

谢谢。

最佳答案

在此处查看 karma-parallel 插件: https://www.npmjs.com/package/karma-parallel

karma-sharding 插件相比,更流行且与 karma-webpack 兼容。

关于reactjs - 缓慢的 Karma 单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48015948/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com