Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Complete rewrite of the adapter

 - now jasmine runs the tests, and jstd is just a reporting pipeline
 - added iit and ddescribe for exclusive runs.
--
Removed separated tests and merged with tests.js. Also removed additional .conf and test*.sh files. Should be simple to run our own tests. One file to rule them all :).
  • Loading branch information...
commit 35ab4f84fedc3f429da1230497909f6f48d3a17e 1 parent 9113b5e
@mhevery mhevery authored committed
Showing with 171 additions and 83 deletions.
  1. +45 −0 src-test/tests.js
  2. +125 −82 src/JasmineAdapter.js
  3. +1 −1  test.sh
View
45 src-test/tests.js
@@ -88,4 +88,49 @@ describe('runs', function(){
});
});
+
+var specs = [];
+
+describe('root describe', function() {
+ it('nested it', function() {
+ specs.push('nested it');
+ });
+});
+
+
+describe('root describe with iit', function() {
+ it('it as iit sibling', function() {
+ specs.push('it as iit sibling');
+ });
+
+ iit('nested iit', function() {
+ specs.push('nested iit');
+ });
+});
+
+
+describe('describe that follows iit with a nested it', function() {
+ it('nested it after iit', function() {
+ specs.push('nested it after iit');
+ });
+});
+
+
+describe('describe with iit followed by it', function() {
+ iit('iit that preceeds an it', function() {
+ specs.push('iit that preceeds an it');
+ });
+
+ it('it that follows an iit', function() {
+ specs.push('it that follows an iit');
+ });
+});
+
+
+describe('test summary', function() {
+ iit('should have executed all iit tests and nothing else', function() {
+ expect(specs).toEqual(['nested iit', 'iit that preceeds an it']);
+ });
+});
+
})();
View
207 src/JasmineAdapter.js
@@ -1,93 +1,136 @@
/**
* @fileoverview Jasmine JsTestDriver Adapter.
- * @author ibolmo@gmail.com (Olmo Maldonado)
* @author misko@hevery.com (Misko Hevery)
*/
-(function(describe, it, beforeEach, afterEach, addResult){
+(function(window) {
+ var testNameFilter;
+ var describePath = [];
+ var exclusive = {
+ count: 0
+ };
+ function exclusiveRemove(name) {
+ var name = describePath.join(' ') + ':' + (name||'');
+ if (exclusive[name]) {
+ exclusive.count--;
+ delete exclusive[name];
+ }
+ }
+ function exclusiveAdd(name) {
+ var name = describePath.join(' ') + ':' + (name||'');
+ if (!exclusive[name]) {
+ exclusive.count++;
+ exclusive[name] = true;
+ }
+ }
+ window.it = function(name, fn){
+ exclusiveRemove(name);
+ jasmine.getEnv().it(name, fn);
+ };
+ window.iit = function(name, fn){
+ exclusiveAdd(name);
+ jasmine.getEnv().it(name, fn);
+ };
+ window.describe = function(name, fn){
+ try {
+ describePath.push(name);
+ exclusiveRemove();
+ jasmine.getEnv().describe(name, fn);
+ } finally {
+ describePath.pop(name);
+ }
+ };
+ window.ddescribe = function(name, fn){
+ try {
+ describePath.push(name);
+ exclusiveAdd();
+ jasmine.getEnv().describe(name, fn);
+ } finally {
+ describePath.pop(name);
+ }
+ };
+ var jasminePlugin = {
+ name:'jasmine',
+ getTestRunsConfigurationFor:function(testCaseInfos, filterExpressions, testRunsConfiguration) {
+ testNameFilter = function(name){
+ return !filterExpressions ||
+ filterExpressions == 'all' ||
+ filterExpressions == '*' ||
+ name.indexOf(filterExpressions) > -1;
+ };
+ var describe = new jstestdriver.TestCaseInfo('jasmine runner', function(){});
+ testRunsConfiguration.push(new jstestdriver.TestRunConfiguration(describe, []));
+ },
+ runTestConfiguration: function(testRunConfiguration, onTestDone, onTestRunConfigurationComplete){
+ var jasmineEnv = jasmine.getEnv();
+ var specLog = jstestdriver.console.log_ = [];
+ var start;
+ jasmineEnv.specFilter = function(spec) {
+ var name = spec.suite.getFullName() + ':';
+ var fullName = name + spec.description;
+ return testNameFilter(fullName) &&
+ (!exclusive.count || exclusive[name] || exclusive[fullName]);
+ };
+ jasmineEnv.reporter = {
+ log: function(str){
+ specLog.push(str);
+ },
-var frame = function(parent, name){
- var caseName = '';
- if (parent && parent.caseName) caseName = parent.caseName + ' ';
- if (name) caseName += name;
+ reportRunnerStarting: function(runner) { },
- var before = [],
- after = [];
+ reportSpecStarting: function(spec) {
+ specLog = jstestdriver.console.log_ = [];
+ start = new Date().getTime();
+ },
- return {
- name: name,
- caseName: caseName,
- parent: parent,
- testCase: TestCase(caseName),
- before: before,
- after: after,
- runBefore: function(){
- if (parent) parent.runBefore.apply(this);
- for (var i = 0, l = before.length; i < l; i++) before[i].apply(this);
- },
- runAfter: function(){
- for (var i = 0, l = after.length; i < l; i++) after[i].apply(this);
- if (parent) parent.runAfter.apply(this);
- }
- };
-};
-
-var currentFrame = frame(null, null);
-
-jasmine.Env.prototype.describe = function(description, context){
- currentFrame = frame(currentFrame, description);
- var result = describe.call(this, description, context);
- currentFrame = currentFrame.parent;
- return result;
-};
-
-jasmine.Env.prototype.it = function(description, closure){
- var result = it.call(this, description, closure),
- currentSpec = this.currentSpec,
- frame = this.jstdFrame = currentFrame,
- name = 'test that it ' + description;
+ 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(resultItems[i].toString());
+ messages.push(resultItems[i].trace.stack);
+ }
+ }
+ onTestDone(
+ new jstestdriver.TestResult(
+ suite.getFullName(),
+ spec.description,
+ state,
+ messages.join('\n'),
+ specLog.join('\n'),
+ end - start));
+ },
- if (this.jstdFrame.testCase.prototype[name])
- throw "Spec with name '" + description + "' already exists.";
-
- this.jstdFrame.testCase.prototype[name] = function(){
- jasmine.getEnv().currentSpec = currentSpec;
- frame.runBefore.apply(currentSpec);
- try {
- currentSpec.queue.start();
- } finally {
- frame.runAfter.apply(currentSpec);
- }
- };
- return result;
-};
-
-jasmine.Env.prototype.beforeEach = function(closure) {
- beforeEach.call(this, closure);
- currentFrame.before.push(closure);
-};
+ reportSuiteResults: function(suite) {},
+
+ reportRunnerResults: function(runner) {
+ onTestRunConfigurationComplete();
+ }
+ };
+ jasmineEnv.execute();
+ return true;
+ },
+ onTestsFinish: function(){}
+ };
+ jstestdriver.pluginRegistrar.register(jasminePlugin);
+})(window);
-jasmine.Env.prototype.afterEach = function(closure) {
- afterEach.call(this, closure);
- currentFrame.after.push(closure);
+// Patch Jasmine for proper stack traces
+jasmine.Spec.prototype.fail = function (e) {
+ var expectationResult = new jasmine.ExpectationResult({
+ passed: false,
+ message: e ? jasmine.util.formatException(e) : 'Exception'
+ });
+ // PATCH
+ if (e) {
+ expectationResult.trace = e;
+ }
+ this.results_.addResult(expectationResult);
};
-
-jasmine.NestedResults.prototype.addResult = function(result) {
- addResult.call(this, result);
- if (result.type != 'MessageResult' && !result.passed()) fail(result.message);
-};
-
-// @reesd - Disable the catch on exceptions when using JSTD, we want them to make it up to JSTD
-jasmine.Block.prototype.execute = function(onComplete) {
- try {
- this.func.apply(this.spec);
- } finally {
- onComplete();
- }
-};
-
-// Reset environment with overriden methods.
-jasmine.currentEnv_ = null;
-jasmine.getEnv();
-
-})(jasmine.Env.prototype.describe, jasmine.Env.prototype.it, jasmine.Env.prototype.beforeEach, jasmine.Env.prototype.afterEach, jasmine.NestedResults.prototype.addResult);
View
2  test.sh
@@ -19,4 +19,4 @@ else
echo "Running '$TESTS'"
fi
-java -jar $JSTD --reset --tests "$TESTS"
+java -jar $JSTD --reset --tests "$TESTS"
Please sign in to comment.
Something went wrong with that request. Please try again.