Skip to content

Commit

Permalink
now able to execute a simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
podefr committed Mar 24, 2012
1 parent b94f9e6 commit ffe2ae8
Show file tree
Hide file tree
Showing 13 changed files with 3,113 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
# Eclipse IDE files
.settings/
.project
*/.DS_Store
19 changes: 19 additions & 0 deletions jsTestDriver.conf
@@ -0,0 +1,19 @@
server: http://localhost:4224

load:
- tools/Jasmine/jasmine.js
- tools/Jasmine/jasmineAdapter.js
- lib/require.js
- src/*.js

test:
- specs/*.js

plugin:
- name: "coverage"
jar: "tools/JsTestDriver/coverage-1.3.4.b.jar"
module: "com.google.jstestdriver.coverage.CoverageModule"


timeout: 90

33 changes: 33 additions & 0 deletions lib/require.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions specs/HelloWorld-spec.js
@@ -0,0 +1,9 @@
require(["HelloWorld"], function (HelloWorld) {

describe("HelloWorldTest", function () {
it("should return hello world!", function () {
expect(HelloWorld()).toEqual("hello world!");
});
});

});
7 changes: 7 additions & 0 deletions src/HelloWorld.js
@@ -0,0 +1,7 @@
define("HelloWorld", function () {

return function () {
return "hello world!";
};

});
189 changes: 189 additions & 0 deletions tools/Jasmine/JasmineAdapter.js
@@ -0,0 +1,189 @@
/**
* @fileoverview Jasmine JsTestDriver Adapter.
* @author misko@hevery.com (Misko Hevery)
* @author olmo.maldonado@gmail.com (Olmo Maldonado)
*/
(function(){


var Env = function(onTestDone, onComplete){
jasmine.Env.call(this);

this.specFilter = function(spec){
if (!this.exclusive) return true;
var blocks = spec.queue.blocks, l = blocks.length;
for (var i = 0; i < l; i++) if (blocks[i].func.exclusive >= this.exclusive) return true;
return false;
};

this.reporter = new Reporter(onTestDone, onComplete);
};
jasmine.util.inherit(Env, jasmine.Env);

// Here we store:
// 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
jasmine.Spec.prototype.fail = function (e) {
var result = new jasmine.ExpectationResult({
passed: false,
message: e ? jasmine.util.formatException(e) : 'Exception'
});
if(e) result.trace = e;
this.results_.addResult(result);
};
20 changes: 20 additions & 0 deletions tools/Jasmine/MIT.LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2008-2011 Pivotal Labs

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:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

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.

0 comments on commit ffe2ae8

Please sign in to comment.