├── .gitignore ├── LICENSE ├── README.md ├── index.js ├── lib └── background.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /*.loga -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2014 Larry Davis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gulp-karma [![NPM version][npm-image]][npm-url] 2 | 3 | > Karma plugin for gulp 3 4 | 5 | ## Deprecated 6 | 7 | `gulp-karma` has been deprectated. Use Karma directly instead: https://github.com/karma-runner/gulp-karma 8 | 9 | [npm-url]: https://npmjs.org/package/gulp-karma 10 | [npm-image]: https://badge.fury.io/js/gulp-karma.png 11 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*jshint node:true */ 2 | 3 | 'use strict'; 4 | 5 | var gutil = require('gulp-util'); 6 | var c = gutil.colors; 7 | var es = require('event-stream'); 8 | var extend = require('xtend'); 9 | var path = require('path'); 10 | var spawn = require('child_process').spawn; 11 | 12 | var server = require('karma').server; 13 | 14 | var karmaPlugin = function(options) { 15 | var child; 16 | var stream; 17 | var files = []; 18 | 19 | options = extend({ 20 | action: 'run' 21 | }, options); 22 | 23 | var action = options.action; 24 | 25 | // Remove option in case Karma uses it in the future 26 | delete options.action; 27 | 28 | if (action === 'watch') { 29 | // Never set singleRun in background mode 30 | options.singleRun = false; 31 | 32 | // Enable watching 33 | options.autoWatch = true; 34 | } 35 | else if (action === 'run') { 36 | // Tell Karma to run once and exit 37 | options.singleRun = true; 38 | 39 | // Disable watching 40 | options.autoWatch = false; 41 | } 42 | 43 | if (options.configFile) { 44 | options.configFile = path.resolve(options.configFile); 45 | } 46 | 47 | function done(code) { 48 | // Stop the server if it's running 49 | if (child) { 50 | child.kill(); 51 | } 52 | 53 | // End the stream if it exists 54 | if (stream) { 55 | if (code) { 56 | stream.emit('error', new gutil.PluginError('gulp-karma', 'karma exited with code ' + code)); 57 | } 58 | else { 59 | stream.emit('end'); 60 | } 61 | } 62 | } 63 | 64 | function startKarmaServer() { 65 | gutil.log('Starting Karma server...'); 66 | 67 | // Start the server 68 | child = spawn( 69 | 'node', 70 | [ 71 | path.join(__dirname, 'lib', 'background.js'), 72 | JSON.stringify(options) 73 | ], 74 | { 75 | stdio: 'inherit' 76 | } 77 | ); 78 | 79 | // Cleanup when the child process exits 80 | child.on('exit', function(code) { 81 | // gutil.log('Karma child process ended'); 82 | done(code); 83 | }); 84 | } 85 | 86 | function queueFile(file) { 87 | if (file) { 88 | // gutil.log('Queueing file '+file.path); 89 | files.push(file.path); 90 | } 91 | else { 92 | stream.emit('error', new Error('Got undefined file')); 93 | } 94 | } 95 | 96 | function endStream() { 97 | // Override files if they were piped 98 | // This doesn't work with the runner, but works fine with singleRun and autoWatch 99 | if (files.length) { 100 | options.files = files; 101 | } 102 | 103 | // Start the server 104 | // If options.singleRun: Server starts, tests run, task completes 105 | // If options.background: Server starts, tests run, files watched 106 | startKarmaServer(); 107 | } 108 | 109 | stream = es.through(queueFile, endStream); 110 | 111 | return stream; 112 | }; 113 | 114 | module.exports = karmaPlugin; 115 | -------------------------------------------------------------------------------- /lib/background.js: -------------------------------------------------------------------------------- 1 | var server = require('karma').server; 2 | var data = JSON.parse(process.argv[2]); 3 | server.start(data); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-karma", 3 | "version": "0.0.5", 4 | "description": "Karma plugin for gulp", 5 | "main": "index.js", 6 | "dependencies": { 7 | "optimist": "~0.6.0", 8 | "gulp-util": "~2.2.14", 9 | "xtend": "~2.1.1", 10 | "event-stream": "~3.0.20" 11 | }, 12 | "peerDependencies": { 13 | "karma": ">=0.10 <=0.13" 14 | }, 15 | "devDependencies": { 16 | "should": "~2.1.1", 17 | "mocha": "~1.15.1" 18 | }, 19 | "scripts": { 20 | "test": "./node_modules/.bin/mocha" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "git://github.com/lazd/gulp-karma.git" 25 | }, 26 | "keywords": [ 27 | "gulpplugin", 28 | "karma" 29 | ], 30 | "author": "Larry Davis ", 31 | "license": "MIT", 32 | "bugs": { 33 | "url": "https://github.com/lazd/gulp-karma/issues" 34 | }, 35 | "engines": { 36 | "node": ">=0.6" 37 | } 38 | } 39 | --------------------------------------------------------------------------------