through2-spy
Advanced tools
Comparing version 1.1.1 to 1.2.0
25
index.js
@@ -0,5 +1,10 @@ | ||
"use strict"; | ||
module.exports = make | ||
module.exports.ctor = ctor | ||
module.exports.obj = obj | ||
module.exports.objCtor = objCtor | ||
var through2 = require("through2") | ||
var xtend = require("xtend") | ||
@@ -20,4 +25,22 @@ function ctor(options, fn) { | ||
function objCtor(options, fn) { | ||
if (typeof options === "function") { | ||
fn = options | ||
options = {} | ||
} | ||
options = xtend({objectMode: true, highWaterMark: 16}, options) | ||
return ctor(options, fn) | ||
} | ||
function make(options, fn) { | ||
return ctor(options, fn)() | ||
} | ||
} | ||
function obj(options, fn) { | ||
if (typeof options === "function") { | ||
fn = options | ||
options = {} | ||
} | ||
options = xtend({objectMode: true, highWaterMark: 16}, options) | ||
return make(options, fn) | ||
} |
{ | ||
"name": "through2-spy", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "A through2 wrapper to for simple stream.PassThrough spies.", | ||
@@ -25,2 +25,12 @@ "main": "index.js", | ||
"license": "MIT", | ||
"jshintConfig": { | ||
"asi": true, | ||
"globalstrict": true, | ||
"validthis": true, | ||
"eqnull": true, | ||
"node": true, | ||
"loopfunc": true, | ||
"newcap": false, | ||
"eqeqeq": false | ||
}, | ||
"bugs": { | ||
@@ -30,10 +40,11 @@ "url": "https://github.com/brycebaril/through2-spy/issues" | ||
"devDependencies": { | ||
"tape": "~2.4.0", | ||
"tap": "~0.4.8", | ||
"stream-spigot": "~3.0.3", | ||
"terminus": "~1.0.9" | ||
"tape": "~2.13.3", | ||
"tap": "~0.4.11", | ||
"stream-spigot": "~3.0.4", | ||
"terminus": "~1.0.10" | ||
}, | ||
"dependencies": { | ||
"through2": "~0.4.1" | ||
"through2": "~0.5.1", | ||
"xtend": "~3.0.0" | ||
} | ||
} |
@@ -54,2 +54,25 @@ through2-spy | ||
API | ||
--- | ||
`require("through2-spy")([options], fn)` | ||
--- | ||
Create a `through2-spy` instance that will call `fn(chunk)` and then silently pass through data downstream. | ||
`require("through2-spy").ctor([options], fn)` | ||
--- | ||
Create a `through2-spy` Type that can be instantiated via `new Type()` or `Type()` to create reusable spies. | ||
`require("through2-spy").obj([options], fn)` | ||
--- | ||
Create a `through2-spy` that defaults to `objectMode = true`. | ||
`require("through2-spy").objCtor([options], fn)` | ||
--- | ||
Create a `through2-spy` Type that defaults to `objectMode = true`. | ||
Options | ||
@@ -64,2 +87,2 @@ ------- | ||
MIT | ||
MIT |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var test = require("tape").test | ||
@@ -36,2 +38,31 @@ | ||
test("objCtor", function (t) { | ||
t.plan(2) | ||
var count = 0 | ||
var Spy = spy.objCtor(function () { | ||
count++ | ||
}) | ||
var input = [ | ||
{foo: "bar"}, | ||
{foo: "baz"}, | ||
{foo: "bif"}, | ||
{foo: "blah"}, | ||
{foo: "buzz"}, | ||
] | ||
// Input gets consumed, so make a copy for comparison. | ||
var copy = input.slice(0) | ||
function combine(records) { | ||
t.equals(count, 5, "Spied the right number of chunks") | ||
t.deepEquals(copy, records, "Content unchanged") | ||
} | ||
spigot({objectMode: true}, input) | ||
.pipe(new Spy()) | ||
.pipe(concat({objectMode: true}, combine)) | ||
}) | ||
test("ctor options", function (t) { | ||
@@ -149,2 +180,32 @@ t.plan(2) | ||
test("return non-error obj", function (t) { | ||
t.plan(2) | ||
// Non-error return is ignored. | ||
var count = 0 | ||
var s = spy.obj(function () { | ||
if (++count > 2) return "WUT" | ||
}) | ||
var input = [ | ||
{foo: "bar"}, | ||
{foo: "baz"}, | ||
{foo: "bif"}, | ||
{foo: "blah"}, | ||
{foo: "buzz"}, | ||
] | ||
// Input gets consumed, so make a copy for comparison. | ||
var copy = input.slice(0) | ||
function combine(records) { | ||
t.equals(count, 5, "Spied the right number of chunks") | ||
t.deepEquals(copy, records, "Content unchanged") | ||
} | ||
spigot({objectMode: true}, input) | ||
.pipe(s) | ||
.pipe(concat({objectMode: true}, combine)) | ||
}) | ||
test("abort", function (t) { | ||
@@ -225,2 +286,2 @@ t.plan(2) | ||
.pipe(concat(combine)) | ||
}) | ||
}) |
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
10918
267
87
2
+ Addedxtend@~3.0.0
+ Addedthrough2@0.5.1(transitive)
+ Addedxtend@3.0.0(transitive)
- Removedobject-keys@0.4.0(transitive)
- Removedthrough2@0.4.2(transitive)
- Removedxtend@2.1.2(transitive)
Updatedthrough2@~0.5.1