All Projects → ryanclark → Karma Webpack

ryanclark / Karma Webpack

Licence: mit
Karma webpack Middleware

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Karma Webpack

Extract Text Webpack Plugin
[DEPRECATED] Please use https://github.com/webpack-contrib/mini-css-extract-plugin Extracts text from a bundle into a separate file
Stars: ✭ 4,071 (+397.68%)
Mutual labels:  webpack-plugin
Optimize Plugin
Optimized Webpack Bundling for Everyone. Intro ⤵️
Stars: ✭ 525 (-35.82%)
Mutual labels:  webpack-plugin
Duplicate Package Checker Webpack Plugin
🕵️ Webpack plugin that warns you when a build contains multiple versions of the same package
Stars: ✭ 635 (-22.37%)
Mutual labels:  webpack-plugin
Mini Css Extract Plugin
Lightweight CSS extraction plugin
Stars: ✭ 4,396 (+437.41%)
Mutual labels:  webpack-plugin
Offline Plugin
Offline plugin (ServiceWorker, AppCache) for webpack (https://webpack.js.org/)
Stars: ✭ 4,444 (+443.28%)
Mutual labels:  webpack-plugin
Jasmine Matchers
Write Beautiful Specs with Custom Matchers for Jest and Jasmine
Stars: ✭ 552 (-32.52%)
Mutual labels:  karma
Moment Locales Webpack Plugin
Easily remove unused Moment.js locales with webpack
Stars: ✭ 396 (-51.59%)
Mutual labels:  webpack-plugin
Unit Test Demo
一步一步介绍如何给项目添加单元测试
Stars: ✭ 766 (-6.36%)
Mutual labels:  karma
Babel Minify Webpack Plugin
[DEPRECATED] Babel Minify Webpack Plugin
Stars: ✭ 502 (-38.63%)
Mutual labels:  webpack-plugin
Nwb
A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)
Stars: ✭ 5,429 (+563.69%)
Mutual labels:  karma
Angular Testing Recipes
Simple testing patterns for Angular version 2+
Stars: ✭ 450 (-44.99%)
Mutual labels:  karma
Webpack Spritesmith
Webpack plugin that converts set of images into a spritesheet and SASS/LESS/Stylus mixins
Stars: ✭ 468 (-42.79%)
Mutual labels:  webpack-plugin
Kotlin Frontend Plugin
Gradle Kotlin (http://kotlinlang.org) plugin for frontend development
Stars: ✭ 578 (-29.34%)
Mutual labels:  karma
Karma Chrome Launcher
A Karma plugin. Launcher for Chrome and Chrome Canary.
Stars: ✭ 441 (-46.09%)
Mutual labels:  karma
Generator M Ionic
Advanced workflows and setup for building rock-solid Ionic apps
Stars: ✭ 677 (-17.24%)
Mutual labels:  karma
Spring Boot Angular2
spring boot backend, angular2 frontend with webpack, typescript, sass, bootstrap4, karma, jasmine
Stars: ✭ 396 (-51.59%)
Mutual labels:  karma
Webpack Config Plugins
Provide best practices for webpack loader configurations
Stars: ✭ 529 (-35.33%)
Mutual labels:  webpack-plugin
Purifycss Webpack
UNMAINTAINED, use https://github.com/FullHuman/purgecss-webpack-plugin
Stars: ✭ 789 (-3.55%)
Mutual labels:  webpack-plugin
Purgecss
Remove unused CSS
Stars: ✭ 6,566 (+702.69%)
Mutual labels:  webpack-plugin
Webpack Deep Scope Analysis Plugin
A webpack plugin for deep scope analysis
Stars: ✭ 589 (-28%)
Mutual labels:  webpack-plugin

npm node deps test coverage chat

Karma Webpack

Use webpack to preprocess files in karma

Install

npm npm i -D karma-webpack

yarn yarn add -D karma-webpack

Usage

karma.conf.js

module.exports = (config) => {
  config.set({
    // ... normal karma configuration

    // make sure to include webpack as a framework
    frameworks: ['mocha', 'webpack'],
    
    plugins: [
      'karma-webpack',
      'karma-mocha',
    ],

    files: [
      // all files ending in ".test.js"
      // !!! use watched: false as we use webpacks watch
      { pattern: 'test/**/*.test.js', watched: false }
    ],

    preprocessors: {
      // add webpack as preprocessor
      'test/**/*.test.js': [ 'webpack' ]
    },

    webpack: {
      // karma watches the test entry points
      // Do NOT specify the entry option
      // webpack watches dependencies

      // webpack configuration
    },
  });
}

Default webpack configuration

This configuration will be merged with what gets provided via karma's config.webpack.

const defaultWebpackOptions = {
  mode: 'development',
  output: {
    filename: '[name].js',
    path: path.join(os.tmpdir(), '_karma_webpack_') + Math.floor(Math.random() * 1000000),
  },
  stats: {
    modules: false,
    colors: true,
  },
  watch: false,
  optimization: {
    runtimeChunk: 'single',
    splitChunks: {
      chunks: 'all',
      minSize: 0,
      cacheGroups: {
        commons: {
          name: 'commons',
          chunks: 'initial',
          minChunks: 1,
        },
      },
    },
  },
  plugins: [],
};

How it works

This project is a framework and preprocessor for Karma that combines test files and dependencies into 2 shared bundles and 1 chunk per test file. It relies on webpack to generate the bundles/chunks and to keep it updated during autoWatch=true.

The first preproccessor triggers the build of all the bundles/chunks and all following files just return the output of this one build process.

Webpack typescript support

By default karma-webpack forces *.js files so if you test *.ts files and use webpack to build typescript to javascript it works out of the box.

If you have a different need you can override by settig webpack.transformPath

// this is the by default applied transformPath
webpack: {
  transformPath: (filepath) => {
      // force *.js files by default
      const info = path.parse(filepath);
      return `${path.join(info.dir, info.name)}.js`;
    },
},

Source Maps

You can use the karma-sourcemap-loader to get the source maps generated for your test bundle.

npm i -D karma-sourcemap-loader

And then add it to your preprocessors.

karma.conf.js

preprocessors: {
  'test/test_index.js': [ 'webpack', 'sourcemap' ]
}

And tell webpack to generate sourcemaps.

webpack.config.js

webpack: {
  // ...
  devtool: 'inline-source-map'
}

Maintainers


Ryan Clark

Cody Mikol

April Arcus

Previous Maintainers

Previous maintainers of the karma-webpack plugin that have done such amazing work to get it to where it is today.

Mika Kalathil Joshua Wiens Will Farley Daniela Valero
Jonathan Trang Carlos Morales
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].