tape-testcheck
Advanced tools
Comparing version 0.1.1 to 1.1.1
@@ -6,2 +6,3 @@ 'use strict'; | ||
}); | ||
exports['default'] = check; | ||
@@ -32,7 +33,4 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
*/ | ||
_tapeLibTest2['default'].prototype.check = function (generators, propertyFn, options, msg) { | ||
if (this._skip) { | ||
return this.end(); | ||
} | ||
function check(generators, propertyFn, options, msg) { | ||
if (typeof options === 'string') { | ||
@@ -43,27 +41,26 @@ msg = options; | ||
this.emit('prerun'); | ||
var result = _testcheck2['default'].check(_testcheck2['default'].property(generators, propertyFn), options); | ||
try { | ||
var result = _testcheck2['default'].check(_testcheck2['default'].property(generators, propertyFn), options); | ||
if (result.result === true) { | ||
this.pass(msg); | ||
} else { | ||
this.fail(msg, { | ||
expected: { result: true }, | ||
actual: result | ||
}); | ||
} | ||
} | ||
if (result.result === true) { | ||
this.pass(msg); | ||
} else { | ||
this.fail(msg, { | ||
expected: { result: true }, | ||
actual: result | ||
}); | ||
} | ||
} catch (err) { | ||
this.error(err); | ||
return; | ||
// Re-exported for convenience | ||
Object.defineProperty(exports, 'gen', { | ||
enumerable: true, | ||
get: function get() { | ||
return _testcheck.gen; | ||
} | ||
this.emit('run'); | ||
}; | ||
_tapeLibTest2['default'].prototype.gen = _testcheck2['default'].gen; | ||
_tapeLibTest2['default'].prototype.sample = _testcheck2['default'].sample; | ||
exports['default'] = _tape2['default']; | ||
module.exports = exports['default']; | ||
}); | ||
Object.defineProperty(exports, 'sample', { | ||
enumerable: true, | ||
get: function get() { | ||
return _testcheck.sample; | ||
} | ||
}); |
{ | ||
"name": "tape-testcheck", | ||
"version": "0.1.1", | ||
"version": "1.1.1", | ||
"description": "Use Testcheck with Tape test runner", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"prepublish": "npm run build", | ||
"build": "babel ./src/index.js --out-file ./dist/index.js", | ||
"build": "babel src --out-dir dist", | ||
"test": "babel-node ./node_modules/.bin/tape ./test/index.js" | ||
@@ -16,2 +16,6 @@ }, | ||
], | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"author": "npbee", | ||
@@ -25,2 +29,3 @@ "license": "MIT", | ||
"babel": "^5.8.23", | ||
"extend-tape": "^1.1.0", | ||
"sinon": "^1.17.1" | ||
@@ -27,0 +32,0 @@ }, |
# Tape Testcheck | ||
Use [Testcheck](https://github.com/leebyron/testcheck-js) with [Tape](https://github.com/substack/tape). | ||
[![Build Status](https://travis-ci.org/npbee/tape-testcheck.svg)](https://travis-ci.org/npbee/tape-testcheck) | ||
A [Tape extension](https://github.com/atabel/extend-tape) to use | ||
[Testcheck](https://github.com/leebyron/testcheck-js) with | ||
[Tape](https://github.com/substack/tape). | ||
## Usage | ||
This is a small library that simply adds a `check` method to Tape's `test` | ||
method. | ||
To have access to the `t.check` method, you need to extend tape with the exported | ||
`check` function. | ||
```javascript | ||
import tape from 'tape'; | ||
import addAssertions from 'extend-tape'; | ||
import check from 'tape-testcheck'; | ||
// Add the `check` assertion | ||
const test = addAssertions(tape, { check }); | ||
// Now you can test away | ||
test('Something', t => { | ||
t.check(...); | ||
}); | ||
``` | ||
For convenience, the `gen` and `sample` methods are re-exported for usage with | ||
your checks: | ||
```javascript | ||
import tape from 'tape'; | ||
import addAssertions from 'extend-tape'; | ||
import check, { gen, sample } from 'tape-testcheck'; | ||
``` | ||
### A basic test | ||
```javascript | ||
import test from 'tape-testcheck'; | ||
import tape from 'tape'; | ||
import addAssertions from 'extend-tape'; | ||
import check, { gen, sample } from 'tape-testcheck'; | ||
const test = addAssertions(tape, { check }); | ||
test('Something', t => { | ||
t.check( | ||
[t.gen.int], | ||
[gen.int], | ||
num => typeof num === 'number', | ||
@@ -32,8 +63,12 @@ 'it works!' | ||
```javascript | ||
import test from 'tape-testcheck'; | ||
import tape from 'tape'; | ||
import addAssertions from 'extend-tape'; | ||
import check, { gen, sample } from 'tape-testcheck'; | ||
const test = addAssertions(tape, { check }); | ||
test('Something', t => { | ||
// with options | ||
t.check( | ||
[t.gen.int], | ||
[gen.int], | ||
num => typeof num === 'number', | ||
@@ -54,8 +89,12 @@ { times: 10 }, | ||
```javascript | ||
import test from 'tape-testcheck'; | ||
import tape from 'tape'; | ||
import addAssertions from 'extend-tape'; | ||
import check, { gen, sample } from 'tape-testcheck'; | ||
const test = addAssertions(tape, { check }); | ||
test('Something', t => { | ||
t.check( | ||
[t.gen.int], | ||
[gen.int], | ||
num => typeof num === 'string', | ||
@@ -92,10 +131,1 @@ 'it fails!' | ||
`options`. The `msg` will be passed to the `t.pass` and `t.fail` methods. | ||
### t.gen | ||
Alias for `testcheck.gen`. | ||
### t.sample | ||
Alias for `testcheck.sample` |
@@ -5,2 +5,3 @@ import Test from 'tape/lib/test'; | ||
/** | ||
@@ -16,5 +17,3 @@ * Run a testcheck check function on the given propertyFn, generators, and | ||
*/ | ||
Test.prototype.check = function (generators, propertyFn, options, msg) { | ||
if (this._skip) { return this.end(); } | ||
export default function check(generators, propertyFn, options, msg) { | ||
if (typeof options === 'string') { | ||
@@ -25,27 +24,17 @@ msg = options; | ||
this.emit('prerun'); | ||
let result = testcheck.check( | ||
testcheck.property(generators, propertyFn), options); | ||
try { | ||
let result = testcheck.check(testcheck.property(generators, propertyFn), options); | ||
if (result.result === true) { | ||
this.pass(msg); | ||
} else { | ||
this.fail(msg, { | ||
expected: { result: true }, | ||
actual: result | ||
}); | ||
} | ||
} catch (err) { | ||
this.error(err); | ||
return; | ||
if (result.result === true) { | ||
this.pass(msg); | ||
} else { | ||
this.fail(msg, { | ||
expected: { result: true }, | ||
actual: result | ||
}); | ||
} | ||
} | ||
this.emit('run'); | ||
}; | ||
Test.prototype.gen = testcheck.gen; | ||
Test.prototype.sample = testcheck.sample; | ||
export default test; | ||
// Re-exported for convenience | ||
export { gen, sample } from 'testcheck'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
129
6092
3
5
81