├── .eslintrc ├── .gitignore ├── CONTRIBUTING.md ├── PULL_REQUEST_TEMPLATE.md ├── lib └── background.js ├── TODO.md ├── .mailmap ├── karma.conf.js ├── .travis.yml ├── test └── grunt-karma-test.js ├── release.config.js ├── LICENSE ├── gruntfile.js ├── package.json ├── tasks └── grunt-karma.js ├── CHANGELOG.md └── README.md /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "standard" 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .project 3 | .settings -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Please see our [contribution guidelines](http://karma-runner.github.io/latest/dev/contributing.html). 4 | -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please make sure that your commit messages follow our [convention](http://karma-runner.github.io/latest/dev/git-commit-msg.html)! 2 | -------------------------------------------------------------------------------- /lib/background.js: -------------------------------------------------------------------------------- 1 | var Server = require('karma').Server 2 | 3 | process.on('message', function (data) { 4 | var server = new Server(data.config) 5 | server.start() 6 | }) 7 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | [] make config file optional 2 | [] move all config into Gruntfile and update docs about that option, once next release 3 | [ ] FIX - don't fail Grunt on failing tests during watch... -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | 2 | dignifiedquire 3 | dignifiedquire 4 | 5 | Michał Gołębiowski-Owczarek 6 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration 2 | 3 | module.exports = function(config) { 4 | config.set({ 5 | 6 | // list of files / patterns to load in the browser 7 | files: [ 8 | 'node_modules/expect.js/index.js', 9 | 'test/**/*.js' 10 | ] 11 | }); 12 | }; 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 10 4 | - 12 5 | 6 | before_install: 7 | - npm config set loglevel warn 8 | 9 | services: 10 | - xvfb 11 | 12 | script: 13 | - commitlint-travis 14 | - npm test 15 | 16 | after_success: 17 | # run automated release process with semantic-release 18 | - if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_EVENT_TYPE" == "push" && "$TRAVIS_NODE_VERSION" == "12" ]]; then 19 | semantic-release; 20 | fi; -------------------------------------------------------------------------------- /test/grunt-karma-test.js: -------------------------------------------------------------------------------- 1 | /* global describe, it, expect */ 2 | 3 | describe('grunt-karma', function () { 4 | describe('one', function () { 5 | it('should be awesome', function () { 6 | console.log('one') 7 | expect('foo').to.be.a('string') 8 | }) 9 | }) 10 | 11 | describe('two', function () { 12 | it('should be equally awesome', function () { 13 | console.log('two') 14 | expect('woot').to.be.a('string') 15 | }) 16 | }) 17 | }) 18 | -------------------------------------------------------------------------------- /release.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | debug: true, 3 | branches: 'master', 4 | verifyConditions: [ 5 | '@semantic-release/changelog', 6 | '@semantic-release/github', 7 | '@semantic-release/npm' 8 | ], 9 | prepare: [ 10 | '@semantic-release/changelog', 11 | '@semantic-release/git', 12 | '@semantic-release/npm' 13 | ], 14 | publish: [ 15 | '@semantic-release/github', 16 | '@semantic-release/npm' 17 | ], 18 | success: [ 19 | '@semantic-release/github' 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Dave Geddes 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function (grunt) { 2 | var plugins = ['karma-mocha'] 3 | var browsers = [] 4 | 5 | if (process.env.TRAVIS) { 6 | plugins.push('karma-firefox-launcher') 7 | browsers.push('Firefox') 8 | } else { 9 | plugins.push('karma-chrome-launcher') 10 | browsers.push('Chrome') 11 | } 12 | 13 | grunt.initConfig({ 14 | pkg: grunt.file.readJSON('package.json'), 15 | 16 | eslint: { 17 | target: [ 18 | 'gruntfile.js', 19 | 'lib/*.js', 20 | 'tasks/*.js', 21 | 'test/*.js' 22 | ] 23 | }, 24 | 25 | 'npm-publish': { 26 | options: { 27 | abortIfDirty: true 28 | } 29 | }, 30 | 31 | 'npm-contributors': { 32 | options: { 33 | commitMessage: 'chore: Update contributors' 34 | } 35 | }, 36 | 37 | conventionalChangelog: { 38 | release: { 39 | options: { 40 | changelogOpts: { 41 | preset: 'angular' 42 | } 43 | }, 44 | src: 'CHANGELOG.md' 45 | } 46 | }, 47 | 48 | conventionalGithubReleaser: { 49 | release: { 50 | options: { 51 | auth: { 52 | type: 'oauth', 53 | token: process.env.GH_TOKEN 54 | }, 55 | changelogOpts: { 56 | preset: 'angular' 57 | } 58 | } 59 | } 60 | }, 61 | 62 | bump: { 63 | options: { 64 | updateConfigs: ['pkg'], 65 | commitFiles: ['package.json', 'CHANGELOG.md'], 66 | commitMessage: 'chore: release v%VERSION%', 67 | pushTo: 'upstream', 68 | gitDescribeOptions: '| echo "beta-$(git rev-parse --short HEAD)"' 69 | } 70 | }, 71 | 72 | karma: { 73 | options: { 74 | browsers: browsers, 75 | frameworks: ['mocha'], 76 | plugins: plugins 77 | }, 78 | single: { 79 | singleRun: true, 80 | files: [ 81 | { 82 | src: 'node_modules/expect.js/index.js' 83 | }, { 84 | src: 'test/**/*.js' 85 | } 86 | ] 87 | }, 88 | config: { 89 | configFile: 'karma.conf.js', 90 | singleRun: true 91 | }, 92 | merge: { 93 | options: { 94 | files: ['node_modules/expect.js/index.js'] 95 | }, 96 | singleRun: true, 97 | files: [ 98 | { 99 | src: 'test/**/*.js' 100 | } 101 | ] 102 | }, 103 | flatten: { 104 | options: { 105 | files: [ 106 | [['node_modules/expect.js/index.js']], 107 | [[['test/**/*.js']]] 108 | ] 109 | }, 110 | singleRun: true 111 | }, 112 | background: { 113 | background: true, 114 | files: [ 115 | { 116 | src: 'node_modules/expect.js/index.js' 117 | }, { 118 | src: 'test/**/*.js' 119 | } 120 | ] 121 | }, 122 | dev: { 123 | reporters: 'dots', 124 | background: true 125 | }, 126 | auto: { 127 | autoWatch: true 128 | } 129 | }, 130 | watch: { 131 | tests: { 132 | files: 'test/**/*.js', 133 | tasks: ['karma:dev:run'] 134 | }, 135 | bgtest: { 136 | // This is just to stop node exiting 137 | files: 'test/**/*.js', 138 | tasks: [] 139 | } 140 | } 141 | }) 142 | 143 | grunt.loadTasks('tasks') 144 | require('load-grunt-tasks')(grunt) 145 | 146 | grunt.registerTask('test', [ 147 | 'eslint', 148 | 'karma:single', 149 | 'karma:config', 150 | 'karma:merge', 151 | 'karma:flatten' 152 | ]) 153 | grunt.registerTask('default', ['test']) 154 | grunt.registerTask('bgtest', ['karma:background', 'watch:bgtest']) 155 | 156 | grunt.registerTask('release', 'Bump the version and publish to npm.', function (type) { 157 | grunt.task.run([ 158 | 'npm-contributors', 159 | 'bump:' + (type || 'patch') + ':bump-only', 160 | 'conventionalChangelog', 161 | 'bump-commit', 162 | 'conventionalGithubReleaser', 163 | 'npm-publish' 164 | ]) 165 | }) 166 | } 167 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "grunt-karma", 3 | "version": "3.0.2", 4 | "description": "grunt plugin for karma test runner", 5 | "main": "tasks/grunt-karma.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/karma-runner/grunt-karma.git" 9 | }, 10 | "keywords": [ 11 | "gruntplugin", 12 | "karma", 13 | "grunt", 14 | "test", 15 | "unit", 16 | "runner", 17 | "TDD" 18 | ], 19 | "scripts": { 20 | "test": "grunt" 21 | }, 22 | "author": "Dave Geddes", 23 | "license": "MIT", 24 | "readmeFilename": "README.md", 25 | "dependencies": { 26 | "lodash": "^4.17.10" 27 | }, 28 | "devDependencies": { 29 | "@commitlint/cli": "^8.3.5", 30 | "@commitlint/travis-cli": "^8.3.5", 31 | "@commitlint/config-conventional": "^8.3.4", 32 | "@semantic-release/changelog": "5.0.1", 33 | "@semantic-release/git": "9.0.0", 34 | "@semantic-release/npm": "7.0.5", 35 | "eslint": "^5.4.0", 36 | "eslint-config-standard": "^11.0.0", 37 | "eslint-plugin-import": "^2.14.0", 38 | "eslint-plugin-node": "^7.0.1", 39 | "eslint-plugin-promise": "^4.0.0", 40 | "eslint-plugin-standard": "^3.1.0", 41 | "expect.js": "^0.3.1", 42 | "grunt": "^1.1.0", 43 | "grunt-bump": "0.8.0", 44 | "grunt-contrib-watch": "^1.0.0", 45 | "grunt-conventional-changelog": "^6.1.0", 46 | "grunt-conventional-github-releaser": "^1.0.0", 47 | "grunt-eslint": "^21.0.0", 48 | "grunt-npm": "0.0.2", 49 | "husky": "^4.2.3", 50 | "karma": "^5.0.1", 51 | "karma-chrome-launcher": "^2.2.0", 52 | "karma-firefox-launcher": "^1.0.0", 53 | "karma-mocha": "1.x || ^0.2.0", 54 | "load-grunt-tasks": "^3.2.0", 55 | "mocha": "^3.4.2", 56 | "semantic-release": "17.0.4" 57 | }, 58 | "peerDependencies": { 59 | "grunt": ">=0.4.x", 60 | "karma": "^4.0.0 || ^5.0.0 || ^6.0.0" 61 | }, 62 | "commitlint": { 63 | "extends": [ 64 | "@commitlint/config-conventional" 65 | ] 66 | }, 67 | "husky": { 68 | "hooks": { 69 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" 70 | } 71 | }, 72 | "contributors": [ 73 | "Dave Geddes ", 74 | "Timo Tijhof ", 75 | "johnjbarton ", 76 | "Julian Motz ", 77 | "Michał Gołębiowski-Owczarek ", 78 | "XhmikosR ", 79 | "Mark Ethan Trostler ", 80 | "dsuckau ", 81 | "Greenkeeper ", 82 | "James Ford ", 83 | "James Forrester ", 84 | "Jeremy Vinai ", 85 | "Jonas Pommerening ", 86 | "Jonny Arnold ", 87 | "Julian ", 88 | "Luis Almeida ", 89 | "Matt Dean ", 90 | "Max Riveiro ", 91 | "Mike Dimmick ", 92 | "Nicolas Breitwieser ", 93 | "Olivier Amblet ", 94 | "Pascal Precht ", 95 | "Robin Hu ", 96 | "Robin Liang ", 97 | "Roman Morozov ", 98 | "Sahat Yalkabov ", 99 | "Valentin Hervieu ", 100 | "Vaughan Hilts ", 101 | "Vlad Filippov ", 102 | "Vojta Jina ", 103 | "enigmak ", 104 | "facboy ", 105 | "jiverson ", 106 | "joshrtay ", 107 | "kolesnik ", 108 | "Adrian ", 109 | "m7r ", 110 | "Alexander Slansky ", 111 | "Alexey Kucherenko ", 112 | "Chris Gross ", 113 | "Chris Wren ", 114 | "Christian Reed ", 115 | "Christoph Kraemer ", 116 | "Daniel Herman ", 117 | "Eddie Monge " 118 | ] 119 | } 120 | -------------------------------------------------------------------------------- /tasks/grunt-karma.js: -------------------------------------------------------------------------------- 1 | /* 2 | * grunt-karma 3 | * https://github.com/karma-runner/grunt-karma 4 | * 5 | * Copyright (c) 2013 Dave Geddes 6 | * Licensed under the MIT license. 7 | */ 8 | 9 | var runner = require('karma').runner 10 | var Server = require('karma').Server 11 | var parseConfig = require('karma').config.parseConfig 12 | var path = require('path') 13 | var _ = require('lodash') 14 | 15 | function finished (code) { 16 | return this(code === 0) 17 | } 18 | 19 | // Parse out all cli arguments in the form of `--arg=something` or 20 | // `-c=otherthing` and return the array. 21 | function parseArgs (args) { 22 | return _.filter(args, function (arg) { 23 | return arg.match(/^--?/) 24 | }) 25 | } 26 | 27 | module.exports = function (grunt) { 28 | grunt.registerMultiTask('karma', 'run karma.', function () { 29 | var done = this.async() 30 | var options = this.options({ 31 | background: false, 32 | client: {} 33 | }) 34 | 35 | // Allow for passing cli arguments to `client.args` using `--grep=x` 36 | var args = parseArgs(process.argv.slice(2)) 37 | if (options.client && _.isArray(options.client.args)) { 38 | args = options.client.args.concat(args) 39 | } 40 | 41 | // If arguments are provided we pass them to karma 42 | if (args.length > 0) { 43 | if (!options.client) { 44 | options.client = {} 45 | } 46 | options.client.args = args 47 | } 48 | 49 | // Only create client info if data is provided 50 | if (options.client) { 51 | // Merge karma default options 52 | _.defaults(options.client, { 53 | args: [] 54 | }) 55 | } 56 | 57 | var opts = _.cloneDeep(options) 58 | // Merge options onto data, with data taking precedence. 59 | var data = _.merge(opts, this.data) 60 | 61 | // But override the browsers array. 62 | if (data.browsers && this.data.browsers) { 63 | data.browsers = this.data.browsers 64 | } 65 | 66 | // Merge client.args 67 | if (this.data.client && _.isArray(this.data.client.args)) { 68 | data.client.args = this.data.client.args.concat(options.client.args) 69 | } 70 | 71 | if (data.configFile) { 72 | data.configFile = path.resolve(data.configFile) 73 | } 74 | 75 | // Combines both sets of files. The order should be: 76 | // - first, values from options.files, 77 | // - then, values from this.files. 78 | if (options.files || this.files.length) { 79 | // For our 'files' option, we support arbitrarily nested arrays, 80 | // as a convenient way to specify files without the user needing to 81 | // concat or flatten anything within their Gruntfile. 82 | data.files = _.flattenDeep(options.files || []) 83 | // The 'files' task data expanded by Grunt internally produces 84 | // a structure that is exactly 2 levels deep. 85 | this.files.forEach((file) => { 86 | file.src.forEach((src) => { 87 | let obj = { 88 | pattern: src 89 | }; 90 | ['watched', 'served', 'included'].forEach((opt) => { 91 | if (opt in file) { 92 | obj[opt] = file[opt] 93 | } 94 | }) 95 | data.files.push(obj) 96 | }) 97 | }) 98 | } 99 | 100 | // Allow the use of templates in preprocessors 101 | if (_.isPlainObject(data.preprocessors)) { 102 | var preprocessors = {} 103 | Object.keys(data.preprocessors).forEach(function (key) { 104 | var value = data.preprocessors[key] 105 | if (options.basePath) { 106 | key = path.join(options.basePath, key) 107 | } 108 | key = path.resolve(key) 109 | key = grunt.template.process(key) 110 | preprocessors[key] = value 111 | }) 112 | data.preprocessors = preprocessors 113 | } 114 | 115 | // support `karma run`, useful for grunt watch 116 | if (this.flags.run) { 117 | runner.run(data, finished.bind(done)) 118 | return 119 | } 120 | 121 | // allow karma to be run in the background so it doesn't block grunt 122 | if (data.background) { 123 | var backgroundProcess = require('child_process').fork( 124 | path.join(__dirname, '..', 'lib', 'background.js') 125 | ) 126 | 127 | backgroundProcess.on('close', function (code) { 128 | var error = code 129 | if (error) { 130 | grunt.log.error('background karma process exited with error (code: ' + code + ')') 131 | } 132 | }) 133 | 134 | process.on('exit', function () { 135 | backgroundProcess.kill() 136 | }) 137 | 138 | backgroundProcess.send({ config: data }) 139 | done() 140 | } else { 141 | var parsedConfig = parseConfig( 142 | data.configFile, 143 | data, 144 | {promiseConfig: true, throwErrors: true} 145 | ) 146 | if (parsedConfig.then) { 147 | parsedConfig.then(function (config) { 148 | var server = new Server(config, finished.bind(done)) 149 | server.start() 150 | }) 151 | } else { 152 | // Support: Karma < 6 153 | var server = new Server(data, finished.bind(done)) 154 | server.start() 155 | } 156 | } 157 | }) 158 | } 159 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [4.0.2](https://github.com/karma-runner/grunt-karma/compare/v4.0.1...v4.0.2) (2021-05-11) 2 | 3 | 4 | ### Bug Fixes 5 | 6 | * **karma:** accept karma 6.x in peerDependencies ([#303](https://github.com/karma-runner/grunt-karma/issues/303)) ([fe01a67](https://github.com/karma-runner/grunt-karma/commit/fe01a67d5d85748f2bbe62a96e2ff52e0d2968d7)) 7 | 8 | ## [4.0.1](https://github.com/karma-runner/grunt-karma/compare/v4.0.0...v4.0.1) (2021-05-11) 9 | 10 | 11 | ### Bug Fixes 12 | 13 | * **karma:** use recommended parseConfig pattern for Karma 6 ([#297](https://github.com/karma-runner/grunt-karma/issues/297)) ([a38d9a9](https://github.com/karma-runner/grunt-karma/commit/a38d9a9d896ed8ef6441a17094350a5f3bc2ea2d)) 14 | 15 | # [4.0.0](https://github.com/karma-runner/grunt-karma/compare/v3.0.2...v4.0.0) (2020-04-14) 16 | 17 | 18 | ### chore 19 | 20 | * **ci:** support semanitic-release ([#277](https://github.com/karma-runner/grunt-karma/issues/277)) ([caba218](https://github.com/karma-runner/grunt-karma/commit/caba2181e1541b5461e13ee1c4e09b6064e73465)) 21 | 22 | 23 | ### BREAKING CHANGES 24 | 25 | * **ci:** drop support for nodejs <8 26 | 27 | 28 | ## [3.0.2](https://github.com/karma-runner/grunt-karma/compare/v3.0.1...v3.0.2) (2019-04-09) 29 | 30 | 31 | 32 | 33 | ## [3.0.1](https://github.com/karma-runner/grunt-karma/compare/v3.0.0...v3.0.1) (2018-11-24) 34 | 35 | 36 | ### Features 37 | 38 | * **karma:** require karma 3 in peerDependencies ([579f82f](https://github.com/karma-runner/grunt-karma/commit/579f82f)), closes [#261](https://github.com/karma-runner/grunt-karma/issues/261) 39 | 40 | 41 | 42 | 43 | # [3.0.0](https://github.com/karma-runner/grunt-karma/compare/v2.0.0...v3.0.0) (2018-09-08) 44 | 45 | 46 | ### Bug Fixes 47 | 48 | * ensure proper path format ([9314248](https://github.com/karma-runner/grunt-karma/commit/9314248)) 49 | * Remove hardcoded useIframe & captureConsole opts ([33386b3](https://github.com/karma-runner/grunt-karma/commit/33386b3)), closes [#165](https://github.com/karma-runner/grunt-karma/issues/165) [#166](https://github.com/karma-runner/grunt-karma/issues/166) 50 | * **deps:** update lodash version to address npm audit warning ([1182766](https://github.com/karma-runner/grunt-karma/commit/1182766)), closes [#259](https://github.com/karma-runner/grunt-karma/issues/259) 51 | * **deps:** Update test to use karma 3.0.0 ([19551fd](https://github.com/karma-runner/grunt-karma/commit/19551fd)), closes [#261](https://github.com/karma-runner/grunt-karma/issues/261) [#251](https://github.com/karma-runner/grunt-karma/issues/251) 52 | 53 | 54 | ### Features 55 | 56 | * upgrade dependencies ([a911ca1](https://github.com/karma-runner/grunt-karma/commit/a911ca1)), closes [#178](https://github.com/karma-runner/grunt-karma/issues/178) [#175](https://github.com/karma-runner/grunt-karma/issues/175) 57 | 58 | 59 | 60 | 61 | # 2.0.0 (2016-05-26) 62 | 63 | 64 | ### Bug Fixes 65 | 66 | * handle basePath option for preprocessors paths ([1a45103](https://github.com/karma-runner/grunt-karma/commit/1a45103)), closes [#146](https://github.com/karma-runner/grunt-karma/issues/146) 67 | * Make background option work with grunt tasks written in CoffeeScript ([52174ef](https://github.com/karma-runner/grunt-karma/commit/52174ef)), closes [#174](https://github.com/karma-runner/grunt-karma/issues/174) 68 | 69 | 70 | 71 | 72 | # 1.0.0 (2016-05-03) 73 | 74 | 75 | 76 | 77 | 78 | ## 0.12.2 (2016-03-17) 79 | 80 | 81 | 82 | 83 | 84 | ## 0.12.1 (2015-09-09) 85 | 86 | 87 | ### Bug Fixes 88 | 89 | * **task:** prevent `spawn ENAMETOOLONG` on Windows ([2b5e643](https://github.com/karma-runner/grunt-karma/commit/2b5e643)) 90 | * Upgrade dependencies ([27abcda](https://github.com/karma-runner/grunt-karma/commit/27abcda)) 91 | 92 | 93 | 94 | 95 | ## 0.12.0 (2015-07-16) 96 | 97 | 98 | #### Bug Fixes 99 | 100 | * Updating grunt-karma to use the new API interface from Karma ([5d1881c9](https://github.com/karma-runner/grunt-karma/commit/5d1881c9)) 101 | * ensure files passed to karma are flat ([6075d692](https://github.com/karma-runner/grunt-karma/commit/6075d692), closes [#142](https://github.com/karma-runner/grunt-karma/issues/142)) 102 | 103 | 104 | 105 | ### 0.11.2 (2015-06-29) 106 | 107 | 108 | #### Bug Fixes 109 | 110 | * ensure files passed to karma are flat ([6075d692](https://github.com/karma-runner/grunt-karma/commit/6075d692), closes [#142](https://github.com/karma-runner/grunt-karma/issues/142)) 111 | 112 | 113 | 114 | ### 0.11.1 (2015-06-19) 115 | 116 | 117 | #### Bug Fixes 118 | 119 | * Allow karma release candidate as peer dependency ([5cdb1844](https://github.com/karma-runner/grunt-karma/commit/5cdb1844)) 120 | 121 | 122 | 123 | ## 0.11.0 (2015-05-28) 124 | 125 | 126 | #### Bug Fixes 127 | 128 | * Allow for karma.conf to be used correctly Now client config is only passed to ka ([15fee6f9](https://github.com/karma-runner/grunt-karma/commit/15fee6f9), closes [#119](https://github.com/karma-runner/grunt-karma/issues/119)) 129 | * Update dependencies ([002926f4](https://github.com/karma-runner/grunt-karma/commit/002926f4)) 130 | * Flatten files array. ([7fe05940](https://github.com/karma-runner/grunt-karma/commit/7fe05940), closes [#142](https://github.com/karma-runner/grunt-karma/issues/142) 131 | 132 | 133 | 134 | ### 0.10.1 (2015-01-09) 135 | 136 | 137 | #### Bug Fixes 138 | 139 | * **task:** allow files definition in karma.conf ([6accf230](https://github.com/karma-runner/grunt-karma/commit/6accf230ce3eb945627709cc80fe3eafc82b9944), closes [#134](https://github.com/karma-runner/grunt-karma/issues/134)) 140 | 141 | 142 | 143 | ## 0.10.0 (2015-01-09) 144 | 145 | 146 | #### Features 147 | 148 | * **task:** 149 | * let Grunt do the file matching ([cb53deae](https://github.com/karma-runner/grunt-karma/commit/cb53deaef6da756be55e35c7d9fa57b84afda2ed)) 150 | * process templates in the config ([a10aaa75](https://github.com/karma-runner/grunt-karma/commit/a10aaa7548267ab035f8f4689eb54b2ead9245ef)) 151 | 152 | 153 | # 0.9.0 (2014-09-04) 154 | 155 | ## Features 156 | ### conventional-changelog 157 | 158 | * add conventional-changelog (72c67e3) 159 | 160 | ### karma-dependency 161 | 162 | * Bump Karma depdency to ~0.9.2 (23a4f25) 163 | 164 | ### 165 | 166 | * make configFile optional (cee07ab) 167 | 168 | 169 | 170 | 171 | # 0.8.3 172 | * Flatten `files` input (@cgross) 173 | 174 | # 0.8.2 175 | * Emergency fix: Don't pass anything to karma if no browsers are defined. 176 | 177 | # 0.8.1 178 | * Kill background child process on main process exit. (@trabianmatt) 179 | * Fix passing `client.args` through the commandline. 180 | * Actually override the browsers array. 181 | * Set client default args. 182 | * Merge `client.args` from all sources. 183 | 184 | # 0.8.0 185 | * Update to `karma@0.12.0` 186 | 187 | #0.3.0 188 | * changed name from gruntacular to grunt-karma 189 | 190 | #0.2.0 191 | * support config sharing via options property 192 | * basic example/test suite 193 | * slight refactor 194 | * use latest testacular 195 | 196 | #0.1.1 197 | * initial version 198 | * docs 199 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # grunt-karma 2 | 3 | [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/karma-runner/grunt-karma) 4 | [![npm version](https://img.shields.io/npm/v/grunt-karma.svg?style=flat-square)](https://www.npmjs.com/package/grunt-karma) [![npm downloads](https://img.shields.io/npm/dm/grunt-karma.svg?style=flat-square)](https://www.npmjs.com/package/grunt-karma) 5 | 6 | [![Build Status](https://img.shields.io/travis/karma-runner/grunt-karma/master.svg?style=flat-square)](https://travis-ci.org/karma-runner/grunt-karma) [![Dependency Status](https://img.shields.io/david/karma-runner/grunt-karma.svg?style=flat-square)](https://david-dm.org/karma-runner/grunt-karma) [![devDependency Status](https://img.shields.io/david/dev/karma-runner/grunt-karma.svg?style=flat-square)](https://david-dm.org/karma-runner/grunt-karma?type=dev) 7 | 8 | 9 | > Grunt plugin for [Karma](https://github.com/karma-runner/karma) 10 | 11 | This current version uses `karma@^3.0.0`. For using older versions see the 12 | old releases of grunt-karma. 13 | 14 | ## Getting Started 15 | From the same directory as your project's Gruntfile and package.json, install 16 | karma and grunt-karma with the following commands: 17 | 18 | ```bash 19 | $ npm install karma --save-dev 20 | $ npm install grunt-karma --save-dev 21 | ``` 22 | 23 | Once that's done, add this line to your project's Gruntfile: 24 | 25 | ```js 26 | grunt.loadNpmTasks('grunt-karma'); 27 | ``` 28 | 29 | ## Config 30 | Inside your `Gruntfile.js` file, add a section named `karma`, containing 31 | any number of configurations for running karma. You can either put your 32 | config in a [karma config file] or leave it all in your Gruntfile (recommended). 33 | 34 | ### Here's an example that points to the config file: 35 | 36 | ```js 37 | karma: { 38 | unit: { 39 | configFile: 'karma.conf.js' 40 | } 41 | } 42 | ``` 43 | 44 | ### Here's an example that puts the config in the Gruntfile: 45 | 46 | ```js 47 | karma: { 48 | unit: { 49 | options: { 50 | files: ['test/**/*.js'] 51 | } 52 | } 53 | } 54 | ``` 55 | 56 | You can override any of the config file's settings by putting them 57 | directly in the Gruntfile: 58 | 59 | ```js 60 | karma: { 61 | unit: { 62 | configFile: 'karma.conf.js', 63 | port: 9999, 64 | singleRun: true, 65 | browsers: ['PhantomJS'], 66 | logLevel: 'ERROR' 67 | } 68 | } 69 | ``` 70 | 71 | To change the `logLevel` in the grunt config file instead of the karma config, use one of the following strings: 72 | `OFF`, `ERROR`, `WARN`, `INFO`, `DEBUG` 73 | 74 | The `files` option can be extended "per-target" in the typical way 75 | Grunt handles [files][grunt-config-files]: 76 | 77 | ```js 78 | karma: { 79 | options: { 80 | files: ['lib/**/*.js'] 81 | }, 82 | unit: { 83 | files: [ 84 | { src: ['test/**/*.js'] } 85 | ] 86 | } 87 | } 88 | ``` 89 | 90 | When using the "Grunt way" of specifying files, you can also extend the 91 | file objects with the options [supported by karma][karma-config-files]: 92 | 93 | ```js 94 | karma: { 95 | unit: { 96 | files: [ 97 | { src: ['test/**/*.js'], served: true }, 98 | { src: ['lib/**/*.js'], served: true, included: false } 99 | ] 100 | } 101 | } 102 | ``` 103 | 104 | ### Config with Grunt Template Strings in `files` 105 | 106 | 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. 107 | 108 | Example: 109 | 110 | ```js 111 | meta: { 112 | jsFiles: ['jquery.js','angular.js'] 113 | }, 114 | karma: { 115 | options: { 116 | files: ['<%= meta.jsFiles %>','angular-mocks.js','**/*-spec.js'] 117 | } 118 | } 119 | ``` 120 | 121 | ## Sharing Configs 122 | If you have multiple targets, it may be helpful to share common 123 | configuration settings between them. Grunt-karma supports this by 124 | using the `options` property: 125 | 126 | ```js 127 | karma: { 128 | options: { 129 | configFile: 'karma.conf.js', 130 | port: 9999, 131 | browsers: ['Chrome', 'Firefox'] 132 | }, 133 | continuous: { 134 | singleRun: true, 135 | browsers: ['PhantomJS'] 136 | }, 137 | dev: { 138 | reporters: 'dots' 139 | } 140 | } 141 | ``` 142 | 143 | In this example the `continuous` and `dev` targets will both use 144 | the `configFile` and `port` specified in the `options`. But 145 | the `continuous` target will override the browser setting to use 146 | PhantomJS, and also run as a singleRun. The `dev` target will simply 147 | change the reporter to dots. 148 | 149 | ## Running tests 150 | There are three ways to run your tests with karma: 151 | 152 | ### Karma Server with Auto Runs on File Change 153 | Setting the `autoWatch` option to true will instruct karma to start 154 | a server and watch for changes to files, running tests automatically: 155 | 156 | ```js 157 | karma: { 158 | unit: { 159 | configFile: 'karma.conf.js', 160 | autoWatch: true 161 | } 162 | } 163 | ``` 164 | Now run `$ grunt karma` 165 | 166 | ### Karma Server with Grunt Watch 167 | Many Grunt projects watch several types of files using [grunt-contrib-watch]. 168 | Config karma like usual (without the autoWatch option), and add 169 | `background:true`: 170 | 171 | ```js 172 | karma: { 173 | unit: { 174 | configFile: 'karma.conf.js', 175 | background: true, 176 | singleRun: false 177 | } 178 | } 179 | ``` 180 | The `background` option will tell grunt to run karma in a child process 181 | so it doesn't block subsequent grunt tasks. 182 | 183 | The `singleRun: false` option will tell grunt to keep the karma server up 184 | after a test run. 185 | 186 | Config your `watch` task to run the karma task with the `:run` flag. For example: 187 | 188 | ```js 189 | watch: { 190 | //run unit tests with karma (server needs to be already running) 191 | karma: { 192 | files: ['app/js/**/*.js', 'test/browser/**/*.js'], 193 | tasks: ['karma:unit:run'] //NOTE the :run flag 194 | } 195 | }, 196 | ``` 197 | 198 | In your terminal window run `$ grunt karma:unit:start watch`, which starts the 199 | karma server and the watch task. Now when grunt watch detects a change to 200 | one of your watched files, it will run the tests specified in the `unit` 201 | target using the already running karma server. This is the preferred method 202 | for development. 203 | 204 | ### Single Run 205 | Keeping a browser window & karma server running during development is 206 | productive, but not a good solution for build processes. For that reason karma 207 | provides a "continuous integration" mode, which will launch the specified 208 | browser(s), run the tests, and close the browser(s). It also supports running 209 | 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: 210 | 211 | ```js 212 | karma: { 213 | unit: { 214 | configFile: 'config/karma.conf.js', 215 | }, 216 | //continuous integration mode: run tests once in PhantomJS browser. 217 | continuous: { 218 | configFile: 'config/karma.conf.js', 219 | singleRun: true, 220 | browsers: ['PhantomJS'] 221 | }, 222 | } 223 | ``` 224 | 225 | The build would then run `grunt karma:continuous` to start PhantomJS, 226 | run tests, and close PhantomJS. 227 | 228 | ## Using additional client.args 229 | You can pass arbitrary `client.args` through the commandline like this: 230 | 231 | ```bash 232 | $ grunt karma:dev watch --grep=mypattern 233 | ``` 234 | 235 | 236 | ## License 237 | MIT License 238 | 239 | [karma-config-file]: http://karma-runner.github.com/latest/config/configuration-file.html 240 | [karma-config-files]: http://karma-runner.github.io/latest/config/files.html 241 | [grunt-config-files]: http://gruntjs.com/configuring-tasks#files 242 | [grunt-contrib-watch]: https://github.com/gruntjs/grunt-contrib-watch 243 | [PhantomJS]: http://phantomjs.org/ 244 | [karma-mocha]: https://github.com/karma-runner/karma-mocha 245 | --------------------------------------------------------------------------------