@erickmerchant/conditional-watch
Advanced tools
Comparing version 1.0.0 to 2.0.0
17
index.js
@@ -6,8 +6,17 @@ const watch = require('recursive-watch') | ||
if (conditional) { | ||
watch(directory, debounce(function () { | ||
fn() | ||
}, options || {wait: 150})) | ||
let files = [] | ||
let debounced = debounce(function () { | ||
fn(files) | ||
files = [] | ||
}, options || {wait: 150}) | ||
watch(directory, function (file) { | ||
files.push(file) | ||
debounced() | ||
}) | ||
} | ||
return fn() | ||
fn() | ||
} |
{ | ||
"name": "@erickmerchant/conditional-watch", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Watch using recursive-watch or not", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
32
test.js
@@ -17,3 +17,3 @@ const test = require('tape') | ||
test('true', function (t) { | ||
test('true - watching', function (t) { | ||
mockery.enable(mockerySettings) | ||
@@ -32,6 +32,6 @@ | ||
fn() | ||
fn('a-file') | ||
}) | ||
require('./index')(true, './foo', function () { | ||
require('./index')(true, './foo', function (files) { | ||
t.ok(1) | ||
@@ -41,2 +41,28 @@ }) | ||
mockery.disable() | ||
mockery.deregisterAll() | ||
}) | ||
test('true - debounced', function (t) { | ||
mockery.enable(mockerySettings) | ||
t.plan(2) | ||
mockery.registerMock('recursive-watch', function (directory, fn) { | ||
t.equal(directory, './foo') | ||
fn('a-file') | ||
fn('b-file') | ||
}) | ||
require('./index')(true, './foo', function (files) { | ||
if (files) { | ||
t.deepEqual(files, ['a-file', 'b-file']) | ||
} | ||
}) | ||
mockery.disable() | ||
mockery.deregisterAll() | ||
}) |
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
3404
62