karma-jasmine
Advanced tools
Comparing version 0.3.4 to 0.3.5
(function(window) { | ||
/* jshint globalstrict: true */ | ||
'use strict'; | ||
/** | ||
@@ -98,18 +101,3 @@ * Decision maker for whether a stack entry is considered relevant. | ||
var indexOf = function(collection, item) { | ||
if (collection.indexOf) { | ||
return collection.indexOf(item); | ||
} | ||
for (var i = 0, l = collection.length; i < l; i++) { | ||
if (collection[i] === item) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
}; | ||
var SuiteNode = function(name, parent) { | ||
function SuiteNode(name, parent) { | ||
this.name = name; | ||
@@ -119,3 +107,3 @@ this.parent = parent; | ||
this.addChild = function(name) { | ||
this.addChild = function (name) { | ||
var suite = new SuiteNode(name, this); | ||
@@ -125,31 +113,32 @@ this.children.push(suite); | ||
}; | ||
}; | ||
} | ||
var getAllSpecNames = function(topSuite) { | ||
var specNames = {}; | ||
function processSuite(suite, pointer) { | ||
var child; | ||
var childPointer; | ||
function processSuite(suite, pointer) { | ||
var child; | ||
var childPointer; | ||
for (var i = 0; i < suite.children.length; i++) { | ||
child = suite.children[i]; | ||
for (var i = 0; i < suite.children.length; i++) { | ||
child = suite.children[i]; | ||
if (child.children) { | ||
childPointer = pointer[child.description] = {_: []}; | ||
processSuite(child, childPointer); | ||
} else { | ||
if (!pointer._) { | ||
pointer._ = []; | ||
} | ||
pointer._.push(child.description); | ||
if (child.children) { | ||
childPointer = pointer[child.description] = {_: []}; | ||
processSuite(child, childPointer); | ||
} else { | ||
if (!pointer._) { | ||
pointer._ = []; | ||
} | ||
pointer._.push(child.description); | ||
} | ||
} | ||
} | ||
function getAllSpecNames(topSuite) { | ||
var specNames = {}; | ||
processSuite(topSuite, specNames); | ||
return specNames; | ||
}; | ||
} | ||
@@ -160,4 +149,6 @@ | ||
*/ | ||
var KarmaReporter = function(tc, jasmineEnv) { | ||
function KarmaReporter(tc, jasmineEnv) { | ||
var currentSuite = new SuiteNode(); | ||
/** | ||
@@ -167,8 +158,6 @@ * @param suite | ||
*/ | ||
var isTopLevelSuite = function (suite) { | ||
function isTopLevelSuite(suite) { | ||
return suite.description === 'Jasmine_TopLevel_Suite'; | ||
}; | ||
} | ||
var currentSuite = new SuiteNode(); | ||
/** | ||
@@ -185,3 +174,3 @@ * Jasmine 2.0 dispatches the following events: | ||
this.jasmineStarted = function(data) { | ||
this.jasmineStarted = function (data) { | ||
// TODO(vojta): Do not send spec names when polling. | ||
@@ -195,3 +184,3 @@ tc.info({ | ||
this.jasmineDone = function() { | ||
this.jasmineDone = function () { | ||
tc.complete({ | ||
@@ -203,3 +192,3 @@ coverage: window.__coverage__ | ||
this.suiteStarted = function(result) { | ||
this.suiteStarted = function (result) { | ||
if (!isTopLevelSuite(result)) { | ||
@@ -211,3 +200,3 @@ currentSuite = currentSuite.addChild(result.description); | ||
this.suiteDone = function(result) { | ||
this.suiteDone = function (result) { | ||
// In the case of xdescribe, only "suiteDone" is fired. | ||
@@ -223,3 +212,3 @@ // We need to skip that. | ||
this.specStarted = function(specResult) { | ||
this.specStarted = function (specResult) { | ||
specResult.startTime = new Date().getTime(); | ||
@@ -229,3 +218,3 @@ }; | ||
this.specDone = function(specResult) { | ||
this.specDone = function (specResult) { | ||
var skipped = specResult.status === 'disabled' || specResult.status === 'pending'; | ||
@@ -260,19 +249,89 @@ | ||
}; | ||
} | ||
/** | ||
* Extract grep option from karma config | ||
* @param {[Array|string]} clientArguments The karma client arguments | ||
* @return {string} The value of grep option by default empty string | ||
*/ | ||
var getGrepOption = function(clientArguments) { | ||
var clientArgString = clientArguments || ''; | ||
if (Object.prototype.toString.call(clientArguments) === '[object Array]') { | ||
clientArgString = clientArguments.join('='); | ||
} | ||
var match = /--grep=(.*)/.exec(clientArgString); | ||
return match ? match[1] : ''; | ||
}; | ||
/** | ||
* Extract grep option from karma config | ||
* @param {[Array|string]} clientArguments The karma client arguments | ||
* @return {string} The value of grep option by default empty string | ||
*/ | ||
var getGrepOption = function(clientArguments) { | ||
var clientArgString = clientArguments || ''; | ||
var createStartFn = function(tc, jasmineEnvPassedIn) { | ||
return function(config) { | ||
// we pass jasmineEnv during testing | ||
// in production we ask for it lazily, so that adapter can be loaded even before jasmine | ||
var jasmineEnv = jasmineEnvPassedIn || window.jasmine.getEnv(); | ||
if (Object.prototype.toString.call(clientArguments) === '[object Array]') { | ||
clientArgString = clientArguments.join('='); | ||
} | ||
jasmineEnv.addReporter(new KarmaReporter(tc, jasmineEnv)); | ||
jasmineEnv.execute(); | ||
var match = /--grep=(.*)/.exec(clientArgString); | ||
return match ? match[1] : ''; | ||
}; | ||
/** | ||
* Create jasmine spec filter | ||
* @param {Object} options Spec filter options | ||
*/ | ||
var KarmaSpecFilter = function(options) { | ||
var filterString = options && options.filterString() && options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); | ||
var filterPattern = new RegExp(filterString); | ||
this.matches = function(specName) { | ||
return filterPattern.test(specName); | ||
}; | ||
}; | ||
/** | ||
* @param {Object} config The karma config | ||
* @param {Object} jasmineEnv jasmine environment object | ||
*/ | ||
var createSpecFilter = function(config, jasmineEnv) { | ||
var specFilter = new KarmaSpecFilter({ | ||
filterString: function() { | ||
return getGrepOption(config.args); | ||
} | ||
}); | ||
jasmineEnv.specFilter = function(spec) { | ||
return specFilter.matches(spec.getFullName()); | ||
}; | ||
}; | ||
/** | ||
* Karma starter function factory. | ||
* | ||
* This function is invoked from the wrapper. | ||
* @see adapter.wrapper | ||
* | ||
* @param {Object} karma Karma runner instance. | ||
* @param {Object} [jasmineEnv] Optional Jasmine environment for testing. | ||
* @return {Function} Karma starter function. | ||
*/ | ||
function createStartFn(karma, jasmineEnv) { | ||
// This function will be assigned to `window.__karma__.start`: | ||
return function () { | ||
jasmineEnv = jasmineEnv || window.jasmine.getEnv(); | ||
jasmineEnv.addReporter(new KarmaReporter(karma, jasmineEnv)); | ||
jasmineEnv.execute(); | ||
}; | ||
} | ||
createSpecFilter(window.__karma__.config, jasmine.getEnv()); | ||
window.__karma__.start = createStartFn(window.__karma__); | ||
})(window); |
{ | ||
"name": "karma-jasmine", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"description": "A Karma plugin - adapter for Jasmine testing framework.", | ||
@@ -40,5 +40,5 @@ "main": "lib/index.js", | ||
"Maksim Ryzhikov <rv.maksim@gmail.com>", | ||
"olegskl <sklyanchuk@gmail.com>", | ||
"Cornelius Schmale <github@cschmale.de>", | ||
"Friedel Ziegelmayer <friedel.ziegelmayer@gmail.com>", | ||
"olegskl <sklyanchuk@gmail.com>", | ||
"Alesei N <github.com@bzik.net>", | ||
@@ -45,0 +45,0 @@ "Barry Fitzgerald <barfitzgerald@gmail.com>", |
@@ -63,2 +63,23 @@ # karma-jasmine [![Build Status](https://travis-ci.org/karma-runner/karma-jasmine.svg?branch=master)](https://travis-ci.org/karma-runner/karma-jasmine) | ||
If you want run only some tests matching a given pattern you can do this in the following way | ||
```bash | ||
karma start & | ||
karma run -- --grep=<pattern> | ||
``` | ||
or | ||
```js | ||
module.exports = function(config) { | ||
config.set({ | ||
... | ||
client: { | ||
args: ['--grep', '<pattern>'], | ||
... | ||
} | ||
}); | ||
}; | ||
``` | ||
---- | ||
@@ -65,0 +86,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15422
317
90