Я использую Karma Test Runner в своем приложении React для запуска модульных тестов. На выполнение всех тестов уходит около 3 часов. Кроме того, когда я пытаюсь запустить один тестовый файл, это занимает около 4-5 минут. Это действительно очень медленно. Вот мой файл конфигурации кармы. Пожалуйста, предложите:
/* eslint-disable import/no-commonjs */
const path = require('path');
const webpackConfig = require('./webpack.config');
webpackConfig.module.exprContextCritical = false;
webpackConfig.externals = {
'react/addons': 'react',
'react/lib/ExecutionEnvironment': 'react',
'react/lib/ReactContext': 'react',
'react-addons-test-utils': 'react-dom',
};
if (!webpackConfig.resolve.alias) {
webpackConfig.resolve.alias = {};
}
webpackConfig.resolve.alias['fs'] = path.resolve(__dirname, 'src/utilities/fsMock');
webpackConfig.devtool = false;
process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = function (config) {
config.set({
browsers: [ 'customChromium' ],
customLaunchers: {
ChromeDebugging: {
base: 'Chrome',
flags: [
'--remote-debugging-port=9333',
],
},
customChromium: {
base: 'ChromeHeadless',
flags: [
'--no-sandbox',
'--disable-setuid-sandbox',
],
},
},
singleRun: true, // just run once by default. Must set to false for ChromeDebugging.
browserNoActivityTimeout: 60000,
frameworks: [ 'mocha', 'chai', 'sinon' ],
logLevel: 'error',
client: {
captureConsole: true,
},
browserConsoleLogOptions: {
level: '',
terminal: true,
format: '%b %T: %m',
},
files: [
// Include babel-polyfill, because PhantomJS is a really old browser
'node_modules/babel-polyfill/dist/polyfill.js',
// All the files that should be loaded as test entrypoints
{ pattern: 'tests/*.js' },
{ pattern: 'tests/**/*.js' },
{ pattern: 'src/*.test.js' },
{ pattern: 'src/**/*.test.js' },
],
plugins: [
'karma-chai',
'karma-mocha',
'karma-sinon',
'karma-sourcemap-loader',
'karma-webpack',
'karma-coverage',
'karma-mocha-reporter',
'karma-phantomjs-launcher',
'karma-chrome-launcher',
'karma-spec-reporter',
],
preprocessors: {
'tests/*.js': [ 'webpack' ],
'tests/**/*.js': [ 'webpack' ],
'src/*.js': [ 'webpack' ],
'src/**/*.js': [ 'webpack' ],
},
reporters: [ // report results in these formats. Installed reporters. spec: pass-fail, dot: progress, code coverage
// 'spec',
'dots',
// 'progress',
//'coverage',
],
specReporter: {
maxLogLines: 5, // limit number of lines logged per test
suppressErrorSummary: true, // do not print error summary
suppressFailed: false, // do not print information about failed tests
suppressPassed: false, // do not print information about passed tests
suppressSkipped: true, // do not print information about skipped tests
showSpecTiming: false,// print the time elapsed for each spec
},
webpack: webpackConfig,
webpackMiddleware: {
noInfo: true, // don't spam the console
stats: 'errors-only',
watchOptions: { poll: 10 },
},
coverageReporter: {
reporters: [
//{
// type: 'html', // produces a html document after code is run
// dir: 'coverage/', // path to created html doc
//},
//{
// type: 'text', // produces a text document after code is run.
// dir: 'coverage/', // path to created html doc
// file : 'coverage.txt' // file name for text output if type is text
//},
],
},
});
};
Кроме того, необходимо ли использовать препроцессор в файле karma.config? Если я удаляю препроцессор, тест выполняется быстро, но выдает ошибку «Невозможно использовать оператор импорта вне модуля».