Merge branch 'rewrite' into next-tick
This commit is contained in:
commit
6c5a7e6e62
44 changed files with 1507 additions and 317 deletions
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
Noiseless testing framework
|
||||
|
||||
Version: 1.2.2
|
||||
Version: 1.2.3
|
||||
License: MIT
|
||||
|
||||
## About
|
||||
|
|
@ -278,28 +278,19 @@ ospec will automatically evaluate all `*.js` files in any folder named `/tests`.
|
|||
$ npm test
|
||||
```
|
||||
|
||||
#### (Optionally) Install Globally
|
||||
#### Installing ospec globally
|
||||
|
||||
While it's recommended to install ospec locally to maintain reproducible environments, sometimes it may be deemed appropriate to install it globally. To do so, run this command:
|
||||
|
||||
```
|
||||
$ npm i -g ospec
|
||||
$ ospec
|
||||
```
|
||||
|
||||
#### (Optionally) Evaluate ES6+ code:
|
||||
|
||||
One way to accomplish this would be to include the 'babel-cli' module (`npm i babel-cli`)
|
||||
|
||||
(This would pre-suppose that you're already using babel in your project and thus have it configured to your liking).
|
||||
|
||||
```
|
||||
$ babel-node ospec
|
||||
npm install ospec -g
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## API
|
||||
|
||||
*Square brackets denote optional arguments
|
||||
Square brackets denote optional arguments
|
||||
|
||||
### void o.spec(String title, Function tests)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
"use strict"
|
||||
|
||||
module.exports = new function init() {
|
||||
var spec = {}, subjects = [], results = [], only = null, ctx = spec, start, stack = 0, nextTickish, hasProcess = typeof process === "object"
|
||||
var spec = {}, subjects = [], results = [], only = null, ctx = spec, start, stack = 0, nextTickish, hasProcess = typeof process === "object", hasOwn = ({}).hasOwnProperty
|
||||
|
||||
function o(subject, predicate) {
|
||||
ctx[subject] = predicate
|
||||
if (predicate === undefined) return new Assert(subject)
|
||||
ctx[unique(subject)] = predicate
|
||||
}
|
||||
o.before = hook("__before")
|
||||
o.after = hook("__after")
|
||||
|
|
@ -14,7 +14,7 @@ module.exports = new function init() {
|
|||
o.new = init
|
||||
o.spec = function(subject, predicate) {
|
||||
var parent = ctx
|
||||
ctx = ctx[subject] = {}
|
||||
ctx = ctx[unique(subject)] = {}
|
||||
predicate()
|
||||
ctx = parent
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ module.exports = new function init() {
|
|||
var timeout = 0, delay = 200, s = new Date
|
||||
var isDone = false
|
||||
var body = fn.toString()
|
||||
var arg = (body.match(/\(([\w_$]+)/) || body.match(/([\w_$]+)\s*=>/) || []).pop()
|
||||
var arg = (body.match(/\(([\w$]+)/) || body.match(/([\w$]+)\s*=>/) || []).pop()
|
||||
if (body.indexOf(arg) === body.lastIndexOf(arg)) throw new Error("`" + arg + "()` should be called at least once")
|
||||
try {
|
||||
fn(function done() {
|
||||
|
|
@ -108,6 +108,13 @@ module.exports = new function init() {
|
|||
}
|
||||
}
|
||||
}
|
||||
function unique(subject) {
|
||||
if (hasOwn.call(ctx, subject)) {
|
||||
console.warn("A test or a spec named `" + subject + "` was already defined")
|
||||
while (hasOwn.call(ctx, subject)) subject += '*'
|
||||
}
|
||||
return subject
|
||||
}
|
||||
function hook(name) {
|
||||
return function(predicate) {
|
||||
if (ctx[name]) throw new Error("This hook should be defined outside of a loop or inside a nested test group:\n" + predicate)
|
||||
|
|
@ -144,7 +151,7 @@ module.exports = new function init() {
|
|||
var aKeys = Object.getOwnPropertyNames(a), bKeys = Object.getOwnPropertyNames(b)
|
||||
if (aKeys.length !== bKeys.length) return false
|
||||
for (var i = 0; i < aKeys.length; i++) {
|
||||
if (!b.hasOwnProperty(aKeys[i]) || !deepEqual(a[aKeys[i]], b[aKeys[i]])) return false
|
||||
if (!hasOwn.call(b, aKeys[i]) || !deepEqual(a[aKeys[i]], b[aKeys[i]])) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ospec",
|
||||
"version": "1.2.2",
|
||||
"version": "1.2.3",
|
||||
"description": "Noiseless testing framework",
|
||||
"main": "ospec.js",
|
||||
"directories": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue