Skip to content

Commit

Permalink
Breaking: Require globs to only use POSIX-style separators
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Dec 29, 2017
1 parent a5ddf43 commit 32532fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
25 changes: 20 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('../');

Expand All @@ -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');
Expand Down Expand Up @@ -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();
});

Expand All @@ -61,15 +63,28 @@ 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();
});

// We default `ignoreInitial` to true, so always wait for `on('ready')`
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();
Expand Down

0 comments on commit 32532fb

Please sign in to comment.