From 3ac17d0075281f39dc3df0bfa53158ecdd5ff65e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yves=20G=C3=A9rardy?= Date: Thu, 30 Nov 2017 23:49:34 +0100 Subject: [PATCH] ospec: tests and docs for o.report --- ospec/README.md | 11 ++++++++++- ospec/tests/test-ospec.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/ospec/README.md b/ospec/README.md index b3a3ff76..9b0b416c 100644 --- a/ospec/README.md +++ b/ospec/README.md @@ -311,7 +311,9 @@ ospec will automatically evaluate all `*.js` files in any folder named `/tests`. Ospec doesn't work when installed globally. Using global scripts is generally a bad idea since you can end up with different, incompatible versions of the same package installed locally and globally. -To work around this limitation, you can use [`npm-run`](https://www.npmjs.com/package/npm-run) which enables one to run the binaries of locally installed packages. +If you're using a recent version of npm (v5+), you can use run `npx ospec` from your project folder. + +Otherwise, to work around this limitation, you can use [`npm-run`](https://www.npmjs.com/package/npm-run) which enables one to run the binaries of locally installed packages. ``` npm install npm-run -g @@ -449,6 +451,13 @@ If running in Node.js, ospec will call `process.exit` after reporting results by default. If you specify a reporter, ospec will not do this and allow your reporter to respond to results in its own way. + +--- + +### Number o.report(results) + +The default reporter used by `o.run()` when none are provided. Returns the number of failures, doesn't exit Node.js by itself. It expects an array of [test result data](#result-data) as argument. + --- ### Function o.new() diff --git a/ospec/tests/test-ospec.js b/ospec/tests/test-ospec.js index 86218c83..526671c6 100644 --- a/ospec/tests/test-ospec.js +++ b/ospec/tests/test-ospec.js @@ -49,6 +49,43 @@ new function(o) { done() }) }) + o("o.report() returns the number of failures", function () { + var log = console.log, error = console.error + console.log = o.spy() + console.error = o.spy() + + function makeError(msg) {try{throw msg ? new Error(msg) : new Error} catch(e){return e}} + try { + var errCount = o.report([{pass: true}, {pass: true}]) + + o(errCount).equals(0) + o(console.log.callCount).equals(1) + o(console.error.callCount).equals(0) + + errCount = o.report([ + {pass: false, error: makeError("hey"), message: "hey"} + ]) + + o(errCount).equals(1) + o(console.log.callCount).equals(2) + o(console.error.callCount).equals(1) + + errCount = o.report([ + {pass: false, error: makeError("hey"), message: "hey"}, + {pass: true}, + {pass: false, error: makeError("ho"), message: "ho"} + ]) + + o(errCount).equals(2) + o(console.log.callCount).equals(3) + o(console.error.callCount).equals(3) + } catch (e) { + o(1).equals(0)("Error while testing the reporter") + } + + console.log = log + console.error = error + }) }) }(o)