I wrote unit tests for a small reach application using Jasmine and Karma.And Karma is running slow for these tests.
This is my karma config:
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) } });
}
This is my 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 } }) ]
};
What do you guys usually do to speed up Karma in running unit tests ?
Thank you.
1 Answers
Answers 1
Have you looked at karma-sharding? This plugin addresses some memory usage problems with some browsers, and numerous or memory intensive specs.
It will not run your tests all in parallel, but as of version 4.0.0, it supports parallel browser execution(i.e. will shard tests across browsers listed in your karma.conf.js
)
0 comments:
Post a Comment