From 32532fb73638c0c4868c3aff2fe92c002da17f2e Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 29 Dec 2017 16:17:35 -0700 Subject: [PATCH] Breaking: Require globs to only use POSIX-style separators --- package.json | 1 + test/index.js | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index db9687d..1b0fd43 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "jscs-preset-gulp": "^1.0.0", "mocha": "^2.0.0", "mocha-lcov-reporter": "^1.2.0", + "normalize-path": "^2.1.1", "rimraf": "^2.6.1", "through2": "^2.0.1" }, diff --git a/test/index.js b/test/index.js index 0382766..b1fa927 100644 --- a/test/index.js +++ b/test/index.js @@ -6,6 +6,7 @@ var path = require('path'); var expect = require('expect'); var rimraf = require('rimraf'); var through = require('through2'); +var normalizePath = require('normalize-path'); var watch = require('../'); @@ -19,7 +20,8 @@ describe('glob-watcher', function() { var outDir = path.join(__dirname, './fixtures/'); var outFile1 = path.join(outDir, 'changed.js'); var outFile2 = path.join(outDir, 'added.js'); - var outGlob = path.join(outDir, './**/*.js'); + var globPattern = '**/*.js'; + var outGlob = normalizePath(path.join(outDir, globPattern)); function changeFile() { fs.writeFileSync(outFile1, 'hello changed'); @@ -49,8 +51,8 @@ describe('glob-watcher', function() { it('only requires a glob and returns watcher', function(done) { watcher = watch(outGlob); - watcher.once('change', function(path) { - expect(path).toEqual(outFile1); + watcher.once('change', function(filepath) { + expect(filepath).toEqual(outFile1); done(); }); @@ -61,8 +63,8 @@ describe('glob-watcher', function() { it('picks up added files', function(done) { watcher = watch(outGlob); - watcher.once('add', function(path) { - expect(path).toEqual(outFile2); + watcher.once('add', function(filepath) { + expect(filepath).toEqual(outFile2); done(); }); @@ -70,6 +72,19 @@ describe('glob-watcher', function() { watcher.on('ready', addFile); }); + it('works with OS-specific cwd', function(done) { + watcher = watch('./fixtures/' + globPattern, { cwd: __dirname }); + + watcher.once('change', function(filepath) { + // Uses path.join here because the resulting path is OS-specific + expect(filepath).toEqual(path.join('fixtures', 'changed.js')); + done(); + }); + + // We default `ignoreInitial` to true, so always wait for `on('ready')` + watcher.on('ready', changeFile); + }); + it('accepts a callback & calls when file is changed', function(done) { watcher = watch(outGlob, function(cb) { cb();