From 595b4ea097bcb512173b6d4a12924ea1a3d70ecd Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 18 Jan 2010 10:47:03 -0800 Subject: checkpoint for integration with angular --- lib/jasmine-jstd-adapter/JasmineAdapter.js | 96 ++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 lib/jasmine-jstd-adapter/JasmineAdapter.js (limited to 'lib/jasmine-jstd-adapter') diff --git a/lib/jasmine-jstd-adapter/JasmineAdapter.js b/lib/jasmine-jstd-adapter/JasmineAdapter.js new file mode 100644 index 00000000..83a1deed --- /dev/null +++ b/lib/jasmine-jstd-adapter/JasmineAdapter.js @@ -0,0 +1,96 @@ +/** + * @fileoverview Jasmine JsTestDriver Adapter. + * @author ibolmo@gmail.com (Olmo Maldonado) + */ + +(function() { + +// Suite/TestCase before and after function stacks. +var before = []; +var after = []; + +jasmine.Env.prototype.describe = (function(describe){ + + // TODO(ibolmo): Support nested describes. + return function(description, specDefinitions){ + this.currentTestCase = TestCase(description); + return describe.call(this, description, specDefinitions); + }; + +})(jasmine.Env.prototype.describe); + + +jasmine.Env.prototype.it = (function(it){ + + return function(desc, func){ + var spec = it.call(this, desc, func); + this.currentTestCase.prototype['test that it ' + desc] = func; + return spec; + }; + +})(jasmine.Env.prototype.it); + + +jasmine.Env.prototype.beforeEach = (function(beforeEach){ + + // TODO(ibolmo): Support beforeEach TestCase. + return function(beforeEachFunction) { + beforeEach.call(this, beforeEachFunction); + if (this.currentTestCase) { + this.currentTestCase.prototype.setUp = beforeEachFunction; + } else { + before.push(beforeEachFunction); + } + }; + +})(jasmine.Env.prototype.beforeEach); + + +jasmine.Env.prototype.afterEach = (function(afterEach){ + + // TODO(ibolmo): Support afterEach TestCase. + return function(afterEachFunction) { + afterEach.call(this, afterEachFunction); + if (this.currentTestCase) { + this.currentTestCase.prototype.tearDown = afterEachFunction; + } else { + after.push(afterEachFunction); + } + }; + +})(jasmine.Env.prototype.afterEach); + + +jasmine.NestedResults.prototype.addResult = (function(addResult){ + + return function(result) { + addResult.call(this, result); + if (result.type != 'MessageResult' && !result.passed()) fail(result.message); + }; + +})(jasmine.NestedResults.prototype.addResult); + + +jstestdriver.plugins.TestRunnerPlugin.prototype.runTestConfiguration = (function(runTestConfiguration){ + + return function(testRunConfiguration, onTestDone, onTestRunConfigurationComplete){ + for (var i = 0, l = before.length; i < l; i++) before[i](); + onTestRunConfigurationComplete = (function(configurationComplete){ + + return function() { + for (var i = 0, l = after.length; i < l; i++) after[i](); + configurationComplete(); + }; + + })(onTestRunConfigurationComplete); + runTestConfiguration.call(this, testRunConfiguration, onTestDone, onTestRunConfigurationComplete); + }; + +})(jstestdriver.plugins.TestRunnerPlugin.prototype.runTestConfiguration); + + +// Reset environment with overriden methods. +jasmine.currentEnv_ = null; +jasmine.getEnv(); + +})(); -- cgit v1.2.3 From 843bd355d25ebf2369aec79f98cb6704d38497e9 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 9 Apr 2010 16:20:15 -0700 Subject: various bug fixes --- lib/jasmine-jstd-adapter/JasmineAdapter.js | 181 +++++++++++++++-------------- 1 file changed, 94 insertions(+), 87 deletions(-) (limited to 'lib/jasmine-jstd-adapter') diff --git a/lib/jasmine-jstd-adapter/JasmineAdapter.js b/lib/jasmine-jstd-adapter/JasmineAdapter.js index 83a1deed..ba54251a 100644 --- a/lib/jasmine-jstd-adapter/JasmineAdapter.js +++ b/lib/jasmine-jstd-adapter/JasmineAdapter.js @@ -1,96 +1,103 @@ /** * @fileoverview Jasmine JsTestDriver Adapter. * @author ibolmo@gmail.com (Olmo Maldonado) + * @author misko@hevery.com (Misko Hevery) */ (function() { -// Suite/TestCase before and after function stacks. -var before = []; -var after = []; - -jasmine.Env.prototype.describe = (function(describe){ - - // TODO(ibolmo): Support nested describes. - return function(description, specDefinitions){ - this.currentTestCase = TestCase(description); - return describe.call(this, description, specDefinitions); - }; - -})(jasmine.Env.prototype.describe); - - -jasmine.Env.prototype.it = (function(it){ - - return function(desc, func){ - var spec = it.call(this, desc, func); - this.currentTestCase.prototype['test that it ' + desc] = func; - return spec; - }; - -})(jasmine.Env.prototype.it); - - -jasmine.Env.prototype.beforeEach = (function(beforeEach){ - - // TODO(ibolmo): Support beforeEach TestCase. - return function(beforeEachFunction) { - beforeEach.call(this, beforeEachFunction); - if (this.currentTestCase) { - this.currentTestCase.prototype.setUp = beforeEachFunction; - } else { - before.push(beforeEachFunction); - } - }; - -})(jasmine.Env.prototype.beforeEach); - - -jasmine.Env.prototype.afterEach = (function(afterEach){ - - // TODO(ibolmo): Support afterEach TestCase. - return function(afterEachFunction) { - afterEach.call(this, afterEachFunction); - if (this.currentTestCase) { - this.currentTestCase.prototype.tearDown = afterEachFunction; - } else { - after.push(afterEachFunction); - } - }; - -})(jasmine.Env.prototype.afterEach); - - -jasmine.NestedResults.prototype.addResult = (function(addResult){ - - return function(result) { - addResult.call(this, result); - if (result.type != 'MessageResult' && !result.passed()) fail(result.message); - }; - -})(jasmine.NestedResults.prototype.addResult); - - -jstestdriver.plugins.TestRunnerPlugin.prototype.runTestConfiguration = (function(runTestConfiguration){ - - return function(testRunConfiguration, onTestDone, onTestRunConfigurationComplete){ - for (var i = 0, l = before.length; i < l; i++) before[i](); - onTestRunConfigurationComplete = (function(configurationComplete){ - - return function() { - for (var i = 0, l = after.length; i < l; i++) after[i](); - configurationComplete(); - }; - - })(onTestRunConfigurationComplete); - runTestConfiguration.call(this, testRunConfiguration, onTestDone, onTestRunConfigurationComplete); - }; - -})(jstestdriver.plugins.TestRunnerPlugin.prototype.runTestConfiguration); - - -// Reset environment with overriden methods. -jasmine.currentEnv_ = null; -jasmine.getEnv(); + function bind(_this, _function){ + return function(){ + return _function.call(_this); + } + } + + var currentFrame = frame(null, null); + + function frame(parent, name){ + var caseName = (parent && parent.caseName ? parent.caseName + " " : '') + (name ? name : ''); + var frame = { + name: name, + caseName: caseName, + parent: parent, + testCase: TestCase(caseName), + before: [], + after: [], + runBefore: function(){ + if (parent) parent.runBefore.apply(this); + for ( var i = 0; i < frame.before.length; i++) { + frame.before[i].apply(this); + } + }, + runAfter: function(){ + for ( var i = 0; i < frame.after.length; i++) { + frame.after[i].apply(this); + } + if (parent) parent.runAfter.apply(this); + } + }; + return frame; + }; + + jasmine.Env.prototype.describe = (function(describe){ + return function(description){ + currentFrame = frame(currentFrame, description); + var val = describe.apply(this, arguments); + currentFrame = currentFrame.parent; + return val; + }; + + })(jasmine.Env.prototype.describe); + + + jasmine.Env.prototype.it = (function(it){ + return function(desc, itFn){ + var self = this; + var spec = it.apply(this, arguments); + var currentSpec = this.currentSpec; + var frame = this.jstdFrame = currentFrame; + this.jstdFrame.testCase.prototype['test that it ' + desc] = function(){ + frame.runBefore.apply(currentSpec); + try { + itFn.apply(currentSpec); + } finally { + frame.runAfter.apply(currentSpec); + } + }; + return spec; + }; + + })(jasmine.Env.prototype.it); + + + jasmine.Env.prototype.beforeEach = (function(beforeEach){ + return function(beforeEachFunction) { + beforeEach.apply(this, arguments); + currentFrame.before.push(beforeEachFunction); + }; + + })(jasmine.Env.prototype.beforeEach); + + + jasmine.Env.prototype.afterEach = (function(afterEach){ + return function(afterEachFunction) { + afterEach.apply(this, arguments); + currentFrame.after.push(afterEachFunction); + }; + + })(jasmine.Env.prototype.afterEach); + + + jasmine.NestedResults.prototype.addResult = (function(addResult){ + return function(result) { + addResult.call(this, result); + if (result.type != 'MessageResult' && !result.passed()) fail(result.message); + }; + + })(jasmine.NestedResults.prototype.addResult); + + // Reset environment with overriden methods. + jasmine.currentEnv_ = null; + jasmine.getEnv(); })(); -- cgit v1.2.3 From 5dda723185a9037b7e92828d32430c21838ee216 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 10 May 2010 20:24:20 -0700 Subject: improved handling of text fields when formater fails to prevent clobering of field --- lib/jasmine-jstd-adapter/JasmineAdapter.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/jasmine-jstd-adapter') diff --git a/lib/jasmine-jstd-adapter/JasmineAdapter.js b/lib/jasmine-jstd-adapter/JasmineAdapter.js index ba54251a..0fdc4612 100644 --- a/lib/jasmine-jstd-adapter/JasmineAdapter.js +++ b/lib/jasmine-jstd-adapter/JasmineAdapter.js @@ -9,7 +9,7 @@ function bind(_this, _function){ return function(){ return _function.call(_this); - } + }; } var currentFrame = frame(null, null); @@ -49,14 +49,22 @@ })(jasmine.Env.prototype.describe); + var id = 0; jasmine.Env.prototype.it = (function(it){ return function(desc, itFn){ var self = this; var spec = it.apply(this, arguments); var currentSpec = this.currentSpec; + if (!currentSpec.$id) { + currentSpec.$id = id++; + } var frame = this.jstdFrame = currentFrame; - this.jstdFrame.testCase.prototype['test that it ' + desc] = function(){ + var name = 'test that it ' + desc; + if (this.jstdFrame.testCase.prototype[name]) + throw "Spec with name '" + desc + "' already exists."; + this.jstdFrame.testCase.prototype[name] = function(){ + jasmine.getEnv().currentSpec = currentSpec; frame.runBefore.apply(currentSpec); try { itFn.apply(currentSpec); -- cgit v1.2.3