|
| 1 | +/** |
| 2 | + * @fileoverview Jasmine JsTestDriver Adapter. |
| 3 | + * @author ibolmo@gmail.com (Olmo Maldonado) |
| 4 | + */ |
| 5 | + |
| 6 | +(function() { |
| 7 | + |
| 8 | +// Suite/TestCase before and after function stacks. |
| 9 | +var before = []; |
| 10 | +var after = []; |
| 11 | + |
| 12 | +jasmine.Env.prototype.describe = (function(describe){ |
| 13 | + |
| 14 | + // TODO(ibolmo): Support nested describes. |
| 15 | + return function(description, specDefinitions){ |
| 16 | + this.currentTestCase = TestCase(description); |
| 17 | + return describe.call(this, description, specDefinitions); |
| 18 | + }; |
| 19 | + |
| 20 | +})(jasmine.Env.prototype.describe); |
| 21 | + |
| 22 | + |
| 23 | +jasmine.Env.prototype.it = (function(it){ |
| 24 | + |
| 25 | + return function(desc, func){ |
| 26 | + var spec = it.call(this, desc, func); |
| 27 | + this.currentTestCase.prototype['test that it ' + desc] = func; |
| 28 | + return spec; |
| 29 | + }; |
| 30 | + |
| 31 | +})(jasmine.Env.prototype.it); |
| 32 | + |
| 33 | + |
| 34 | +jasmine.Env.prototype.beforeEach = (function(beforeEach){ |
| 35 | + |
| 36 | + // TODO(ibolmo): Support beforeEach TestCase. |
| 37 | + return function(beforeEachFunction) { |
| 38 | + beforeEach.call(this, beforeEachFunction); |
| 39 | + if (this.currentTestCase) { |
| 40 | + this.currentTestCase.prototype.setUp = beforeEachFunction; |
| 41 | + } else { |
| 42 | + before.push(beforeEachFunction); |
| 43 | + } |
| 44 | + }; |
| 45 | + |
| 46 | +})(jasmine.Env.prototype.beforeEach); |
| 47 | + |
| 48 | + |
| 49 | +jasmine.Env.prototype.afterEach = (function(afterEach){ |
| 50 | + |
| 51 | + // TODO(ibolmo): Support afterEach TestCase. |
| 52 | + return function(afterEachFunction) { |
| 53 | + afterEach.call(this, afterEachFunction); |
| 54 | + if (this.currentTestCase) { |
| 55 | + this.currentTestCase.prototype.tearDown = afterEachFunction; |
| 56 | + } else { |
| 57 | + after.push(afterEachFunction); |
| 58 | + } |
| 59 | + }; |
| 60 | + |
| 61 | +})(jasmine.Env.prototype.afterEach); |
| 62 | + |
| 63 | + |
| 64 | +jasmine.NestedResults.prototype.addResult = (function(addResult){ |
| 65 | + |
| 66 | + return function(result) { |
| 67 | + addResult.call(this, result); |
| 68 | + if (result.type != 'MessageResult' && !result.passed()) fail(result.message); |
| 69 | + }; |
| 70 | + |
| 71 | +})(jasmine.NestedResults.prototype.addResult); |
| 72 | + |
| 73 | + |
| 74 | +jstestdriver.plugins.TestRunnerPlugin.prototype.runTestConfiguration = (function(runTestConfiguration){ |
| 75 | + |
| 76 | + return function(testRunConfiguration, onTestDone, onTestRunConfigurationComplete){ |
| 77 | + for (var i = 0, l = before.length; i < l; i++) before[i](); |
| 78 | + onTestRunConfigurationComplete = (function(configurationComplete){ |
| 79 | + |
| 80 | + return function() { |
| 81 | + for (var i = 0, l = after.length; i < l; i++) after[i](); |
| 82 | + configurationComplete(); |
| 83 | + }; |
| 84 | + |
| 85 | + })(onTestRunConfigurationComplete); |
| 86 | + runTestConfiguration.call(this, testRunConfiguration, onTestDone, onTestRunConfigurationComplete); |
| 87 | + }; |
| 88 | + |
| 89 | +})(jstestdriver.plugins.TestRunnerPlugin.prototype.runTestConfiguration); |
| 90 | + |
| 91 | + |
| 92 | +// Reset environment with overriden methods. |
| 93 | +jasmine.currentEnv_ = null; |
| 94 | +jasmine.getEnv(); |
| 95 | + |
| 96 | +})(); |
0 commit comments