Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test of executing command for each simultaneous change. #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions test/test-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,45 @@ describe('chokidar-cli', function() {
}, TIMEOUT_WATCH_READY);
});


it('should run command for each simultaneous change, if not debounced or throttled', done => {
let killed = false;

// I hope it's safe to use the pipe and tee here. It should work
// on any unix-y system.
const logChanges = `echo {path} | tee -a ${CHANGE_FILE}`;

// Run watcher
run(`node ../index.js "dir/**/*.js" -d 0 -c "${logChanges}"`, {
pipe: DEBUG_TESTS,
cwd: './test',
// Called after process is spawned
callback(child) {
setTimeout(function killChild() {
// Kill child after test case
child.kill();
killed = true;
}, TIMEOUT_KILL);
}
})
.then(function childProcessExited() {
// Process should be killed after a timeout,
// test if the process died unexpectedly before it
assert(killed, 'process exited too quickly');
done();
});

setTimeout(() => {
run('touch dir/a.js dir/b.js', { cwd: './test' })
.then(
setTimeout(() => {
assert(changeFileContains('a.js'), 'change file should include a.js');
assert(changeFileContains('b.js'), 'change file should include b.js');
}, TIMEOUT_CHANGE_DETECTED)
);
}, TIMEOUT_WATCH_READY);
});

it('should replace {path} and {event} in command', done => {
const command = `echo '{event}:{path}' > ${CHANGE_FILE}`;

Expand Down Expand Up @@ -124,3 +163,7 @@ function resolve(relativePath) {
function changeFileExists() {
return fs.existsSync(resolve(CHANGE_FILE));
}

function changeFileContains(pattern) {
return fs.readFileSync(resolve(CHANGE_FILE)).toString().match(pattern);
}