From 185cd5c4a9fad6dff4254df8b18938377f6c4401 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Sun, 23 Feb 2014 23:44:36 -0800 Subject: [PATCH] Factor test runner into Jasminum project --- package.json | 18 +- test.js | 278 ------------- test/browser-reporter.js | 87 ---- test/browser-runner.js | 20 - test/{domain.js => domain-test.js} | 6 +- test/{eta.js => eta-test.js} | 64 +-- test/index.html | 4 +- test/index.js | 27 ++ test/{never-again.js => never-again-test.js} | 16 +- test/node-reporter.js | 94 ----- test/node-runner.js | 24 -- test/{node.js => node-test.js} | 60 +-- test/{q.js => q-test.js} | 409 ++++++++++--------- test/{queue.js => queue-test.js} | 16 +- test/{traces.js => traces-test.js} | 4 +- 15 files changed, 325 insertions(+), 802 deletions(-) delete mode 100644 test.js delete mode 100644 test/browser-reporter.js delete mode 100644 test/browser-runner.js rename test/{domain.js => domain-test.js} (95%) rename test/{eta.js => eta-test.js} (85%) create mode 100644 test/index.js rename test/{never-again.js => never-again-test.js} (83%) delete mode 100644 test/node-reporter.js delete mode 100644 test/node-runner.js rename test/{node.js => node-test.js} (83%) rename test/{q.js => q-test.js} (78%) rename test/{queue.js => queue-test.js} (87%) rename test/{traces.js => traces-test.js} (91%) diff --git a/package.json b/package.json index 6a742865..be85df99 100644 --- a/package.json +++ b/package.json @@ -46,25 +46,23 @@ }, "devDependencies": { "jshint": "~2.3.0", - "jasmine-node": "1.11.0", - "opener": "*", - "promises-aplus-tests": "1.x", + "jasminum": "~0.0.0", + "opener": "~1.3.0", + "promises-aplus-tests": "~1.0.2", + "mr": "~0.15.1", + "istanbul": "~0.2.4", + "matcha": "~0.2.0", "grunt": "~0.4.1", "grunt-cli": "~0.1.9", "grunt-contrib-uglify": "~0.2.2", "grunt-contrib-clean": "~0.5.0", - "matcha": "~0.2.0", "grunt-global-wrap": "~1.1.0", "grunt-amd-wrap": "~1.0.0", - "grunt-s3": "~0.2.0-alpha.2", - "mr": "~0.13.3", - "collections": "~0.2.2", - "colors": "~0.6.2", - "istanbul": "~0.2.4" + "grunt-s3": "~0.2.0-alpha.2" }, "scripts": { "lint": "jshint q.js", - "test": "npm run lint && node test/node-runner.js && promises-aplus-tests test/aplus-adapter", + "test": "npm run lint && jasminum test && promises-aplus-tests test/aplus-adapter", "cover": "istanbul cover test/index.js && istanbul report html && opener coverage/index.html", "release": "grunt release", "benchmark": "matcha" diff --git a/test.js b/test.js deleted file mode 100644 index b73722e7..00000000 --- a/test.js +++ /dev/null @@ -1,278 +0,0 @@ -// vim:ts=4:sts=4:sw=4: -/* global describe, xdescribe, ddescribe, it, xit, iit, expect, beforeEach, - afterEach */ - -require("collections/shim"); -var Q = require("../q"); - -var currentSuite; -var currentTest; -var currentReport; - -describe = function (name, callback) { - if (currentSuite) { - var parent = currentSuite; - currentSuite = parent.nestSuite(name); - callback(); - currentSuite = parent; - } else { - var root = new Suite(name); - currentSuite = root; - try { - callback(); - } finally { - currentSuite = null; - } - return root; - } -}; - -xdescribe = function (name, callback) { - var parent = currentSuite.nestSuite(name); - currentSuite = parent.nestSuite(name); - currentSuite.skip = true; - callback(); - currentSuite = parent; -}; - -ddescribe = function (name, callback) { - var parent = currentSuite; - currentSuite = parent.nestSuite(name, true); - callback(); - currentSuite = parent; -}; - -it = function (name, callback) { - currentSuite.nestTest(name, callback); -}; - -iit = function (name, callback) { - currentSuite.nestTest(name, callback, true); -}; - -xit = function (name, callback) { - var test = currentSuite.nestTest(name, callback); - test.skip = true; -}; - -beforeEach = function (callback) { - if (!currentSuite) { - throw new Error("Cannot use `beforeEach` outside of a 'define' block"); - } - currentSuite.beforeEach = callback; -}; - -afterEach = function (callback) { - if (!currentSuite) { - throw new Error("Cannot use `afterEach` outside of a 'define' block"); - } - currentSuite.afterEach = callback; -}; - -expect = function (value) { - if (!currentTest) { - throw new Error("Cannot declare an expectation outside of an 'it' block"); - } - return new currentTest.Expectation(value, currentTest); -}; - -function Expectation(value, test) { - this.value = value; - this.test = test; - this.not = Object.create(this); - this.not.isNot = true; -} - -function getStackTrace() { - var stack = new Error("").stack; - if (typeof stack === "string") { - return stack.replace(/^[^\n]*\n[^\n]\n/, ""); - } else { - return stack; - } -} - -function expectMethod(operator, operatorName) { - return function (value) { - var args = Array.prototype.slice.call(arguments, 1); - args.unshift(value, this.value); - var guard = operator.apply(void 0, args); - var stack = getStackTrace(); - var assertion = { - operator: (this.isNot ? "not " : "") + operatorName, - not: this.isNot, - expected: this.value, - actual: value, - stack: stack || "" - }; - if (!!guard === !!this.isNot) { - currentReport.failAssertion(assertion); - } else { - currentReport.passAssertion(assertion); - } - }; -} - -function lessThan(a, b) { - return Object.compare(a, b) < 0; -} - -function greaterThan(a, b) { - return Object.compare(a, b) > 0; -} - -function near(a, b, epsilon) { - var difference = Math.abs(Object.compare(a, b)); - if (difference === 0) { - return Object.equals(a, b); - } else { - return difference < epsilon; - } -} - -// TODO extensible expectations -Expectation.prototype.equals = expectMethod(Object.equals, "to equal"); -Expectation.prototype.is = expectMethod(Object.is, "to be"); -Expectation.prototype.has = expectMethod(Object.has, "to have"); -Expectation.prototype.contains = expectMethod(Object.contains, "to contain"); -Expectation.prototype.lessThan = expectMethod(lessThan, "to be less than"); -Expectation.prototype.greaterThan = expectMethod(greaterThan, "to be greater than"); -Expectation.prototype.near = expectMethod(near, "to be near"); - -function Suite(name) { - this.name = name; - this.exclusive = false; - this.root = this; - this.children = []; - this.testCount = 0; -} - -Suite.prototype.type = "describe"; - -Suite.prototype.nestSuite = function (name, exclusive) { - var child = Object.create(this); - child.parent = this; - child.name = name; - child.children = []; - child.exclusive = false; - this.children.push(child); - if (exclusive) { - child.setExclusive(); - } - return child; -}; - -Suite.prototype.nestTest = function (name, callback, exclusive) { - var child = new this.Test(name, callback, this, this.root); - this.root.testCount++; - child.exclusive = !!exclusive; - this.children.push(child); - if (exclusive) { - this.setExclusive(); - } - return child; -}; - -Suite.prototype.setExclusive = function () { - var parent = this; - while (parent) { - parent.exclusive = true; - parent = parent.parent; - } -}; - -Suite.prototype.run = function (report) { - var self = this; - if (self.skip) { - return Q(); - } - self.started = true; - var exclusiveChildren = self.children.filter(function (child) { - return child.exclusive; - }); - var children = exclusiveChildren.length ? exclusiveChildren : self.children; - var suiteReport = report.start(self); - return children.reduce(function (previous, child) { - return previous.then(function () { - if (child.run) { - return child.run(suiteReport); - } - }); - }, Q()) - .finally(function () { - suiteReport.end(self); - self.finished = true; - }); -}; - -Suite.prototype.Test = Test; - -function Test(name, callback, suite, root) { - this.name = name; - this.callback = callback; - this.children = []; - this.suite = suite; - this.root = root; -} - -Test.prototype.Expectation = Expectation; - -Test.prototype.type = "it"; - -Test.prototype.run = function (report) { - var self = this; - self.started = true; - currentTest = self; - currentReport = report.start(self); - return Q.try(function () { - if (!self.skip) { - return Q.try(function () { - if (self.suite.beforeEach) { - return call(self.suite.beforeEach, currentTest, currentReport, "before"); - } - }) - .then(function () { - return call(self.callback, currentTest, currentReport, "during"); - }) - .finally(function () { - if (self.suite.afterEach) { - return call(self.suite.afterEach, currentTest, currentReport, "after"); - } - }); - } - }) - .timeout(3000) - .then(function () { - if (self.skip) { - currentReport.skip(self); - } - }, function (error) { - currentReport.error(error, self); - }) - .finally(function () { - currentReport.end(self); - currentTest = null; - currentReport = null; - }); -}; - -function call(callback, test, report, phase) { - function done(error) { - if (!deferred.promise.isPending()) { - report.error(new Error("`done` called multiple times " + phase + " " + JSON.stringify(test.name)), test); - } - if (error) { - deferred.reject(error); - } else { - deferred.resolve(); - } - } - if (callback.length === 1) { - var deferred = Q.defer(); - callback(done); - return deferred.promise; - } else { - return callback(); - } -} - diff --git a/test/browser-reporter.js b/test/browser-reporter.js deleted file mode 100644 index 07f123b7..00000000 --- a/test/browser-reporter.js +++ /dev/null @@ -1,87 +0,0 @@ - -var body = document.querySelector("body"); -body.classList.add("testing"); - -module.exports = Reporter; -function Reporter() { - this.root = this; - this.passed = 0; - this.failed = 0; - this.skipped = 0; - this.errors = 0; - this.passedAssertions = 0; - this.failedAssertions = 0; - this.depth = 0; -} - -Reporter.prototype.start = function (test) { - var child = Object.create(this); - child.depth = this.depth + 1; - child.failed = false; - child.skipped = false; - console.group(test.type + " " + test.name); - return child; -}; - -Reporter.prototype.end = function (test) { - if (test.type === "it") { - if (this.failed) { - this.root.failed++; - body.classList.add("fail"); - console.error("FAIL"); - } else if (this.skipped) { - this.root.skipped++; - } else { - this.root.passed++; - } - } - console.groupEnd(); -}; - -Reporter.prototype.summarize = function (suite) { - if (!this.failed) { - body.classList.add("pass"); - } - console.log(this.passed + " passed tests"); - console.log(this.passedAssertions + " passed assertions"); - if (this.failed) { - console.error(this.failed + " failed tests"); - } else { - console.log(this.failed + " failed tests"); - } - if (this.failedAssertions) { - console.error(this.failedAssertions + " failed assertions"); - } else { - console.log(this.failedAssertions + " failed assertions"); - } - console.log(this.errors + " errors"); - var skipped = suite.testCount - this.passed - this.failed; - console.log(skipped + " skipped tests"); -}; - -Reporter.prototype.skip = function () { - this.skipped = true; - this.root.skipped++; -}; - -Reporter.prototype.failAssertion = function (assertion) { - console.log("expected"); - console.log(assertion.expected); - console.log(assertion.operator); - console.log(assertion.actual); - console.log("at"); - console.error(assertion.stack); - this.failed = true; - this.root.failedAssertions++; -}; - -Reporter.prototype.passAssertion = function () { - this.root.passedAssertions++; -}; - -Reporter.prototype.error = function (error, test) { - this.failed = true; - this.root.erros++; - console.log(error.stack); -}; - diff --git a/test/browser-runner.js b/test/browser-runner.js deleted file mode 100644 index e80fbf9a..00000000 --- a/test/browser-runner.js +++ /dev/null @@ -1,20 +0,0 @@ - -require("../test"); -var Reporter = require("./browser-reporter"); - -var suite = describe("Q", function () { - require("./q"); - require("./eta"); - require("./traces"); - require("./never-again"); - require("./node"); - require("./queue"); -}); - -var report = new Reporter(); -suite.run(report) -.then(function () { - report.summarize(suite); -}) -.done(); - diff --git a/test/domain.js b/test/domain-test.js similarity index 95% rename from test/domain.js rename to test/domain-test.js index 84a031c3..8d7caae8 100644 --- a/test/domain.js +++ b/test/domain-test.js @@ -41,7 +41,7 @@ describe("node domain support", function () { }, 100); d.on("error", function (theError) { - expect(theError).is(error); + expect(theError).toBe(error); clearTimeout(errorTimeout); done(); }); @@ -59,7 +59,7 @@ describe("node domain support", function () { }, 100); d.on("error", function (theError) { - expect(theError).is(error); + expect(theError).toBe(error); clearTimeout(errorTimeout); done(); }); @@ -83,7 +83,7 @@ describe("node domain support", function () { }, 500); d.on("error", function (theError) { - expect(theError).is(error); + expect(theError).toBe(error); clearTimeout(errorTimeout); done(); }); diff --git a/test/eta.js b/test/eta-test.js similarity index 85% rename from test/eta.js rename to test/eta-test.js index c01dc21e..0bf43320 100644 --- a/test/eta.js +++ b/test/eta-test.js @@ -7,9 +7,9 @@ describe("estimate", function () { it("a deferred assumes never fulfilled", function (done) { var deferred = Q.defer(); - expect(deferred.promise.getEstimate()).is(Infinity); + expect(deferred.promise.getEstimate()).toBe(Infinity); deferred.promise.observeEstimate(function (estimate) { - expect(estimate).is(Infinity); + expect(estimate).toBe(Infinity); done(); }); }); @@ -18,14 +18,14 @@ describe("estimate", function () { var deferred = Q.defer(); var now = Date.now(); deferred.promise.observeEstimate(function (estimate) { - expect(estimate).is(now + 2000) + expect(estimate).toBe(now + 2000) done(); }); - expect(deferred.promise.getEstimate()).is(Infinity); + expect(deferred.promise.getEstimate()).toBe(Infinity); deferred.setEstimate(now + 1000); - expect(deferred.promise.getEstimate()).is(now + 1000); + expect(deferred.promise.getEstimate()).toBe(now + 1000); deferred.setEstimate(now + 2000); - expect(deferred.promise.getEstimate()).is(now + 2000); + expect(deferred.promise.getEstimate()).toBe(now + 2000); }); it("a deferred's estimate becomes the estimate of the resolution", function () { @@ -33,13 +33,13 @@ describe("estimate", function () { var d2 = Q.defer(); var now = Date.now(); - expect(d1.promise.getEstimate()).is(Infinity); + expect(d1.promise.getEstimate()).toBe(Infinity); d1.setEstimate(now + 1000); - expect(d1.promise.getEstimate()).is(now + 1000); + expect(d1.promise.getEstimate()).toBe(now + 1000); - expect(d2.promise.getEstimate()).is(Infinity); + expect(d2.promise.getEstimate()).toBe(Infinity); d2.resolve(d1.promise); - expect(d2.promise.getEstimate()).is(now + 1000); + expect(d2.promise.getEstimate()).toBe(now + 1000); }); it("a deferred's new estimate is observable upon resolution", function (done) { @@ -48,7 +48,7 @@ describe("estimate", function () { var now = Date.now(); d2.promise.observeEstimate(function (estimate) { - expect(estimate).is(now + 1000); + expect(estimate).toBe(now + 1000); done(); }); @@ -59,9 +59,9 @@ describe("estimate", function () { it("interprets invalid estimates as forever", function () { var deferred = Q.defer(); deferred.setEstimate({}); - expect(deferred.promise.getEstimate()).is(Infinity); + expect(deferred.promise.getEstimate()).toBe(Infinity); deferred.setEstimate(NaN); - expect(deferred.promise.getEstimate()).is(Infinity); + expect(deferred.promise.getEstimate()).toBe(Infinity); }); describe("then", function () { @@ -78,7 +78,7 @@ describe("estimate", function () { var thenPromise = thisDeferred.promise.then(null, null, 1000); // So the composite time to completion should be one second from // now. - expect(thenPromise.getEstimate()).is(now + 1000); + expect(thenPromise.getEstimate()).toBe(now + 1000); // But we don't go through the exercise of resolving thisPromise as // it is beyond the scope of this test. If we did, the time to // completion would be almost instantaneous since neither @@ -107,13 +107,13 @@ describe("estimate", function () { // The composite ETA of thenPromise should be now + 100ms (this) + // 200ms (then). setTimeout(function () { - expect(thenPromise.getEstimate()).near(now + 300, 10); + expect(thenPromise.getEstimate()).toBeNear(now + 300, 10); }, 0); // But the actual time of completion will be now + 200ms (this // actual) + 300ms (fulfilled actual) setTimeout(function () { - expect(thenPromise.getEstimate()).near(now + 500, 10); + expect(thenPromise.getEstimate()).toBeNear(now + 500, 10); done(); }, 600); }); @@ -125,24 +125,24 @@ describe("estimate", function () { it("composes initial estimate for all fulfilled values", function () { var now = Date.now(); var allPromise = Q.all([Q(), Q(), Q()]); - expect(allPromise.getEstimate()).near(now, 10); + expect(allPromise.getEstimate()).toBeNear(now, 10); }); it("composes initial estimate for forever pending values", function () { var now = Date.now(); var allPromise = Q.all([Q(), Q.defer().promise, Q()]); - expect(allPromise.getEstimate()).is(Infinity); + expect(allPromise.getEstimate()).toBe(Infinity); }); it("composes estimate for forever pending value update", function (done) { var now = Date.now(); var oneDeferred = Q.defer(); var allPromise = Q.all([Q(), oneDeferred.promise, Q()]); - expect(allPromise.getEstimate()).is(Infinity); + expect(allPromise.getEstimate()).toBe(Infinity); var expected = [Infinity, now + 10]; var updates = 0; allPromise.observeEstimate(function (estimate) { - expect(estimate).near(expected.shift(), 10); + expect(estimate).toBeNear(expected.shift(), 10); if (++updates === 2) { done(); } @@ -165,10 +165,10 @@ describe("estimate", function () { d1.setEstimate(now); d2.setEstimate(now); d3.setEstimate(now); - expect(allPromise.getEstimate()).is(Infinity); + expect(allPromise.getEstimate()).toBe(Infinity); var updates = 0; allPromise.observeEstimate(function (estimate) { - expect(estimate).is(now); + expect(estimate).toBe(now); // TODO ascertain why this observer is getting called redundantly, // albeit idempotently // Both updates provide the initial value. @@ -179,7 +179,7 @@ describe("estimate", function () { .then(function () { // The input promises are forever-pending. We should never get // here. - expect(false).is(true); + expect(false).toBe(true); }); }); @@ -197,7 +197,7 @@ describe("estimate", function () { d1.setEstimate(now); d2.setEstimate(now); d3.setEstimate(now); - expect(allPromise.getEstimate()).is(Infinity); + expect(allPromise.getEstimate()).toBe(Infinity); // TODO again, ascertain the reason for the duplicate dispatch var expected = [ now, @@ -205,7 +205,7 @@ describe("estimate", function () { now + 1000 ]; allPromise.observeEstimate(function (estimate) { - expect(estimate).is(expected.shift()); + expect(estimate).toBe(expected.shift()); if (expected.length === 0) { done(); } @@ -231,7 +231,7 @@ describe("estimate", function () { d1.setEstimate(now + 1000); d2.setEstimate(now + 2000); d3.setEstimate(now + 500); - expect(allPromise.getEstimate()).is(Infinity); + expect(allPromise.getEstimate()).toBe(Infinity); // These are the estimates we expect to observe var expected = [ @@ -240,7 +240,7 @@ describe("estimate", function () { now + 500 // When d2 drops from +2000 to +500 ]; allPromise.observeEstimate(function (estimate) { - expect(estimate).is(expected.shift()); + expect(estimate).toBe(expected.shift()); if (expected.length === 0) { done(); } @@ -270,7 +270,7 @@ describe("estimate", function () { d1.setEstimate(now + 1000); d2.setEstimate(now + 2000); d3.setEstimate(now + 500); - expect(allPromise.getEstimate()).is(Infinity); + expect(allPromise.getEstimate()).toBe(Infinity); // These are the estimates we expect to observe var expected = [ @@ -280,7 +280,7 @@ describe("estimate", function () { now + 400, // When d3 drops from +500 to +0 ]; allPromise.observeEstimate(function (estimate) { - expect(estimate).is(expected.shift()); + expect(estimate).toBe(expected.shift()); if (expected.length === 0) { done(); } @@ -305,7 +305,7 @@ describe("estimate", function () { var delayedPromise = Q().delay(100); var updates = 0; delayedPromise.observeEstimate(function (estimate) { - expect(estimate).near(now + 100, 10); + expect(estimate).toBeNear(now + 100, 10); if (++updates === 2) { done(); } @@ -319,7 +319,7 @@ describe("estimate", function () { var delayedPromise = deferred.promise.delay(1000); var expected = [now + 2000, now + 2000]; delayedPromise.observeEstimate(function (estimate) { - expect(estimate).is(expected.shift()); + expect(estimate).toBe(expected.shift()); if (expected.length === 0) { done(); } @@ -335,7 +335,7 @@ describe("estimate", function () { var thenResolvedPromise = Q().delay(200).thenResolve(Q().delay(200)); var updates = 0; thenResolvedPromise.observeEstimate(function (estimate) { - expect(estimate).near(now + 200, 10); + expect(estimate).toBeNear(now + 200, 10); if (++updates === 4) { done(); } diff --git a/test/index.html b/test/index.html index 6191b11a..b9e7e253 100644 --- a/test/index.html +++ b/test/index.html @@ -2,8 +2,8 @@ - - + + diff --git a/test/index.js b/test/index.js new file mode 100644 index 00000000..a7efe657 --- /dev/null +++ b/test/index.js @@ -0,0 +1,27 @@ + +// "Isomprphic" test suite runner. This can be executed either: +// run node test/index.js +// or visit test/index.html (which loads this with Mr) + +var Suite = require("jasminum/suite"); +var Q = require("../q"); + +var suite = new Suite("Q").describe(function () { + + require("./q-test"); + require("./eta-test"); + require("./traces-test"); + require("./never-again-test"); + require("./node-test"); + require("./queue-test"); + + if (typeof process !== "undefined" && process.domain === null) { + // Parens around require signify that this is not a dependency as far + // as the browser loader is concerned. + (require)("./domain-test"); + } + +}); + +suite.runAndReport(Q.Promise).done(); + diff --git a/test/never-again.js b/test/never-again-test.js similarity index 83% rename from test/never-again.js rename to test/never-again-test.js index addc71fc..6e0e35c3 100644 --- a/test/never-again.js +++ b/test/never-again-test.js @@ -4,10 +4,10 @@ var REASON = "this is not an error, but it might show up in the console"; describe("gh-9", function () { it("treats falsy values as resolved values without error", function () { - expect(Q(null).isPending()).is(false); - expect(Q(void 0).isPending()).is(false); - expect(Q(false).isPending()).is(false); - expect(Q().isPending()).is(false); + expect(Q(null).isPending()).toBe(false); + expect(Q(void 0).isPending()).toBe(false); + expect(Q(false).isPending()).toBe(false); + expect(Q().isPending()).toBe(false); }); }); @@ -17,14 +17,14 @@ describe("gh-22", function () { for (var key in []) { keys.push(key); } - expect(keys.length).is(0); + expect(keys.length).toBe(0); }); }); describe("gh-73", function () { it("does not choke on non-error rejection reasons", function (done) { Q.onerror = function (error) { - expect(error).is(REASON); + expect(error).toBe(REASON); deferred.resolve(); }; @@ -41,7 +41,7 @@ describe("gh-73", function () { describe("gh-90", function () { it("does not choke on rejection reasons with an undefined `stack`", function (done) { Q.onerror = function (theError) { - expect(theError).is(error); + expect(theError).toBe(error); deferred.resolve(); }; @@ -76,7 +76,7 @@ describe("gh-75", function () { } badPromise.then(onResolution, onResolution).then(function () { - expect(resolutions).is(1); + expect(resolutions).toBe(1); }) .done(done, done); }); diff --git a/test/node-reporter.js b/test/node-reporter.js deleted file mode 100644 index dc5f47dc..00000000 --- a/test/node-reporter.js +++ /dev/null @@ -1,94 +0,0 @@ - -require("colors"); - -module.exports = Reporter; -function Reporter() { - this.root = this; - this.passed = 0; - this.failed = 0; - this.skipped = 0; - this.errors = 0; - this.passedAssertions = 0; - this.failedAssertions = 0; - this.depth = 0; -} - -Reporter.prototype.start = function (test) { - var child = Object.create(this); - child.depth = this.depth + 1; - child.failed = false; - child.skipped = false; - console.log((Array(child.depth + 1).join("❯") + " " + test.type + " " + test.name).grey); - return child; -}; - -Reporter.prototype.end = function (test) { - if (test.type === "it") { - if (this.failed) { - this.root.failed++; - } else if (this.skipped) { - this.root.skipped++; - } else { - this.root.passed++; - } - } -}; - -Reporter.prototype.summarize = function (suite) { - if (!this.failed && this.passed) { - console.log((this.passed + " passed tests").green); - } else { - console.log(this.passed + " passed tests"); - } - if (!this.failedAssertions && this.passedAssertions) { - console.log((this.passedAssertions + " passed assertions").green); - } else { - console.log(this.passedAssertions + " passed assertions"); - } - if (this.failed) { - console.log((this.failed + " failed tests").red); - } else { - console.log(this.failed + " failed tests"); - } - if (this.failedAssertions) { - console.log((this.failedAssertions + " failed assertions").red); - } else { - console.log(this.failedAssertions + " failed assertions"); - } - if (this.errors) { - console.log((this.errors + " errors").red); - } else { - console.log(this.errors + " errors"); - } - var skipped = suite.testCount - this.passed - this.failed; - if (skipped) { - console.log((skipped + " skipped tests").cyan); - } -}; - -Reporter.prototype.skip = function () { - this.skipped = true; - this.root.skipped++; -}; - -Reporter.prototype.failAssertion = function (assertion) { - console.log("expected".red); - console.log(assertion.expected); - console.log(assertion.operator.red); - console.log(assertion.actual); - console.log("at".red); - console.error(assertion.stack); - this.failed = true; - this.root.failedAssertions++; -}; - -Reporter.prototype.passAssertion = function () { - this.root.passedAssertions++; -}; - -Reporter.prototype.error = function (error, test) { - this.failed = true; - this.root.errors++; - console.error(error.stack); -}; - diff --git a/test/node-runner.js b/test/node-runner.js deleted file mode 100644 index 757cd059..00000000 --- a/test/node-runner.js +++ /dev/null @@ -1,24 +0,0 @@ - -require("../test"); -var Reporter = require("./node-reporter"); - -var suite = describe("Q", function () { - require("./q"); - require("./eta"); - require("./traces"); - require("./never-again"); - require("./node"); - require("./queue"); - require("./domain"); -}); - -var report = new Reporter(); -suite.run(report) -.then(function () { - report.summarize(suite); - if (report.failed) { - process.exit(-1); - } -}) -.done(); - diff --git a/test/node.js b/test/node-test.js similarity index 83% rename from test/node.js rename to test/node-test.js index 1c670b6c..591d8b84 100644 --- a/test/node.js +++ b/test/node-test.js @@ -27,7 +27,7 @@ describe("node support", function () { callback(null, a + b + c); }, [1, 2, 3]) .then(function (sum) { - expect(sum).is(6); + expect(sum).toBe(6); }) .done(done, done); }); @@ -38,9 +38,9 @@ describe("node support", function () { callback(exception); }, [1, 2, 3]) .then(function () { - expect(true).is(false); + expect(true).toBe(false); }, function (_exception) { - expect(_exception).is(exception); + expect(_exception).toBe(exception); }) .done(done, done); }); @@ -54,7 +54,7 @@ describe("node support", function () { callback(null, a + b + c); }, 1, 2, 3) .then(function (sum) { - expect(sum).is(6); + expect(sum).toBe(6); }) .done(done, done); }); @@ -65,9 +65,9 @@ describe("node support", function () { callback(exception); }, 1, 2, 3) .then(function () { - expect(true).is(false); + expect(true).toBe(false); }, function (_exception) { - expect(_exception).is(exception); + expect(_exception).toBe(exception); }) .done(done, done); }); @@ -81,7 +81,7 @@ describe("node support", function () { callback(null, a + b + c + d); }, 1, 2).call({}, 3, 4) .then(function (ten) { - expect(ten).is(10); + expect(ten).toBe(10); }) .done(done, done); }); @@ -95,7 +95,7 @@ describe("node support", function () { callback(null, this + a + b + c); }, 1, 2).call(3 /* effectively ignored as fn bound to 1 */, 4, 5) .then(function (twelve) { - expect(twelve).is(12); + expect(twelve).toBe(12); }) .done(done, done); }); @@ -106,7 +106,7 @@ describe("node support", function () { callback(null, this); }, expectedThis).call() .then(function(actualThis) { - expect(actualThis).is(expectedThis); + expect(actualThis).toBe(expectedThis); }) .done(done, done); }); @@ -118,7 +118,7 @@ describe("node support", function () { it("fulfills with callback result", function (done) { Q.npost(obj, "method", [1, 2, 3]) .then(function (sum) { - expect(sum).is(6); + expect(sum).toBe(6); }) .done(done, done); }); @@ -126,7 +126,7 @@ describe("node support", function () { it("gets the correct thisp", function (done) { return Q.npost(obj, "thispChecker", []) .then(function (result) { - expect(result).is(true); + expect(result).toBe(true); }) .done(done, done); }); @@ -134,9 +134,9 @@ describe("node support", function () { it("rejects with callback error", function (done) { return Q.npost(obj, "errorCallbacker", [1, 2, 3]) .then(function () { - expect("blue").is("no, yellow!"); + expect("blue").toBe("no, yellow!"); }, function (_exception) { - expect(_exception).is(exception); + expect(_exception).toBe(exception); }) .done(done, done); }); @@ -144,9 +144,9 @@ describe("node support", function () { it("rejects with thrown error", function (done) { return Q.npost(obj, "errorThrower", [1, 2, 3]) .then(function () { - expect(true).is(false); + expect(true).toBe(false); }, function (_exception) { - expect(_exception).is(exception); + expect(_exception).toBe(exception); }) .done(done, done); }); @@ -154,7 +154,7 @@ describe("node support", function () { it("works on promises for objects with Node methods", function (done) { return Q.npost(obj, "method", [1, 2, 3]) .then(function (sum) { - expect(sum).is(6); + expect(sum).toBe(6); }) .done(done, done); }); @@ -166,7 +166,7 @@ describe("node support", function () { it("fulfills with callback result", function (done) { Q.ninvoke(obj, "method", 1, 2, 3) .then(function (sum) { - expect(sum).is(6); + expect(sum).toBe(6); }) .done(done, done); }); @@ -174,7 +174,7 @@ describe("node support", function () { it("gets the correct thisp", function (done) { Q.ninvoke(obj, "thispChecker") .then(function (result) { - expect(result).is(true); + expect(result).toBe(true); }) .done(done, done); }); @@ -182,9 +182,9 @@ describe("node support", function () { it("rejects with callback error", function (done) { Q.ninvoke(obj, "errorCallbacker", 1, 2, 3) .then(function () { - expect("blue").is("no, yellow!"); + expect("blue").toBe("no, yellow!"); }, function (_exception) { - expect(_exception).is(exception); + expect(_exception).toBe(exception); }) .done(done, done); }); @@ -192,9 +192,9 @@ describe("node support", function () { it("rejects with thrown error", function (done) { Q.ninvoke(obj, "errorThrower", 1, 2, 3) .then(function () { - expect(true).is(false); + expect(true).toBe(false); }, function (_exception) { - expect(_exception).is(exception); + expect(_exception).toBe(exception); }) .done(done, done); }); @@ -202,7 +202,7 @@ describe("node support", function () { it("works on promises for objects with Node methods", function (done) { Q.ninvoke(obj, "method", 1, 2, 3) .then(function (sum) { - expect(sum).is(6); + expect(sum).toBe(6); }) .done(done, done); }); @@ -216,7 +216,7 @@ describe("node support", function () { var callback = Q.makeNodeResolver(deferred.resolve); callback(null, 10); deferred.promise.then(function (value) { - expect(value).is(10); + expect(value).toBe(10); }) .done(done, done); }); @@ -227,9 +227,9 @@ describe("node support", function () { var exception = new Error("Holy Exception of Anitoch"); callback(exception); deferred.promise.then(function () { - expect(5).is(3); + expect(5).toBe(3); }, function (_exception) { - expect(_exception).is(exception); + expect(_exception).toBe(exception); }) .done(done, done); }); @@ -240,22 +240,22 @@ describe("node support", function () { it("calls back with a resolution", function (done) { Q(10).nodeify(function (error, value) { - expect(error).is(null); - expect(value).is(10); + expect(error).toBe(null); + expect(value).toBe(10); done(); }); }); it("calls back with an error", function (done) { Q.reject(10).nodeify(function (error, value) { - expect(error).is(10); + expect(error).toBe(10); done(); }); }); it("forwards a promise", function (done) { Q(10).nodeify().then(function (ten) { - expect(ten).is(10); + expect(ten).toBe(10); }).done(done, done); }); diff --git a/test/q.js b/test/q-test.js similarity index 78% rename from test/q.js rename to test/q-test.js index 6c8bc2e1..af96768f 100644 --- a/test/q.js +++ b/test/q-test.js @@ -9,7 +9,7 @@ afterEach(function () { describe("Q proper", function () { it("returns a fulfilled promise when given a value", function () { - expect(Q(5).isFulfilled()).is(true); + expect(Q(5).isFulfilled()).toBe(true); }); it("passes promises through", function () { @@ -17,9 +17,9 @@ describe("Q proper", function () { var r = Q.reject(new Error("aaargh")); var p = Q.Promise(function () { }); - expect(Q(f)).is(f); - expect(Q(r)).is(r); - expect(Q(p)).is(p); + expect(Q(f)).toBe(f); + expect(Q(r)).toBe(r); + expect(Q(p)).toBe(p); }); }); @@ -31,8 +31,8 @@ describe("defer and then", function () { var deferred = Q.defer(); deferred.resolve(10); deferred.promise.then(function (value) { - expect(turn).is(1); - expect(value).is(10); + expect(turn).toBe(1); + expect(value).toBe(10); }).done(done, done); turn++; }); @@ -44,8 +44,8 @@ describe("defer and then", function () { deferred.promise.then(function () { expect(true).toBe(false); }, function (value) { - expect(turn).is(1); - expect(value).is(-1); + expect(turn).toBe(1); + expect(value).toBe(-1); }).done(done, done); turn++; }); @@ -54,12 +54,12 @@ describe("defer and then", function () { var turn = 0; var deferred = Q.defer(); deferred.promise.then(function (value) { - expect(turn).is(2); - expect(value).is(10); + expect(turn).toBe(2); + expect(value).toBe(10); turn++; }).done(done, done); asap(function () { - expect(turn).is(1); + expect(turn).toBe(1); deferred.resolve(10); turn++; }); @@ -72,13 +72,13 @@ describe("defer and then", function () { deferred.promise.then(function () { expect(true).toBe(false); }, function (value) { - expect(turn).is(2); - expect(value).is(-1); + expect(turn).toBe(2); + expect(value).toBe(-1); turn++; }) .done(done, done); asap(function () { - expect(turn).is(1); + expect(turn).toBe(1); deferred.reject(-1); turn++; }); @@ -95,8 +95,8 @@ describe("defer and then", function () { function resolve(value) { i++; - expect(value).is(resolution); - expect(nextTurn).is(true); + expect(value).toBe(resolution); + expect(nextTurn).toBe(true); if (i === count) { done(); } @@ -119,16 +119,16 @@ describe("defer and then", function () { throw new Error(REASON); }); deferred.promise.then(function (value) { - expect(value).is(10); + expect(value).toBe(10); }, function () { - expect("not").is("here"); + expect("not").toBe("here"); }).done(done, done); deferred.resolve(10); }); it("returns `undefined` from the deferred's methods", function () { - expect(Q.defer().resolve()).is(undefined); - expect(Q.defer().reject()).is(undefined); + expect(Q.defer().resolve()).toBe(undefined); + expect(Q.defer().reject()).toBe(undefined); }); }); @@ -138,7 +138,7 @@ describe("always next tick", function (done) { it("generated by `resolve`", function (done) { var turn = 0; Q().then(function () { - expect(turn).is(1); + expect(turn).toBe(1); }).done(done, done); turn++; }); @@ -146,9 +146,9 @@ describe("always next tick", function (done) { it("generated by `reject`", function (done) { var turn = 0; var promise = Q.reject().then(function () { - expect(true).is(false); + expect(true).toBe(false); }, function () { - expect(turn).is(1); + expect(turn).toBe(1); }).done(done, done); turn++; }); @@ -164,7 +164,7 @@ describe("promises for objects", function () { deferred.resolve({a: 1}); deferred.promise.get("a") .then(function (a) { - expect(a).is(1); + expect(a).toBe(1); }).done(done, done); }); @@ -175,9 +175,9 @@ describe("promises for objects", function () { }) .get("a") .then(function () { - expect("be").is("not to be"); + expect("be").toBe("not to be"); }, function (_exception) { - expect(_exception).is(exception); + expect(_exception).toBe(exception); }) .done(done, done); }); @@ -193,9 +193,10 @@ describe("promises for objects", function () { return 1 + value; } }; + Q(subject).invoke("a", 1).then(function (two) { - expect(subject._a).is(1); - expect(two).is(2); + expect(subject._a).toBe(1); + expect(two).toBe(2); }).done(done, done); }); @@ -216,8 +217,8 @@ describe("promises for objects", function () { }; Q(subject).invoke("bar", 1, 2) .then(function (two) { - expect(foo).is(1); - expect(two).is(2); + expect(foo).toBe(1); + expect(two).toBe(2); }) .done(done, done); }); @@ -227,7 +228,7 @@ describe("promises for objects", function () { Q(subject) .invoke("foo") .then(function () { - expect("here").is("not here"); + expect("here").toBe("not here"); }, function () { }) .done(done, done); @@ -237,7 +238,7 @@ describe("promises for objects", function () { Q() .invoke("foo") .then(function () { - expect("here").is("not here"); + expect("here").toBe("not here"); }, function () { }) .done(done, done); @@ -257,7 +258,7 @@ describe("promises for objects", function () { Q(new Klass(10, 20)) .keys() .then(function (keys) { - expect(keys.sort()).equals(["a", "b"]); + expect(keys.sort()).toEqual(["a", "b"]); }) .done(done, done); }); @@ -269,7 +270,7 @@ describe("promises for objects", function () { describe("inspect", function () { it("for a fulfilled promise", function () { - expect(Q(10).inspect()).equals({ + expect(Q(10).inspect()).toEqual({ state: "fulfilled", value: 10 }); @@ -278,7 +279,7 @@ describe("inspect", function () { it("for a rejected promise", function () { var error = new Error("In your face."); var rejected = Q.reject(error); - expect(rejected.inspect()).equals({ + expect(rejected.inspect()).toEqual({ state: "rejected", reason: error }); @@ -286,7 +287,7 @@ describe("inspect", function () { it("for a pending, unresolved promise", function () { var pending = Q.defer().promise; - expect(pending.inspect()).equals({ state: "pending" }); + expect(pending.inspect()).toEqual({ state: "pending" }); }); it("for a promise resolved to a rejected promise", function () { @@ -295,7 +296,7 @@ describe("inspect", function () { var rejected = Q.reject(error); deferred.resolve(rejected); - expect(deferred.promise.inspect()).equals({ + expect(deferred.promise.inspect()).toEqual({ state: "rejected", reason: error }); @@ -306,7 +307,7 @@ describe("inspect", function () { var fulfilled = Q(10); deferred.resolve(fulfilled); - expect(deferred.promise.inspect()).equals({ + expect(deferred.promise.inspect()).toEqual({ state: "fulfilled", value: 10 }); @@ -317,7 +318,7 @@ describe("inspect", function () { var b = Q.defer(); a.resolve(b.promise); - expect(a.promise.inspect()).equals({ state: "pending" }); + expect(a.promise.inspect()).toEqual({ state: "pending" }); }); }); @@ -331,7 +332,7 @@ describe("promises for functions", function () { }) .apply(void 0, [1, 2, 3]) .then(function (sum) { - expect(sum).is(6); + expect(sum).toBe(6); }) .done(done, done); }); @@ -344,7 +345,7 @@ describe("promises for functions", function () { }) .call(void 0, 1, 2, 3) .then(function (sum) { - expect(sum).is(6); + expect(sum).toBe(6); }) .done(done, done); }); @@ -358,7 +359,7 @@ describe("promises for functions", function () { })) (2, 1) .then(function (difference) { - expect(difference).is(1); + expect(difference).toBe(1); }) .done(done, done); }); @@ -369,7 +370,7 @@ describe("promises for functions", function () { }, 2) (3) .then(function (product) { - expect(product).is(6); + expect(product).toBe(6); }) .done(done, done); }); @@ -381,7 +382,7 @@ describe("promises for functions", function () { }); bound() .then(function (_result) { - expect(_result).is(result); + expect(_result).toBe(result); }) .done(done, done); }); @@ -393,9 +394,9 @@ describe("promises for functions", function () { }); bound() .then(function () { - expect("flying pigs").is("swillin' pigs"); + expect("flying pigs").toBe("swillin' pigs"); }, function (_exception) { - expect(_exception).is(exception); + expect(_exception).toBe(exception); }) .done(done, done); }); @@ -403,8 +404,8 @@ describe("promises for functions", function () { it("passes arguments through", function (done) { var x = {}, y = {}; var bound = Q.fbind(function (a, b) { - expect(a).is(x); - expect(b).is(y); + expect(a).toBe(x); + expect(b).toBe(y); }); bound(x, y).done(done, done); }); @@ -412,8 +413,8 @@ describe("promises for functions", function () { it("passes and also partially applies arguments", function (done) { var x = {}, y = {}; var bound = Q.fbind(function (a, b) { - expect(a).is(x); - expect(b).is(y); + expect(a).toBe(x); + expect(b).toBe(y); }, x); bound(y).done(done, done); }); @@ -421,7 +422,7 @@ describe("promises for functions", function () { it("doesn't bind `this`", function (done) { var theThis = { me: "this" }; var bound = Q.fbind(function () { - expect(this).is(theThis); + expect(this).toBe(theThis); }); bound.call(theThis) .done(done, done); @@ -439,7 +440,7 @@ describe("promises for functions", function () { }) }; return object.add(30, 40).then(function (sum) { - expect(sum).is(100); + expect(sum).toBe(100); }); }); @@ -453,7 +454,7 @@ describe("promises for functions", function () { }).bind() (2, 1) .then(function (difference) { - expect(difference).is(1); + expect(difference).toBe(1); }) .done(done, done); }); @@ -464,7 +465,7 @@ describe("promises for functions", function () { }).bind(null, 2) (3) .then(function (product) { - expect(product).is(6); + expect(product).toBe(6); }) .done(done, done); }); @@ -476,7 +477,7 @@ describe("promises for functions", function () { }).bind(); bound() .then(function (_result) { - expect(_result).is(result); + expect(_result).toBe(result); }) .done(done, done); }); @@ -488,9 +489,9 @@ describe("promises for functions", function () { }).bind(); bound() .then(function () { - expect("flying pigs").is("swillin' pigs"); + expect("flying pigs").toBe("swillin' pigs"); }, function (_exception) { - expect(_exception).is(exception); + expect(_exception).toBe(exception); }) .done(done, done); }); @@ -498,8 +499,8 @@ describe("promises for functions", function () { it("passes arguments through", function (done) { var x = {}, y = {}; var bound = Q(function (a, b) { - expect(a).is(x); - expect(b).is(y); + expect(a).toBe(x); + expect(b).toBe(y); }).bind(); bound(x, y).done(done, done); }); @@ -507,8 +508,8 @@ describe("promises for functions", function () { it("passes and also partially applies arguments", function (done) { var x = {}, y = {}; var bound = Q(function (a, b) { - expect(a).is(x); - expect(b).is(y); + expect(a).toBe(x); + expect(b).toBe(y); }).bind(null, x); bound(y).done(done, done); }); @@ -520,32 +521,32 @@ describe("promise states", function () { it("of fulfillment", function () { var promise = Q(10); - expect(promise.isFulfilled()).is(true); - expect(promise.isRejected()).is(false); - expect(promise.isPending()).is(false); + expect(promise.isFulfilled()).toBe(true); + expect(promise.isRejected()).toBe(false); + expect(promise.isPending()).toBe(false); }); it("of rejection", function () { var error = new Error("Oh, snap."); var promise = Q.reject(error); - expect(promise.isFulfilled()).is(false); - expect(promise.isRejected()).is(true); - expect(promise.isPending()).is(false); + expect(promise.isFulfilled()).toBe(false); + expect(promise.isRejected()).toBe(true); + expect(promise.isPending()).toBe(false); }); it("of rejection with a falsy value", function () { var promise = Q.reject(undefined); - expect(promise.isFulfilled()).is(false); - expect(promise.isRejected()).is(true); - expect(promise.isPending()).is(false); + expect(promise.isFulfilled()).toBe(false); + expect(promise.isRejected()).toBe(true); + expect(promise.isPending()).toBe(false); }); it("of deferred", function () { var deferred = Q.defer(); var promise = deferred.promise; - expect(promise.isFulfilled()).is(false); - expect(promise.isRejected()).is(false); - expect(promise.isPending()).is(true); + expect(promise.isFulfilled()).toBe(false); + expect(promise.isRejected()).toBe(false); + expect(promise.isPending()).toBe(true); }); it("of deferred rejection", function () { @@ -553,18 +554,18 @@ describe("promise states", function () { var rejection = Q.reject(new Error("Rejected!")); deferred.resolve(rejection); var promise = deferred.promise; - expect(promise.isFulfilled()).is(false); - expect(promise.isRejected()).is(true); - expect(promise.isPending()).is(false); + expect(promise.isFulfilled()).toBe(false); + expect(promise.isRejected()).toBe(true); + expect(promise.isPending()).toBe(false); }); it("of deferred fulfillment", function () { var deferred = Q.defer(); deferred.resolve(10); var promise = deferred.promise; - expect(promise.isFulfilled()).is(true); - expect(promise.isRejected()).is(false); - expect(promise.isPending()).is(false); + expect(promise.isFulfilled()).toBe(true); + expect(promise.isRejected()).toBe(false); + expect(promise.isPending()).toBe(false); }); it("of deferred deferred", function () { @@ -572,9 +573,9 @@ describe("promise states", function () { var b = Q.defer(); a.resolve(b.promise); var promise = a.promise; - expect(promise.isFulfilled()).is(false); - expect(promise.isRejected()).is(false); - expect(promise.isPending()).is(true); + expect(promise.isFulfilled()).toBe(false); + expect(promise.isRejected()).toBe(false); + expect(promise.isPending()).toBe(true); }); it("of isFulfilled side effects", function (done) { @@ -584,8 +585,8 @@ describe("promise states", function () { var parentPromise = deferred.promise; var childPromise = parentPromise.then(function () { - expect(parentPromise.isFulfilled()).is(true); - expect(childPromise.isFulfilled()).is(false); + expect(parentPromise.isFulfilled()).toBe(true); + expect(childPromise.isFulfilled()).toBe(false); return parentPromise.then(function (value) { asap(finish); @@ -596,10 +597,10 @@ describe("promise states", function () { deferred.resolve(1); function finish() { - expect(childPromise.isPending()).is(false); - expect(childPromise.isRejected()).is(false); - expect(childPromise.isFulfilled()).is(true); - expect(childPromise.inspect().value).is(2); + expect(childPromise.isPending()).toBe(false); + expect(childPromise.isRejected()).toBe(false); + expect(childPromise.isFulfilled()).toBe(true); + expect(childPromise.inspect().value).toBe(2); done(); } }); @@ -612,7 +613,7 @@ describe("propagation", function () { Q(10) .then() .then(function (ten) { - expect(ten).is(10); + expect(ten).toBe(10); }) .done(done, done); }); @@ -623,7 +624,7 @@ describe("propagation", function () { return ten + 10; }) .then(function (twen) { - expect(twen).is(20); + expect(twen).toBe(20); }) .done(done, done); }); @@ -632,11 +633,11 @@ describe("propagation", function () { var error = new Error("Bah!"); Q.reject(error) .then(null, function (_error) { - expect(_error).is(error); + expect(_error).toBe(error); return 10; }) .then(function (value) { - expect(value).is(10); + expect(value).toBe(10); }) .done(done, done); }); @@ -646,7 +647,7 @@ describe("propagation", function () { Q.reject(error) .then() .then(null, function (_error) { - expect(_error).is(error); + expect(_error).toBe(error); }) .done(done, done); }); @@ -659,7 +660,7 @@ describe("propagation", function () { throw nextError; }) .then(null, function (_error) { - expect(_error).is(nextError); + expect(_error).toBe(nextError); }) .done(done, done); }); @@ -670,7 +671,7 @@ describe("propagation", function () { a.resolve(b.promise); b.resolve(10); a.promise.then(function (eh) { - expect(eh).is(10); + expect(eh).toBe(10); }) .done(done, done); }); @@ -681,7 +682,7 @@ describe("all", function () { it("fulfills when passed an empty array", function (done) { Q.all([]) .then(function (values) { - expect(values).equals([]); + expect(values).toEqual([]); }) .done(done, done); }); @@ -696,7 +697,7 @@ describe("all", function () { Q.delay(250) .then(function () { - expect(promise.isRejected()).is(true); + expect(promise.isRejected()).toBe(true); }) .timeout(1000) .done(done, done); @@ -708,14 +709,14 @@ describe("all", function () { Q.all([normal, foreign]) .then(function (result) { - expect(result).equals([1, 2]); + expect(result).toEqual([1, 2]); }) .done(done, done); }); it("calls thenables lazilly", function (done) { var promise = Q({then: function () { - expect(true).is(false); + expect(true).toBe(false); }}) Q.delay(10) .done(done, done); @@ -731,7 +732,7 @@ describe("all", function () { toResolve.resolve(2); return promise.then(function (result) { - expect(result).equals([0, , 2]); + expect(result).toEqual([0, , 2]); }) .done(done, done); }); @@ -740,8 +741,8 @@ describe("all", function () { var input = [Q(0), Q(1)]; return Q.all(input).then(function (result) { - expect(result).not.equals(input); - expect(input).not.equals([0, 1]); + expect(result).not.toEqual(input); + expect(input).not.toEqual([0, 1]); }) .done(done, done); }); @@ -753,7 +754,7 @@ describe("allSettled", function () { it("works on an empty array", function (done) { Q.allSettled([]) .then(function (snapshots) { - expect(snapshots).equals([]); + expect(snapshots).toEqual([]); }) .done(done, done); }); @@ -761,7 +762,7 @@ describe("allSettled", function () { it("deals with a mix of non-promises and promises", function (done) { Q.allSettled([1, Q(2), Q.reject(3)]) .then(function (snapshots) { - expect(snapshots).equals([ + expect(snapshots).toEqual([ { state: "fulfilled", value: 1 }, { state: "fulfilled", value: 2 }, { state: "rejected", reason: 3 } @@ -789,8 +790,8 @@ describe("allSettled", function () { Q.allSettled(promises) .then(function () { - expect(fulfilled).is(true); - expect(rejected).is(true); + expect(fulfilled).toBe(true); + expect(rejected).toBe(true); }) .done(done, done); }); @@ -800,8 +801,8 @@ describe("allSettled", function () { Q.allSettled(input) .then(function (snapshots) { - expect(snapshots).not.is(input); - expect(snapshots).equals([ + expect(snapshots).not.toBe(input); + expect(snapshots).toEqual([ { state: "fulfilled", value: 1 }, { state: "fulfilled", value: 2 }, { state: "rejected", reason: 3 } @@ -816,7 +817,7 @@ describe("spread", function () { it("spreads values across arguments", function (done) { Q.spread([1, 2, 3], function (a, b) { - expect(b).is(2); + expect(b).toBe(2); }) .done(done, done); }); @@ -824,7 +825,7 @@ describe("spread", function () { it("spreads promises for arrays across arguments", function (done) { return Q([Q(10)]) .spread(function (value) { - expect(value).is(10); + expect(value).toBe(10); }) .done(done, done); }); @@ -836,8 +837,8 @@ describe("spread", function () { Q.spread( [deferredA.promise, deferredB.promise], function (a, b) { - expect(a).is(10); - expect(b).is(20); + expect(a).toBe(10); + expect(b).toBe(20); } ) .done(done, done); @@ -855,10 +856,10 @@ describe("spread", function () { var err = new Error(); Q.spread([Q(10), Q.reject(err)], function () { - expect(true).is(false); + expect(true).toBe(false); }, function (actual) { - expect(actual).is(err); + expect(actual).toBe(err); } ) .done(done, done); @@ -881,7 +882,7 @@ describe("finally", function (done) { called = true; }) .then(function () { - expect(called).is(true); + expect(called).toBe(true); }) .done(done, done); }); @@ -892,7 +893,7 @@ describe("finally", function (done) { return "bar"; }) .then(function (result) { - expect(result).is("foo"); + expect(result).toBe("foo"); }) .done(done, done); }); @@ -909,8 +910,8 @@ describe("finally", function (done) { return promise; }) .then(function (result) { - expect(promise.isPending()).is(false); - expect(result).is("foo"); + expect(promise.isPending()).toBe(false); + expect(result).toBe("foo"); }) .done(done, done); }); @@ -924,10 +925,10 @@ describe("finally", function (done) { return Q.reject(exception1); }) .then(function () { - expect(false).is(true); + expect(false).toBe(true); }, function (exception) { - expect(exception).is(exception1); + expect(exception).toBe(exception1); }) .done(done, done); }); @@ -942,10 +943,10 @@ describe("finally", function (done) { throw exception1; }) .then(function () { - expect(false).is(true); + expect(false).toBe(true); }, function (exception) { - expect(exception).is(exception1); + expect(exception).toBe(exception1); }) .done(done, done); }); @@ -963,9 +964,9 @@ describe("finally", function (done) { called = true; }) .then(function () { - expect(called).is(true); + expect(called).toBe(true); }, function () { - expect(called).is(true); + expect(called).toBe(true); }) .done(done, done); }); @@ -976,9 +977,9 @@ describe("finally", function (done) { return "bar"; }) .then(function () { - expect(false).is(true); + expect(false).toBe(true); }, function (exception) { - expect(exception).is(exception1); + expect(exception).toBe(exception1); }) .done(done, done); }); @@ -995,10 +996,10 @@ describe("finally", function (done) { return promise; }) .then(function () { - expect(false).is(true); + expect(false).toBe(true); }, function (exception) { - expect(exception).is(exception1); - expect(promise.isPending()).is(false); + expect(exception).toBe(exception1); + expect(promise.isPending()).toBe(false); }) .done(done, done); }); @@ -1013,9 +1014,9 @@ describe("finally", function (done) { return Q.reject(exception2); }) .then(function () { - expect(false).is(true); + expect(false).toBe(true); }, function (exception) { - expect(exception).is(exception2); + expect(exception).toBe(exception2); }) .done(done, done); }); @@ -1032,9 +1033,9 @@ describe("finally", function (done) { throw exception2; }) .then(function () { - expect(false).is(true); + expect(false).toBe(true); }, function (exception) { - expect(exception).is(exception2); + expect(exception).toBe(exception2); }) .done(done, done); }); @@ -1063,8 +1064,8 @@ describe("done", function () { promise.catch(function () { }) .finally(function () { - expect(called).is(true); - expect(returnValue).is(undefined); + expect(called).toBe(true); + expect(returnValue).toBe(undefined); }) .done(done, done); }); @@ -1074,9 +1075,9 @@ describe("done", function () { it("should rethrow that error in the next turn and return nothing", function (done) { Q.onerror = function (error) { - expect(turn).is(1); - expect(error).is("foo"); - expect(returnValue).is(undefined); + expect(turn).toBe(1); + expect(error).toBe("foo"); + expect(returnValue).toBe(undefined); deferred.resolve(); }; @@ -1121,8 +1122,8 @@ describe("done", function () { .catch(function () { }) .finally(function () { - expect(called).is(true); - expect(returnValue).is(undefined); + expect(called).toBe(true); + expect(returnValue).toBe(undefined); }) .done(done, done); }); @@ -1133,9 +1134,9 @@ describe("done", function () { it("should rethrow that error in the next turn and return nothing", function (done) { Q.onerror = function (error) { - expect(turn).is(1); - expect(error).is("foo"); - expect(returnValue).is(undefined); + expect(turn).toBe(1); + expect(error).toBe("foo"); + expect(returnValue).toBe(undefined); deferred.resolve(); }; @@ -1162,9 +1163,9 @@ describe("done", function () { it("should throw the original error in the next turn", function (done) { Q.onerror = function (error) { - expect(turn).is(1); - expect(error).is("bar"); - expect(returnValue).is(undefined); + expect(turn).toBe(1); + expect(error).toBe("bar"); + expect(returnValue).toBe(undefined); deferred.resolve(); }; @@ -1201,7 +1202,7 @@ describe("timeout", function () { }) .timeout(200) .then(undefined, function (error) { - expect(error).is(goodError); + expect(error).toBe(goodError); }) .done(done, done); }); @@ -1211,10 +1212,10 @@ describe("timeout", function () { .timeout(10) .then( function () { - expect(true).is(false); + expect(true).toBe(false); }, function (error) { - expect(/time/i.test(error.message)).is(true); + expect(/time/i.test(error.message)).toBe(true); } ) .done(done, done); @@ -1225,10 +1226,10 @@ describe("timeout", function () { .timeout(10, "custom") .then( function () { - expect(true).is(false); + expect(true).toBe(false); }, function (error) { - expect(/custom/i.test(error.message)).is(true); + expect(/custom/i.test(error.message)).toBe(true); } ) .done(done, done); @@ -1242,7 +1243,7 @@ describe("delay", function () { var promise = Q(5).delay(50); setTimeout(function () { - expect(promise.isPending()).is(true); + expect(promise.isPending()).toBe(true); }, 40); promise.then(function () { @@ -1255,7 +1256,7 @@ describe("delay", function () { Q.delay(20) .then(function () { - expect(promise.isPending()).is(false); + expect(promise.isPending()).toBe(false); }) .done(done, done); }); @@ -1264,7 +1265,7 @@ describe("delay", function () { var promise = Q.delay(50); setTimeout(function () { - expect(promise.isPending()).is(true); + expect(promise.isPending()).toBe(true); }, 40); promise.done(done, done); @@ -1274,11 +1275,11 @@ describe("delay", function () { var promise = Q.delay("what", 50); setTimeout(function () { - expect(promise.isPending()).is(true); + expect(promise.isPending()).toBe(true); }, 40); promise.then(function (value) { - expect(value).is("what"); + expect(value).toBe("what"); }) .done(done, done); }); @@ -1288,12 +1289,12 @@ describe("delay", function () { var promise2 = promise1.delay(30); setTimeout(function () { - expect(promise1.isPending()).is(false); - expect(promise2.isPending()).is(true); + expect(promise1.isPending()).toBe(false); + expect(promise2.isPending()).toBe(true); }, 40); promise2.then(function (value) { - expect(value).is("what"); + expect(value).toBe("what"); }) .done(done, done); }); @@ -1312,8 +1313,8 @@ describe("thenResolve", function () { }) .thenResolve("foo") .then(function (val) { - expect(waited).is(true); - expect(val).is("foo"); + expect(waited).toBe(true); + expect(val).toBe("foo"); }) .done(done, done); }); @@ -1325,10 +1326,10 @@ describe("thenResolve", function () { .thenResolve("foo") .then( function () { - expect(true).is(false); + expect(true).toBe(false); }, function (reason) { - expect(reason).is("boo"); + expect(reason).toBe("boo"); } ) .done(done, done); @@ -1349,8 +1350,8 @@ describe("thenResolve", function () { }) .thenResolve(Q("foo")) .then(function (val) { - expect(waited).is(true); - expect(val).is("foo"); + expect(waited).toBe(true); + expect(val).toBe("foo"); }) .done(done, done); }); @@ -1372,11 +1373,11 @@ describe("thenReject", function () { .thenReject("foo") .then( function () { - expect(true).is(false); + expect(true).toBe(false); }, function (reason) { - expect(waited).is(true); - expect(reason).is("foo"); + expect(waited).toBe(true); + expect(reason).toBe("foo"); } ) .done(done, done); @@ -1388,10 +1389,10 @@ describe("thenReject", function () { .thenResolve("foo") .then( function () { - expect(true).is(false); + expect(true).toBe(false); }, function (reason) { - expect(reason).is("boo"); + expect(reason).toBe("boo"); } ) .done(done, done); @@ -1410,10 +1411,10 @@ describe("thenables", function () { } }) .then(function (ten) { - expect(ten).is(10); + expect(ten).toBe(10); }) .then(function (undefined) { - expect(undefined).is(void 0); + expect(undefined).toBe(void 0); }) .done(done, done); }); @@ -1426,7 +1427,7 @@ describe("thenables", function () { }) .get(0) .then(function (ten) { - expect(ten).is(10); + expect(ten).toBe(10); }) .done(done, done); }); @@ -1438,7 +1439,7 @@ describe("thenables", function () { }} ]) .then(function (snapshots) { - expect(snapshots).equals([{ state: "fulfilled", value: 10 }]); + expect(snapshots).toEqual([{ state: "fulfilled", value: 10 }]); }) .done(done, done); }); @@ -1452,7 +1453,7 @@ describe("thenables", function () { }} ]) .then(function (snapshots) { - expect(snapshots).equals([{ state: "fulfilled", value: 10 }]); + expect(snapshots).toEqual([{ state: "fulfilled", value: 10 }]); }) .done(done, done); }); @@ -1462,44 +1463,44 @@ describe("thenables", function () { describe("isPromise", function () { it("returns true if passed a promise", function () { - expect(Q.isPromise(Q(10))).is(true); + expect(Q.isPromise(Q(10))).toBe(true); }); it("returns false if not passed a promise", function () { - expect(Q.isPromise(undefined)).is(false); - expect(Q.isPromise(null)).is(false); - expect(Q.isPromise(10)).is(false); - expect(Q.isPromise("str")).is(false); - expect(Q.isPromise("")).is(false); - expect(Q.isPromise(true)).is(false); - expect(Q.isPromise(false)).is(false); - expect(Q.isPromise({})).is(false); + expect(Q.isPromise(undefined)).toBe(false); + expect(Q.isPromise(null)).toBe(false); + expect(Q.isPromise(10)).toBe(false); + expect(Q.isPromise("str")).toBe(false); + expect(Q.isPromise("")).toBe(false); + expect(Q.isPromise(true)).toBe(false); + expect(Q.isPromise(false)).toBe(false); + expect(Q.isPromise({})).toBe(false); expect(Q.isPromise({ then: function () {} - })).is(false); - expect(Q.isPromise(function () {})).is(false); + })).toBe(false); + expect(Q.isPromise(function () {})).toBe(false); }); }); xdescribe("isThenable", function () { it("returns true if passed a promise like object", function () { - expect(Q.isThenable(Q(10))).is(true); + expect(Q.isThenable(Q(10))).toBe(true); expect(Q.isThenable({ then: function () {} - })).is(true); + })).toBe(true); }); it("returns false if not passed a promise like object", function () { - expect(Q.isThenable(undefined)).is(false); - expect(Q.isThenable(null)).is(false); - expect(Q.isThenable(10)).is(false); - expect(Q.isThenable("str")).is(false); - expect(Q.isThenable("")).is(false); - expect(Q.isThenable(true)).is(false); - expect(Q.isThenable(false)).is(false); - expect(Q.isThenable({})).is(false); - expect(Q.isThenable(function () {})).is(false); + expect(Q.isThenable(undefined)).toBe(false); + expect(Q.isThenable(null)).toBe(false); + expect(Q.isThenable(10)).toBe(false); + expect(Q.isThenable("str")).toBe(false); + expect(Q.isThenable("")).toBe(false); + expect(Q.isThenable(true)).toBe(false); + expect(Q.isThenable(false)).toBe(false); + expect(Q.isThenable({})).toBe(false); + expect(Q.isThenable(function () {})).toBe(false); }); }); @@ -1511,7 +1512,7 @@ describe("promised", function () { return a + b; }); sum(Q(4), Q(5)).then(function (sum) { - expect(sum).is(9); + expect(sum).toBe(9); }) .done(done, done); }); @@ -1521,7 +1522,7 @@ describe("promised", function () { return this + a; }); inc.call(Q(4), Q(5)).then(function (sum) { - expect(sum).is(9); + expect(sum).toBe(9); }) .done(done, done); }); @@ -1531,9 +1532,9 @@ describe("promised", function () { return a + b; }); sum(Q.reject(exception), Q(4)).then(function () { - expect(4).is(42); + expect(4).toBe(42); }, function (_exception) { - expect(_exception).is(exception); + expect(_exception).toBe(exception); }) .done(done, done); }); @@ -1543,9 +1544,9 @@ describe("promised", function () { return this + a; }); inc.call(Q.reject(exception), Q(4)).then(function () { - expect(4).is(42); + expect(4).toBe(42); }, function (_exception) { - expect(_exception).is(exception); + expect(_exception).toBe(exception); }) .done(done, done); }); @@ -1566,7 +1567,7 @@ it("computes a large sum without blowing the stack", function () { }, Q(0)); return result.then(function (value) { - expect(value).is(iters * (iters + 1) / 2); + expect(value).toBe(iters * (iters + 1) / 2); }); }); diff --git a/test/queue.js b/test/queue-test.js similarity index 87% rename from test/queue.js rename to test/queue-test.js index 26ed6155..85145aa4 100644 --- a/test/queue.js +++ b/test/queue-test.js @@ -8,14 +8,14 @@ describe("queue", function () { var queue = Queue(); queue.put(1); return queue.get().then(function (value) { - expect(value).is(1); + expect(value).toBe(1); }); }); it("should dequeue then enqueue", function () { var queue = Queue(); var promise = queue.get().then(function (value) { - expect(value).is(1); + expect(value).toBe(1); }); queue.put(1); return promise; @@ -44,19 +44,19 @@ describe("queue", function () { return Q.try(function () { return queue.get() .then(function (value) { - expect(value).is(1); + expect(value).toBe(1); }); }) .then(function () { return queue.get() .then(function (value) { - expect(value).is(2); + expect(value).toBe(2); }); }) .then(function () { return queue.get() .then(function (value) { - expect(value).is(3); + expect(value).toBe(3); }); }) @@ -85,15 +85,15 @@ describe("queue", function () { return Q.all([ queue.get() .then(function (value) { - expect(value).is(1); + expect(value).toBe(1); }), queue.get() .then(function (value) { - expect(value).is(2); + expect(value).toBe(2); }), queue.get() .then(function (value) { - expect(value).is(3); + expect(value).toBe(3); }) ]); }); diff --git a/test/traces.js b/test/traces-test.js similarity index 91% rename from test/traces.js rename to test/traces-test.js index 18f7a5c9..dd1fb86d 100644 --- a/test/traces.js +++ b/test/traces-test.js @@ -27,8 +27,8 @@ describe("stack trace formatting", function () { var b = captured.get(); Q.spread([a, b], function (a, b) { - expect(a).not.is(undefined); - expect(a).is(b); + expect(a).not.toBe(undefined); + expect(a).toBe(b); }) .done(done, done); });