Version 1.0.0
@stackline/grunt-karma
grunt plugin for karma test runner
Independent maintenance of grunt-karma 4.0.2. Original authors and licenses are retained.
Installation
# Preserve existing imports with an npm alias
npm install grunt-karma@npm:@stackline/grunt-karma@1.0.0
# Or use the scoped package name in your imports
npm install @stackline/grunt-karma@1.0.0Node.js: See compatibility notes. Read the compatibility and maintenance notes before migrating.
Usage and API
The reference below may retain upstream package names. Use the alias installation above to run those imports with this Stackline release.
@stackline/grunt-karma
Independent maintenance fork of grunt-karma@4.0.2. Original API, module format, runtime dependency ranges, and supported Node.js engines are preserved.
npm install @stackline/grunt-karma
# Preserve existing imports with an npm alias:
npm install grunt-karma@npm:@stackline/grunt-karma@1.0.0
See UPSTREAM.md for the exact source and issue review, and CHANGELOG.md for focused maintenance changes. Development and release tooling runs on Node.js 24; that does not change the library runtime requirement.
Maintained by Stackline. Issues · npm.
Upstream documentation
grunt-karma
Grunt plugin for Karma
This current version uses karma@^3.0.0. For using older versions see the
old releases of grunt-karma.
Getting Started
From the same directory as your project's Gruntfile and package.json, install karma and grunt-karma with the following commands:
$ npm install karma --save-dev
$ npm install grunt-karma --save-dev
Once that's done, add this line to your project's Gruntfile:
grunt.loadNpmTasks('grunt-karma');
Config
Inside your Gruntfile.js file, add a section named karma, containing
any number of configurations for running karma. You can either put your
config in a [karma config file] or leave it all in your Gruntfile (recommended).
Here's an example that points to the config file:
karma: {
unit: {
configFile: 'karma.conf.js'
}
}
Here's an example that puts the config in the Gruntfile:
karma: {
unit: {
options: {
files: ['test/**/*.js']
}
}
}
You can override any of the config file's settings by putting them directly in the Gruntfile:
karma: {
unit: {
configFile: 'karma.conf.js',
port: 9999,
singleRun: true,
browsers: ['PhantomJS'],
logLevel: 'ERROR'
}
}
To change the logLevel in the grunt config file instead of the karma config, use one of the following strings:
OFF, ERROR, WARN, INFO, DEBUG
The files option can be extended "per-target" in the typical way
Grunt handles files:
karma: {
options: {
files: ['lib/**/*.js']
},
unit: {
files: [
{ src: ['test/**/*.js'] }
]
}
}
When using the "Grunt way" of specifying files, you can also extend the file objects with the options supported by karma:
karma: {
unit: {
files: [
{ src: ['test/**/*.js'], served: true },
{ src: ['lib/**/*.js'], served: true, included: false }
]
}
}
Config with Grunt Template Strings in files
When using template strings in the files option, the results will flattened. Therefore, if you include a variable that includes an array, the array will be flattened before being passed to Karma.
Example:
meta: {
jsFiles: ['jquery.js','angular.js']
},
karma: {
options: {
files: ['<%= meta.jsFiles %>','angular-mocks.js','**/*-spec.js']
}
}
Sharing Configs
If you have multiple targets, it may be helpful to share common
configuration settings between them. Grunt-karma supports this by
using the options property:
karma: {
options: {
configFile: 'karma.conf.js',
port: 9999,
browsers: ['Chrome', 'Firefox']
},
continuous: {
singleRun: true,
browsers: ['PhantomJS']
},
dev: {
reporters: 'dots'
}
}
In this example the continuous and dev targets will both use
the configFile and port specified in the options. But
the continuous target will override the browser setting to use
PhantomJS, and also run as a singleRun. The dev target will simply
change the reporter to dots.
Running tests
There are three ways to run your tests with karma:
Karma Server with Auto Runs on File Change
Setting the autoWatch option to true will instruct karma to start
a server and watch for changes to files, running tests automatically:
karma: {
unit: {
configFile: 'karma.conf.js',
autoWatch: true
}
}
Now run $ grunt karma
Karma Server with Grunt Watch
Many Grunt projects watch several types of files using grunt-contrib-watch.
Config karma like usual (without the autoWatch option), and add
background:true:
karma: {
unit: {
configFile: 'karma.conf.js',
background: true,
singleRun: false
}
}
The background option will tell grunt to run karma in a child process
so it doesn't block subsequent grunt tasks.
The singleRun: false option will tell grunt to keep the karma server up
after a test run.
Config your watch task to run the karma task with the :run flag. For example:
watch: {
//run unit tests with karma (server needs to be already running)
karma: {
files: ['app/js/**/*.js', 'test/browser/**/*.js'],
tasks: ['karma:unit:run'] //NOTE the :run flag
}
},
In your terminal window run $ grunt karma:unit:start watch, which starts the
karma server and the watch task. Now when grunt watch detects a change to
one of your watched files, it will run the tests specified in the unit
target using the already running karma server. This is the preferred method
for development.
Single Run
Keeping a browser window & karma server running during development is
productive, but not a good solution for build processes. For that reason karma
provides a "continuous integration" mode, which will launch the specified
browser(s), run the tests, and close the browser(s). It also supports running
tests in PhantomJS, a headless webkit browser which is great for running tests as part of a build. To run tests in continous integration mode just add the singleRun option:
karma: {
unit: {
configFile: 'config/karma.conf.js',
},
//continuous integration mode: run tests once in PhantomJS browser.
continuous: {
configFile: 'config/karma.conf.js',
singleRun: true,
browsers: ['PhantomJS']
},
}
The build would then run grunt karma:continuous to start PhantomJS,
run tests, and close PhantomJS.
Using additional client.args
You can pass arbitrary client.args through the commandline like this:
$ grunt karma:dev watch --grep=mypattern
License
MIT License
Upstream issues and maintenance review
Upstream review
Source: grunt-karma@4.0.2, f9619531457237082176641a9103749e3faf462a. Existing published runtime files match the integrity-checked upstream npm tarball byte-for-byte. Generated adapter files, where applicable, are built from original sources. License and authorship notices remain unchanged.
Issue triage (2026-09-29)
- #311: Prototype pollution report: Keep the upstream4.0.2 source identity verified against the npm tarball; resolve the existing lodash^4.17.10 range to the patched release. Exercise all original single/config/merge/flatten task cases in real Chromium.
No upstream contact was made and no blanket issue-resolution claim is implied. Node24 is used for development only; published engine declarations remain unchanged.
Verification
npm ci --ignore-scripts, npm run build --if-present, npm test, npm run test:package, npm audit --audit-level=low. Exact CI tarballs require successful CI and CodeQL before provenance-enabled publication.
Release changes
Stackline changes
1.0.0
- Scoped maintenance fork of grunt-karma@4.0.2; preserve original library/task sources, API, dependencies and engines.
- Replace obsolete lint/release tools with modern development runners, retain functional upstream tests and add packed-consumer integration.
- Gate exact artifacts with full audit, CI, CodeQL, npm provenance and immutable GitHub releases.
4.0.2 (2021-05-11)
Bug Fixes
4.0.1 (2021-05-11)
Bug Fixes
4.0.0 (2020-04-14)
chore
BREAKING CHANGES
- ci: drop support for nodejs <8
3.0.2 (2019-04-09)
3.0.1 (2018-11-24)
Features
3.0.0 (2018-09-08)
Bug Fixes
- ensure proper path format (9314248)
- Remove hardcoded useIframe & captureConsole opts (33386b3), closes #165 #166
- deps: update lodash version to address npm audit warning (1182766), closes #259
- deps: Update test to use karma 3.0.0 (19551fd), closes #261 #251
Features
2.0.0 (2016-05-26)
Bug Fixes
- handle basePath option for preprocessors paths (1a45103), closes #146
- Make background option work with grunt tasks written in CoffeeScript (52174ef), closes #174
1.0.0 (2016-05-03)
0.12.2 (2016-03-17)
0.12.1 (2015-09-09)
Bug Fixes
<a name"0.12.0">
0.12.0 (2015-07-16)
Bug Fixes
- Updating grunt-karma to use the new API interface from Karma (5d1881c9)
- ensure files passed to karma are flat (6075d692, closes #142)
<a name"0.11.2">
0.11.2 (2015-06-29)
Bug Fixes
<a name"0.11.1">
0.11.1 (2015-06-19)
Bug Fixes
- Allow karma release candidate as peer dependency (5cdb1844)
<a name"0.11.0">
0.11.0 (2015-05-28)
Bug Fixes
- Allow for karma.conf to be used correctly Now client config is only passed to ka (15fee6f9, closes #119)
- Update dependencies (002926f4)
- Flatten files array. (7fe05940, closes #142
0.10.1 (2015-01-09)
Bug Fixes
0.10.0 (2015-01-09)
Features
0.9.0 (2014-09-04)
Features
conventional-changelog
- add conventional-changelog (72c67e3)
karma-dependency
- Bump Karma depdency to ~0.9.2 (23a4f25)
- make configFile optional (cee07ab)
0.8.3
- Flatten
filesinput (@cgross)
0.8.2
- Emergency fix: Don't pass anything to karma if no browsers are defined.
0.8.1
- Kill background child process on main process exit. (@trabianmatt)
- Fix passing
client.argsthrough the commandline. - Actually override the browsers array.
- Set client default args.
- Merge
client.argsfrom all sources.
0.8.0
- Update to
karma@0.12.0
#0.3.0
- changed name from gruntacular to grunt-karma
#0.2.0
- support config sharing via options property
- basic example/test suite
- slight refactor
- use latest testacular
#0.1.1
- initial version
- docs
Release files and references
- README.md
- UPSTREAM.md
- CHANGELOG.md
- LICENSE
- NOTICE
- Package and publication metadata
- Full text documentation
Package bytes, npm provenance and the immutable GitHub release were verified for this version. Security checks describe the reviewed release; documented compatibility risks and upstream reports are not blanket claims of resolution.