Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow Karma Unit Tests

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 ?

I put the code at: https://github.com/zainulfranciscus/karma-test karma took 1 min 15 sec to start and 33 seconds to ran the tests, whenever I updated a test. There are 35 unit tests

Thank you.

like image 824
zfranciscus Avatar asked Apr 20 '26 12:04

zfranciscus


1 Answers

Check out the karma-parallel plugin here: https://www.npmjs.com/package/karma-parallel

More popular and karma-webpack compatible compared to the karma-sharding plugin.

like image 85
Mikeumus Avatar answered Apr 22 '26 02:04

Mikeumus