From 7ee2e26525a75606275e532cb998020ec222567d Mon Sep 17 00:00:00 2001 From: Chris Moultrie Date: Tue, 4 Mar 2014 16:31:59 -0500 Subject: [PATCH] More workey, but not much --- lib/jasmine-node/boot.js | 18 +-- lib/jasmine-node/console.js | 3 - lib/jasmine-node/index.js | 19 ++- lib/jasmine-node/jasmine-2.0.0.js | 2 +- lib/jasmine-node/reporter.js | 132 +++++++++++---------- spec/TestSpec.js | 188 +++++++++++++++--------------- 6 files changed, 185 insertions(+), 177 deletions(-) diff --git a/lib/jasmine-node/boot.js b/lib/jasmine-node/boot.js index c3d95c5..f9d50ad 100755 --- a/lib/jasmine-node/boot.js +++ b/lib/jasmine-node/boot.js @@ -156,15 +156,15 @@ * * Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded. */ - var currentWindowOnload = window.onload; - - window.onload = function() { - if (currentWindowOnload) { - currentWindowOnload(); - } - htmlReporter.initialize(); - env.execute(); - }; + // var currentWindowOnload = window.onload; + // + // window.onload = function() { + // if (currentWindowOnload) { + // currentWindowOnload(); + // } + // htmlReporter.initialize(); + // //env.execute(); + // }; /** * Helper function for readability above. diff --git a/lib/jasmine-node/console.js b/lib/jasmine-node/console.js index 85de464..9da15a1 100755 --- a/lib/jasmine-node/console.js +++ b/lib/jasmine-node/console.js @@ -34,15 +34,12 @@ getJasmineRequireObj().console = function(jRequire, j$) { }; getJasmineRequireObj().ConsoleReporter = function() { - console.log('asdfasdfasd'); - var noopTimer = { start: function(){}, elapsed: function(){ return 0; } }; function ConsoleReporter(options) { - console.log('ahdsf', options); var print = options.print, showColors = options.showColors || false, onComplete = options.onComplete || function() {}, diff --git a/lib/jasmine-node/index.js b/lib/jasmine-node/index.js index d265448..e075053 100755 --- a/lib/jasmine-node/index.js +++ b/lib/jasmine-node/index.js @@ -137,18 +137,11 @@ jasmine.executeSpecsInFolder = function(options){ onComplete: done, stackFilter: removeJasmineFrames})); } else { - console.log('console reporter!'); - console.log(util.inspect(jasmine)) - reporter = new jasmine.ConsoleReporter({print: print, color: true}); - console.log(reporter()); - jasmineEnv.addReporter(reporter); - - //jasmineEnv.addReporter(jasmine.ConsoleReporter({print: print, - //jasmineEnv.addReporter(new jasmine.TerminalReporter({print: print, - // color: showColors - // includeStackTrace: includeStackTrace, - // onComplete: done, - // stackFilter: removeJasmineFrames})); + jasmineEnv.addReporter(new jasmine.TerminalReporter({print: print, + color: showColors, + includeStackTrace: includeStackTrace, + onComplete: done, + stackFilter: removeJasmineFrames})); } if (growl) { @@ -164,6 +157,8 @@ jasmine.executeSpecsInFolder = function(options){ ); } else { describe = jasmineEnv.describe; + beforeEach = jasmineEnv.beforeEach; + expect = jasmineEnv.expect; var specsList = specs.getSpecs(); for (var i = 0, len = specsList.length; i < len; ++i) { diff --git a/lib/jasmine-node/jasmine-2.0.0.js b/lib/jasmine-node/jasmine-2.0.0.js index 24463ec..56a4f01 100755 --- a/lib/jasmine-node/jasmine-2.0.0.js +++ b/lib/jasmine-node/jasmine-2.0.0.js @@ -810,7 +810,7 @@ getJasmineRequireObj().Any = function() { if (this.expectedObject == Object) { return typeof other == 'object'; } - + if (this.expectedObject == Boolean) { return typeof other == 'boolean'; } diff --git a/lib/jasmine-node/reporter.js b/lib/jasmine-node/reporter.js index 24a7317..1e2d063 100755 --- a/lib/jasmine-node/reporter.js +++ b/lib/jasmine-node/reporter.js @@ -20,6 +20,8 @@ this.print_ = config.print || function (str) { process.stdout.write(util.format(str)); }; this.color_ = config.color ? this.ANSIColors : this.NoColors; + this.currentSuite_ = null; + this.started_ = false; this.finished_ = false; @@ -32,16 +34,25 @@ this.stackFilter_ = config.stackFilter || function(t) { return t; }; } - jasmineNode.TerminalReporter.prototype = { - reportRunnerStarting: function(runner) { + jasmineStarted: function(runner) { + this.printLine_("Jasmine Starting with " + runner.totalSpecsDefined + " specs"); + }, + suiteDone: function(done) { + this.reportFailures_(); + //console.log(done); + }, + // specDone: function(result) { + // console.log(result.status); + // }, + suiteStarted: function(suite) { this.started_ = true; this.startedAt = new Date(); - var suites = runner.topLevelSuites(); - for (var i = 0; i < suites.length; i++) { - var suite = suites[i]; - this.suites_.push(this.summarize_(suite)); - } + this.suites_.push(this.summarize_(suite, true)); + this.currentSuite_ = this.suites_[this.suites_.length - 1]; + }, + specStarted: function(spec) { + this.currentSuite_.children.push(this.summarize_(spec, false)); }, ANSIColors: { @@ -62,9 +73,8 @@ neutral: function() { return ''; } }, - summarize_: function(suiteOrSpec) { - var isSuite = suiteOrSpec instanceof jasmine.Suite; - + // Builds the description object for the spec or suite + summarize_: function(suiteOrSpec, isSuite) { // We could use a separate object for suite and spec var summary = { id: suiteOrSpec.id, @@ -75,21 +85,22 @@ }; if (isSuite) { - var calculateNestingLevel = function(examinedSuite) { - var nestingLevel = 0; - while (examinedSuite.parentSuite !== null) { - nestingLevel += 1; - examinedSuite = examinedSuite.parentSuite; - } - return nestingLevel; - }; - - summary.suiteNestingLevel = calculateNestingLevel(suiteOrSpec); - - var children = suiteOrSpec.children(); - for (var i = 0; i < children.length; i++) { - summary.children.push(this.summarize_(children[i])); - } + // var calculateNestingLevel = function(examinedSuite) { + // var nestingLevel = 0; + // while (examinedSuite.parentSuite !== null) { + // nestingLevel += 1; + // examinedSuite = examinedSuite.parentSuite; + // } + // return nestingLevel; + // }; + + //summary.suiteNestingLevel = calculateNestingLevel(suiteOrSpec); + summary.suiteNestingLevel = 0; + + // var children = suiteOrSpec.children(); + // for (var i = 0; i < children.length; i++) { + // summary.children.push(this.summarize_(children[i])); + // } } return summary; @@ -144,39 +155,37 @@ // Not used in this context }, - reportSpecResults: function(spec) { - var result = spec.results(); + specDone: function(spec) { + //console.log(spec); var msg = ''; - if (result.skipped) { + if (spec.status === 'skipped') { msg = this.stringWithColor_('-', this.color_.ignore()); - } else if (result.passed()) { + } else if (spec.status === 'passed') { msg = this.stringWithColor_('.', this.color_.pass()); - } else { + } else if (spec.status === 'failed'){ msg = this.stringWithColor_('F', this.color_.fail()); this.addFailureToFailures_(spec); + } else { + msg = this.stringWithColor_('U' + spec.status, this.color_.fail()); } this.spec_results += msg; this.print_(msg); }, addFailureToFailures_: function(spec) { - var result = spec.results(); - var failureItem = null; - - var items_length = result.items_.length; - for (var i = 0; i < items_length; i++) { - if (result.items_[i].passed_ === false) { - failureItem = result.items_[i]; - - var failure = { - spec: spec.suite.getFullName() + " " + spec.description, - message: failureItem.message, - stackTrace: failureItem.trace.stack - } - - this.failures_.push(failure); + failures = spec.failedExpectations; + for (var i = 0; i < failures.length; i++) { + failure = failures[i]; + + var failureDesc = { + spec: spec.description, + message: failure.message, + stackTrace: failure.stack } + + this.failures_.push(failureDesc); } + }, printRunnerResults_: function(runner){ @@ -223,33 +232,35 @@ jasmineNode.TerminalVerboseReporter.prototype = { - reportSpecStarting: function(spec) { + specStarted: function(spec) { now = new Date().getTime(); this.specTimes_[spec.id] = now; - var suite = spec.suite; - while (suite) { - if (!this.suiteTimes_[suite.id]) { - this.suiteTimes_[suite.id] = now; - } - suite = suite.parentSuite; - } + // var suite = spec.suite; + // while (suite) { + // if (!this.suiteTimes_[suite.id]) { + // this.suiteTimes_[suite.id] = now; + // } + // suite = suite.parentSuite; + // } + jasmineNode.TerminalReporter.prototype.specStarted.call(this, spec); }, - reportSpecResults: function(spec) { + specDone: function(spec) { var elapsed = new Date().getTime() - this.specTimes_[spec.id]; - if (spec.results().failedCount > 0) { + if (spec.failedExpectations.length > 0) { this.addFailureToFailures_(spec); } this.specResults_[spec.id] = { - messages: spec.results().getItems(), - result: spec.results().failedCount > 0 ? 'failed' : 'passed', + messages: spec.failedExpectations, + result: spec.failedExpectations.length > 0 ? 'failed' : 'passed', runtime: elapsed }; + jasmineNode.TerminalReporter.prototype.specDone.call(this, spec); }, - reportSuiteResults: function(suite) { + suiteDone: function(suite) { var startTime = this.suiteTimes_[suite.id]; if (startTime) { var elapsed = new Date().getTime() - startTime; @@ -257,9 +268,10 @@ runtime: elapsed }; } + jasmineNode.TerminalReporter.prototype.suiteDone.call(this, suite); }, - reportRunnerResults: function(runner) { + jasmineDone: function(runner) { var messages = new Array(); this.buildMessagesFromResults_(messages, this.suites_); @@ -271,7 +283,7 @@ this.print_(messages[messages_length-1]); // Call the parent object's method - jasmineNode.TerminalReporter.prototype.reportRunnerResults.call(this, runner); + jasmineNode.TerminalReporter.prototype.jasmineDone.call(this, runner); }, buildMessagesFromResults_: function(messages, results, depth) { diff --git a/spec/TestSpec.js b/spec/TestSpec.js index 27297d8..ec70568 100755 --- a/spec/TestSpec.js +++ b/spec/TestSpec.js @@ -3,98 +3,102 @@ describe('jasmine-node-flat', function(){ expect(1+2).toEqual(3); }); }); -return - -describe('beforeEach Timeout', function(){ - beforeEach(function(done) { - setTimeout(done, 1000); - }, 100); - it('should fail', function(){ - expect(1+2).toEqual(3); - }); -}); - -describe('afterEach Timeout', function(){ - afterEach(function(done) { - setTimeout(done, 1000); - }, 100); - it('should pass and then afterEach will fail', function(){ - expect(1+2).toEqual(3); - }); -}); - -describe('Testing some characters', function() { - var chars = ['&', '\'', '"', '<', '>']; - for(var i = 0; i < chars.length; i+=1) { - currentChar = chars[i]; - it('should reject ' + currentChar, (function(currentChar) { - expect(false).toEqual(false); - })(currentChar)); - } -}); - -describe('Testing waitsfor functionality', function() { - it("Runs and then waitsFor", function() { - runs(function() { - 1+1; - }); - waitsFor(function() { - return true === false; - }, "the impossible", 1000); - runs(function() { - expect(true).toBeTruthy(); - }); - }); -}); - -describe('root', function () { - - describe('nested', function () { - - xit('nested statement', function () { - expect(1).toBeTruthy(); - }); - - }); - - it('root statement', function () { - expect(1).toBeTruthy(); - }); - -}); - -describe("Top level describe block", function() { - it("first it block in top level describe", function() { - expect(true).toEqual(true); - }); - describe("Second level describe block", function() { - it("first it block in second level describe", function() { - expect(true).toBe(true); - }); - }); - it("second it block in top level describe", function() { - expect(true).toEqual(true); +describe('jasmine-node-flat', function(){ + it('should pass', function(){ + expect(1+2).toEqual(4); }); }); -describe('async', function () { - - var request = function (str, func) { - func('1', '2', 'hello world'); - }; - - it("should respond with hello world", function(done) { - request("http://localhost:3000/hello", function(error, response, body){ - expect(body).toEqual("hello world"); - done(); - }); - }); - - it("should respond with hello world", function(done) { - request("http://localhost:3000/hello", function(error, response, body){ - expect(body).toEqual("hello world"); - done(); - }); - }, 250); // timeout after 250 ms - -}); +// describe('beforeEach Timeout', function(){ +// beforeEach(function(done) { +// setTimeout(done, 1000); +// }, 100); +// it('should fail', function(){ +// expect(1+2).toEqual(3); +// }); +// }); +// +// describe('afterEach Timeout', function(){ +// afterEach(function(done) { +// setTimeout(done, 1000); +// }, 100); +// it('should pass and then afterEach will fail', function(){ +// expect(1+2).toEqual(3); +// }); +// }); +// +// describe('Testing some characters', function() { +// var chars = ['&', '\'', '"', '<', '>']; +// for(var i = 0; i < chars.length; i+=1) { +// currentChar = chars[i]; +// it('should reject ' + currentChar, (function(currentChar) { +// expect(false).toEqual(false); +// })(currentChar)); +// } +// }); +// +// describe('Testing waitsfor functionality', function() { +// it("Runs and then waitsFor", function() { +// runs(function() { +// 1+1; +// }); +// waitsFor(function() { +// return true === false; +// }, "the impossible", 1000); +// runs(function() { +// expect(true).toBeTruthy(); +// }); +// }); +// }); +// +// describe('root', function () { +// +// describe('nested', function () { +// +// xit('nested statement', function () { +// expect(1).toBeTruthy(); +// }); +// +// }); +// +// it('root statement', function () { +// expect(1).toBeTruthy(); +// }); +// +// }); +// +// describe("Top level describe block", function() { +// it("first it block in top level describe", function() { +// expect(true).toEqual(true); +// }); +// describe("Second level describe block", function() { +// it("first it block in second level describe", function() { +// expect(true).toBe(true); +// }); +// }); +// it("second it block in top level describe", function() { +// expect(true).toEqual(true); +// }); +// }); +// +// describe('async', function () { +// +// var request = function (str, func) { +// func('1', '2', 'hello world'); +// }; +// +// it("should respond with hello world", function(done) { +// request("http://localhost:3000/hello", function(error, response, body){ +// expect(body).toEqual("hello world"); +// done(); +// }); +// }); +// +// it("should respond with hello world", function(done) { +// request("http://localhost:3000/hello", function(error, response, body){ +// expect(body).toEqual("hello world"); +// done(); +// }); +// }, 250); // timeout after 250 ms +// +// });