Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ospec

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ospec - npm Package Compare versions

Comparing version 1.2.3 to 1.3.0

LICENSE

54

ospec.js

@@ -0,10 +1,19 @@

/* eslint-disable no-bitwise, no-process-exit */
"use strict"
module.exports = new function init() {
var spec = {}, subjects = [], results = [], only = null, ctx = spec, start, stack = 0, hasProcess = typeof process === "object"
module.exports = new function init(name) {
var spec = {}, subjects = [], results, only = null, ctx = spec, start, stack = 0, nextTickish, hasProcess = typeof process === "object", hasOwn = ({}).hasOwnProperty
if (name != null) spec[name] = ctx = {}
function o(subject, predicate) {
subject = unique(subject, predicate)
ctx[subject] = predicate
if (predicate === undefined) return new Assert(subject)
if (predicate === undefined) {
if (results == null) throw new Error("Assertions should not occur outside test definitions")
return new Assert(subject)
}
else if (results == null) {
ctx[unique(subject)] = predicate
} else {
throw new Error("Test definition shouldn't be nested. To group tests use `o.spec()`")
}
}

@@ -18,8 +27,10 @@ o.before = hook("__before")

var parent = ctx
subject = unique(subject, predicate)
ctx = ctx[subject] = {}
ctx = ctx[unique(subject)] = {}
predicate()
ctx = parent
}
o.only = function(subject, predicate) {o(subject, only = predicate)}
o.only = function(subject, predicate, silent) {
if (!silent) console.log(highlight("/!\\ WARNING /!\\ o.only() mode"))
o(subject, only = predicate)
}
o.spy = function(fn) {

@@ -43,2 +54,3 @@ var spy = function() {

o.run = function() {
results = []
start = new Date

@@ -74,3 +86,2 @@ test(spec, [], [], report)

function next() {
stack++
if (cursor === fns.length) return

@@ -83,3 +94,3 @@

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")

@@ -113,4 +124,3 @@ try {

fn()
if (stack < 5000) next()
else (hasProcess ? process.nextTick : setTimeout)(next, stack = 0)
nextTickish(next)
}

@@ -120,6 +130,6 @@ }

}
function unique(subject, predicate) {
if (ctx.hasOwnProperty(subject) && predicate) {
console.warn("A test named `" + subject + "` was already defined")
subject = subject + "*"
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 += "*"
}

@@ -164,3 +174,3 @@ return subject

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
}

@@ -224,2 +234,3 @@ return true

console.log(
(name ? name + ": " : "") +
results.length + " assertions completed in " + Math.round(new Date - start) + "ms, " +

@@ -231,3 +242,12 @@ "of which " + results.filter(function(result){return result.error}).length + " failed"

if(hasProcess) {
nextTickish = process.nextTick
} else {
nextTickish = function fakeFastNextTick(next) {
if (stack++ < 5000) next()
else setTimeout(next, stack = 0)
}
}
return o
}
{
"name": "ospec",
"version": "1.2.3",
"version": "1.3.0",
"description": "Noiseless testing framework",

@@ -15,3 +15,3 @@ "main": "ospec.js",

},
"repository": "lhorie/mithril.js#rewrite"
"repository": "MithrilJS/mithril.js"
}

@@ -1,2 +0,3 @@

# ospec
ospec [![NPM Version](https://img.shields.io/npm/v/ospec.svg)](https://www.npmjs.com/package/ospec) [![NPM License](https://img.shields.io/npm/l/ospec.svg)](https://www.npmjs.com/package/ospec)
=====

@@ -7,5 +8,2 @@ [About](#about) | [Usage](#usage) | [API](#api) | [Goals](#goals)

Version: 1.2.3
License: MIT
## About

@@ -256,3 +254,3 @@

```javascript
var _o = o.new()
var _o = o.new('optional name')
_o("a test", function() {

@@ -283,17 +281,16 @@ _o(1).equals(1)

#### (Optionally) Install Globally
#### Direct use from the command line
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.
```
$ npm i -g ospec
$ ospec
npm install npm-run -g
```
#### (Optionally) Evaluate ES6+ code:
Then, from a project that has ospec installed as a (dev) dependency:
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-run ospec
```

@@ -305,3 +302,3 @@

*Square brackets denote optional arguments
Square brackets denote optional arguments

@@ -308,0 +305,0 @@ ### void o.spec(String title, Function tests)

@@ -15,3 +15,3 @@ "use strict"

o(2).equals(2)
})
}, true)
})

@@ -24,3 +24,3 @@

o.spec("sync", function() {
var a = 0, b = 0
var a = 0, b = 0, illegalAssertionThrows = false

@@ -33,3 +33,11 @@ o.before(function() {a = 1})

try {o("illegal assertion")} catch (e) {illegalAssertionThrows = true}
o("assertions", function() {
var nestedTestDeclarationThrows = false
try {o("illegal nested test", function(){})} catch (e) {nestedTestDeclarationThrows = true}
o(illegalAssertionThrows).equals(true)
o(nestedTestDeclarationThrows).equals(true)
var spy = o.spy()

@@ -49,3 +57,3 @@ spy(a)

o({}).notDeepEquals(undef1)
var sparse1 = [void 1, void 2, void 3]

@@ -62,3 +70,3 @@ delete sparse1[0]

monkeypatch2.field = 4
o(monkeypatch1).notDeepEquals([1, 2])

@@ -65,0 +73,0 @@ o(monkeypatch1).notDeepEquals(monkeypatch2)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc