karma-babel-polyfill
raw JSON → 0.0.5 verified Sat Apr 25 auth: no javascript deprecated
A Karma plugin that injects babel-polyfill into the test browser environment, ensuring that ES2015+ APIs (e.g., Promise, Map, Set) are available when running tests with Karma. Version 0.0.5 is the final release; the package has not been updated since 2016 and is considered deprecated in favor of using @babel/polyfill or @babel/regenerator directly with Karma's configuration. It requires karma as a peer dependency and is designed for use with older Babel 6 setups.
Common errors
error Error: Cannot find module 'karma-babel-polyfill' ↓
cause Package not installed or not listed in plugins array in karma.conf.js.
fix
Run: npm install --save-dev karma-babel-polyfill
Then add 'karma-babel-polyfill' to the plugins array in karma.conf.js.
error TypeError: babelPolyfill is not a function ↓
cause Incorrect usage of the module via import or require in wrong context.
fix
Do not manually call require('karma-babel-polyfill') in config; instead use the string 'babel-polyfill' in the frameworks array.
error ReferenceError: regeneratorRuntime is not defined ↓
cause babel-polyfill may not be loaded before test files; also may need add regenerator runtime.
fix
Ensure 'babel-polyfill' is in frameworks array. If using async/await, consider using @babel/plugin-transform-runtime.
Warnings
deprecated Package has not been updated since 2016 and relies on deprecated babel-polyfill which is no longer maintained. ↓
fix Migrate to using @babel/polyfill or @babel/regenerator with Karma's single-run mode, or use core-js directly.
gotcha Frameworks entry must be 'babel-polyfill' not 'karma-babel-polyfill' ↓
fix In karma.conf.js, set frameworks: ['babel-polyfill']
gotcha The package only provides CommonJS module; cannot be imported via ES import. ↓
fix Use require() or list in karma.conf.js as string.
breaking Only works with Babel 6; not compatible with Babel 7 or @babel/core. ↓
fix Update to @babel/polyfill and corresponding Karma plugins.
Install
npm install karma-babel-polyfill yarn add karma-babel-polyfill pnpm add karma-babel-polyfill Imports
- default wrong
import karmaBabelPolyfill from 'karma-babel-polyfill';correctmodule.exports = require('karma-babel-polyfill'); - frameworks wrong
frameworks: ['karma-babel-polyfill']correctframeworks: ['babel-polyfill'] - plugins wrong
plugins: [require('karma-babel-polyfill')]correctplugins: ['karma-babel-polyfill']
Quickstart
// karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['mocha', 'babel-polyfill'], // Add 'babel-polyfill'
files: ['test/**/*.js'],
preprocessors: {
'test/**/*.js': ['babel']
},
babelPreprocessor: {
options: {
presets: ['env']
}
},
plugins: ['karma-babel-polyfill', 'karma-mocha', 'karma-chrome-launcher', 'karma-babel-preprocessor'],
browsers: ['ChromeHeadless'],
singleRun: true
});
};
// Install: npm install --save-dev karma-babel-polyfill karma karma-mocha karma-chrome-launcher karma-babel-preprocessor babel-preset-env