mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-17 19:11:08 +00:00
chore(jstd adapter): switch to our version with backported fixes
sha of the version: da92db714142b49f9cf61db664e782bb0ccad80b
This commit is contained in:
parent
ee6af9a978
commit
e801faba2e
2 changed files with 186 additions and 176 deletions
|
|
@ -1,189 +1,198 @@
|
||||||
/**
|
/**
|
||||||
* @fileoverview Jasmine JsTestDriver Adapter.
|
* @fileoverview Jasmine JsTestDriver Adapter.
|
||||||
* @author misko@hevery.com (Misko Hevery)
|
* @author misko@hevery.com (Misko Hevery)
|
||||||
* @author olmo.maldonado@gmail.com (Olmo Maldonado)
|
|
||||||
*/
|
*/
|
||||||
(function(){
|
(function(window) {
|
||||||
|
var rootDescribes = new Describes(window);
|
||||||
|
var describePath = [];
|
||||||
|
rootDescribes.collectMode();
|
||||||
|
|
||||||
|
var JASMINE_TYPE = 'jasmine test case';
|
||||||
|
TestCase('Jasmine Adapter Tests', null, JASMINE_TYPE);
|
||||||
|
|
||||||
|
var jasminePlugin = {
|
||||||
|
name:'jasmine',
|
||||||
|
|
||||||
|
getTestRunsConfigurationFor: function(testCaseInfos, expressions, testRunsConfiguration) {
|
||||||
|
for (var i = 0; i < testCaseInfos.length; i++) {
|
||||||
|
if (testCaseInfos[i].getType() == JASMINE_TYPE) {
|
||||||
|
testRunsConfiguration.push(new jstestdriver.TestRunConfiguration(testCaseInfos[i], []));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
runTestConfiguration: function(testRunConfiguration, onTestDone, onTestRunConfigurationComplete){
|
||||||
|
if (testRunConfiguration.getTestCaseInfo().getType() != JASMINE_TYPE) return false;
|
||||||
|
|
||||||
|
var jasmineEnv = jasmine.currentEnv_ = new jasmine.Env();
|
||||||
|
rootDescribes.playback();
|
||||||
|
var specLog = jstestdriver.console.log_ = [];
|
||||||
|
var start;
|
||||||
|
jasmineEnv.specFilter = function(spec) {
|
||||||
|
return rootDescribes.isExclusive(spec);
|
||||||
|
};
|
||||||
|
jasmineEnv.reporter = {
|
||||||
|
log: function(str){
|
||||||
|
specLog.push(str);
|
||||||
|
},
|
||||||
|
|
||||||
|
reportRunnerStarting: function(runner) { },
|
||||||
|
|
||||||
|
reportSpecStarting: function(spec) {
|
||||||
|
specLog = jstestdriver.console.log_ = [];
|
||||||
|
start = new Date().getTime();
|
||||||
|
},
|
||||||
|
|
||||||
|
reportSpecResults: function(spec) {
|
||||||
|
var suite = spec.suite;
|
||||||
|
var results = spec.results();
|
||||||
|
if (results.skipped) return;
|
||||||
|
var end = new Date().getTime();
|
||||||
|
var messages = [];
|
||||||
|
var resultItems = results.getItems();
|
||||||
|
var state = 'passed';
|
||||||
|
for ( var i = 0; i < resultItems.length; i++) {
|
||||||
|
if (!resultItems[i].passed()) {
|
||||||
|
state = resultItems[i].message.match(/AssertionError:/) ? 'error' : 'failed';
|
||||||
|
messages.push({
|
||||||
|
message: resultItems[i].toString(),
|
||||||
|
name: resultItems[i].trace.name,
|
||||||
|
stack: formatStack(resultItems[i].trace.stack)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onTestDone(
|
||||||
|
new jstestdriver.TestResult(
|
||||||
|
suite.getFullName(),
|
||||||
|
spec.description,
|
||||||
|
state,
|
||||||
|
jstestdriver.angular.toJson(messages),
|
||||||
|
specLog.join('\n'),
|
||||||
|
end - start));
|
||||||
|
},
|
||||||
|
|
||||||
|
reportSuiteResults: function(suite) {},
|
||||||
|
|
||||||
|
reportRunnerResults: function(runner) {
|
||||||
|
onTestRunConfigurationComplete();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
jasmineEnv.execute();
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
onTestsFinish: function(){
|
||||||
|
jasmine.currentEnv_ = null;
|
||||||
|
rootDescribes.collectMode();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
jstestdriver.pluginRegistrar.register(jasminePlugin);
|
||||||
|
|
||||||
|
function formatStack(stack) {
|
||||||
|
var lines = (stack||'').split(/\r?\n/);
|
||||||
|
var frames = [];
|
||||||
|
for (i = 0; i < lines.length; i++) {
|
||||||
|
if (!lines[i].match(/\/jasmine[\.-]/)) {
|
||||||
|
frames.push(lines[i].replace(/https?:\/\/\w+(:\d+)?\/test\//, '').replace(/^\s*/, ' '));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return frames.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
function noop(){}
|
||||||
|
function Describes(window){
|
||||||
|
var describes = {};
|
||||||
|
var beforeEachs = {};
|
||||||
|
var afterEachs = {};
|
||||||
|
// Here we store:
|
||||||
|
// 0: everyone runs
|
||||||
|
// 1: run everything under ddescribe
|
||||||
|
// 2: run only iits (ignore ddescribe)
|
||||||
|
var exclusive = 0;
|
||||||
|
var collectMode = true;
|
||||||
|
intercept('describe', describes);
|
||||||
|
intercept('xdescribe', describes);
|
||||||
|
intercept('beforeEach', beforeEachs);
|
||||||
|
intercept('afterEach', afterEachs);
|
||||||
|
|
||||||
|
function intercept(functionName, collection){
|
||||||
|
window[functionName] = function(desc, fn){
|
||||||
|
if (collectMode) {
|
||||||
|
collection[desc] = function(){
|
||||||
|
jasmine.getEnv()[functionName](desc, fn);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
jasmine.getEnv()[functionName](desc, fn);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
window.ddescribe = function(name, fn){
|
||||||
|
if (exclusive < 1) {
|
||||||
|
exclusive = 1; // run ddescribe only
|
||||||
|
}
|
||||||
|
window.describe(name, function(){
|
||||||
|
var oldIt = window.it;
|
||||||
|
window.it = function(name, fn){
|
||||||
|
fn.exclusive = 1; // run anything under ddescribe
|
||||||
|
jasmine.getEnv().it(name, fn);
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
fn.call(this);
|
||||||
|
} finally {
|
||||||
|
window.it = oldIt;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
window.iit = function(name, fn){
|
||||||
|
exclusive = fn.exclusive = 2; // run only iits
|
||||||
|
jasmine.getEnv().it(name, fn);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var Env = function(onTestDone, onComplete){
|
this.collectMode = function() {
|
||||||
jasmine.Env.call(this);
|
collectMode = true;
|
||||||
|
exclusive = 0; // run everything
|
||||||
|
};
|
||||||
|
this.playback = function(){
|
||||||
|
collectMode = false;
|
||||||
|
playback(beforeEachs);
|
||||||
|
playback(afterEachs);
|
||||||
|
playback(describes);
|
||||||
|
|
||||||
this.specFilter = function(spec){
|
function playback(set) {
|
||||||
if (!this.exclusive) return true;
|
for ( var name in set) {
|
||||||
var blocks = spec.queue.blocks, l = blocks.length;
|
set[name]();
|
||||||
for (var i = 0; i < l; i++) if (blocks[i].func.exclusive >= this.exclusive) return true;
|
}
|
||||||
return false;
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.reporter = new Reporter(onTestDone, onComplete);
|
this.isExclusive = function(spec) {
|
||||||
};
|
if (exclusive) {
|
||||||
jasmine.util.inherit(Env, jasmine.Env);
|
var blocks = spec.queue.blocks;
|
||||||
|
for ( var i = 0; i < blocks.length; i++) {
|
||||||
|
if (blocks[i].func.exclusive >= exclusive) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Here we store:
|
})(window);
|
||||||
// 0: everyone runs
|
|
||||||
// 1: run everything under ddescribe
|
|
||||||
// 2: run only iits (ignore ddescribe)
|
|
||||||
Env.prototype.exclusive = 0;
|
|
||||||
|
|
||||||
|
|
||||||
Env.prototype.execute = function(){
|
|
||||||
collectMode = false;
|
|
||||||
playback();
|
|
||||||
jasmine.Env.prototype.execute.call(this);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var Reporter = function(onTestDone, onComplete){
|
|
||||||
this.onTestDone = onTestDone;
|
|
||||||
this.onComplete = onComplete;
|
|
||||||
this.reset();
|
|
||||||
};
|
|
||||||
jasmine.util.inherit(Reporter, jasmine.Reporter);
|
|
||||||
|
|
||||||
|
|
||||||
Reporter.formatStack = function(stack) {
|
|
||||||
var line, lines = (stack || '').split(/\r?\n/), l = lines.length, frames = [];
|
|
||||||
for (var i = 0; i < l; i++){
|
|
||||||
line = lines[i];
|
|
||||||
if (line.match(/\/jasmine[\.-]/)) continue;
|
|
||||||
frames.push(line.replace(/https?:\/\/\w+(:\d+)?\/test\//, '').replace(/^\s*/, ' '));
|
|
||||||
}
|
|
||||||
return frames.join('\n');
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Reporter.prototype.reset = function(){
|
|
||||||
this.specLog = jstestdriver.console.log_ = [];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Reporter.prototype.log = function(str){
|
|
||||||
this.specLog.push(str);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Reporter.prototype.reportSpecStarting = function(){
|
|
||||||
this.reset();
|
|
||||||
this.start = +new Date();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Reporter.prototype.reportSpecResults = function(spec){
|
|
||||||
var elapsed = +new Date() - this.start, results = spec.results();
|
|
||||||
|
|
||||||
if (results.skipped) return;
|
|
||||||
|
|
||||||
var item, state = 'passed', items = results.getItems(), l = items.length, messages = [];
|
|
||||||
for (var i = 0; i < l; i++){
|
|
||||||
item = items[i];
|
|
||||||
if (item.passed()) continue;
|
|
||||||
state = (item.message.indexOf('AssertionError:') != -1) ? 'error' : 'failed';
|
|
||||||
messages.push({
|
|
||||||
message: item + '',
|
|
||||||
name: item.trace.name,
|
|
||||||
stack: Reporter.formatStack(item.trace.stack)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.onTestDone(new jstestdriver.TestResult(
|
|
||||||
spec.suite.getFullName(),
|
|
||||||
spec.description,
|
|
||||||
state,
|
|
||||||
jstestdriver.angular.toJson(messages),
|
|
||||||
this.specLog.join('\n'),
|
|
||||||
elapsed
|
|
||||||
));
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Reporter.prototype.reportRunnerResults = function(){
|
|
||||||
this.onComplete();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var collectMode = true, intercepted = {};
|
|
||||||
|
|
||||||
describe = intercept('describe');
|
|
||||||
beforeEach = intercept('beforeEach');
|
|
||||||
afterEach = intercept('afterEach');
|
|
||||||
|
|
||||||
var JASMINE_TYPE = 'jasmine test case';
|
|
||||||
TestCase('Jasmine Adapter Tests', null, JASMINE_TYPE);
|
|
||||||
|
|
||||||
jstestdriver.pluginRegistrar.register({
|
|
||||||
|
|
||||||
name: 'jasmine',
|
|
||||||
|
|
||||||
getTestRunsConfigurationFor: function(testCaseInfos, expressions, testRunsConfiguration) {
|
|
||||||
for (var i = 0; i < testCaseInfos.length; i++) {
|
|
||||||
if (testCaseInfos[i].getType() == JASMINE_TYPE) {
|
|
||||||
testRunsConfiguration.push(new jstestdriver.TestRunConfiguration(testCaseInfos[i], []));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false; // allow other TestCases to be collected.
|
|
||||||
},
|
|
||||||
|
|
||||||
runTestConfiguration: function(config, onTestDone, onComplete){
|
|
||||||
if (config.getTestCaseInfo().getType() != JASMINE_TYPE) return false;
|
|
||||||
(jasmine.currentEnv_ = new Env(onTestDone, onComplete)).execute();
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
|
|
||||||
onTestsFinish: function(){
|
|
||||||
jasmine.currentEnv_ = null;
|
|
||||||
collectMode = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
function intercept(method){
|
|
||||||
var bucket = intercepted[method] = [], method = window[method];
|
|
||||||
return function(desc, fn){
|
|
||||||
if (collectMode) bucket.push(function(){ method(desc, fn); });
|
|
||||||
else method(desc, fn);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function playback(){
|
|
||||||
for (var method in intercepted){
|
|
||||||
var bucket = intercepted[method];
|
|
||||||
for (var i = 0, l = bucket.length; i < l; i++) bucket[i]();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
})();
|
|
||||||
|
|
||||||
var ddescribe = function(name, fn){
|
|
||||||
var env = jasmine.getEnv();
|
|
||||||
if (!env.exclusive) env.exclusive = 1; // run ddescribe only
|
|
||||||
describe(name, function(){
|
|
||||||
var oldIt = it;
|
|
||||||
it = function(name, fn){
|
|
||||||
fn.exclusive = 1; // run anything under ddescribe
|
|
||||||
env.it(name, fn);
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
fn.call(this);
|
|
||||||
} finally {
|
|
||||||
it = oldIt;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
var iit = function(name, fn){
|
|
||||||
var env = jasmine.getEnv();
|
|
||||||
env.exclusive = fn.exclusive = 2; // run only iits
|
|
||||||
env.it(name, fn);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Patch Jasmine for proper stack traces
|
// Patch Jasmine for proper stack traces
|
||||||
jasmine.Spec.prototype.fail = function (e) {
|
jasmine.Spec.prototype.fail = function (e) {
|
||||||
var result = new jasmine.ExpectationResult({
|
var expectationResult = new jasmine.ExpectationResult({
|
||||||
passed: false,
|
passed: false,
|
||||||
message: e ? jasmine.util.formatException(e) : 'Exception'
|
message: e ? jasmine.util.formatException(e) : 'Exception'
|
||||||
});
|
});
|
||||||
if(e) result.trace = e;
|
// PATCH
|
||||||
this.results_.addResult(result);
|
if (e) {
|
||||||
|
expectationResult.trace = e;
|
||||||
|
}
|
||||||
|
this.results_.addResult(expectationResult);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
1
lib/jasmine-jstd-adapter/version.txt
Normal file
1
lib/jasmine-jstd-adapter/version.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
da92db714142b49f9cf61db664e782bb0ccad80b
|
||||||
Loading…
Reference in a new issue