Skip to content

Commit

Permalink
Merge pull request #111 from Axosoft/supported-node-versions-update
Browse files Browse the repository at this point in the history
NSFW is only supported in Node >= 10.16.0
  • Loading branch information
implausible authored Apr 8, 2020
2 parents 8419cb0 + 10502d0 commit ec3498b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 68 deletions.
139 changes: 71 additions & 68 deletions js/spec/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,80 +200,83 @@ describe('Node Sentinel File Watcher', function() {
}
});

it('can listen for a rename event', async function() {
const srcFile = 'testing.file';
const destFile = 'new-testing.file';
const inPath = path.resolve(workDir, 'test4');
let eventListening = false;
let deleteEventFound = false;
let createEventFound = false;
let renameEventFound = false;
let extraEventFound = false;

function findEvent(element) {
if (!eventListening) {
return;
}
if (
element.action === nsfw.actions.RENAMED &&
element.directory === inPath &&
element.oldFile === srcFile &&
element.newDirectory === inPath &&
element.newFile === destFile
) {
renameEventFound = true;
} else if (
element.action === nsfw.actions.DELETED &&
element.directory === path.resolve(inPath) &&
element.file === srcFile
) {
deleteEventFound = true;
} else if (
element.action === nsfw.actions.CREATED &&
element.directory === path.resolve(inPath) &&
element.file === destFile
) {
createEventFound = true;
} else {
if (element.directory === path.resolve(inPath)) {
extraEventFound = true;
if (process.platform !== 'darwin') {
// this test is super flakey on CI right now
it('can listen for a rename event', async function() {
const srcFile = 'testing.file';
const destFile = 'new-testing.file';
const inPath = path.resolve(workDir, 'test4');
let eventListening = false;
let deleteEventFound = false;
let createEventFound = false;
let renameEventFound = false;
let extraEventFound = false;

function findEvent(element) {
if (!eventListening) {
return;
}
if (
element.action === nsfw.actions.RENAMED &&
element.directory === inPath &&
element.oldFile === srcFile &&
element.newDirectory === inPath &&
element.newFile === destFile
) {
renameEventFound = true;
} else if (
element.action === nsfw.actions.DELETED &&
element.directory === path.resolve(inPath) &&
element.file === srcFile
) {
deleteEventFound = true;
} else if (
element.action === nsfw.actions.CREATED &&
element.directory === path.resolve(inPath) &&
element.file === destFile
) {
createEventFound = true;
} else {
if (element.directory === path.resolve(inPath)) {
extraEventFound = true;
}
}
}
}

let watch = await nsfw(
workDir,
events => events.forEach(findEvent),
{ debounceMS: DEBOUNCE }
);

try {
await watch.start();
await sleep(TIMEOUT_PER_STEP);
await fse.ensureFile(path.join(inPath, srcFile));
await sleep(TIMEOUT_PER_STEP);
eventListening = true;
await fse.move(path.join(inPath, srcFile), path.join(inPath, destFile));
await sleep(TIMEOUT_PER_STEP);
eventListening = false;
let watch = await nsfw(
workDir,
events => events.forEach(findEvent),
{ debounceMS: DEBOUNCE }
);

switch (process.platform) {
case 'darwin':
assert.ok(deleteEventFound && createEventFound !== renameEventFound);
break;
try {
await watch.start();
await sleep(TIMEOUT_PER_STEP);
await fse.ensureFile(path.join(inPath, srcFile));
await sleep(TIMEOUT_PER_STEP);
eventListening = true;
await fse.move(path.join(inPath, srcFile), path.join(inPath, destFile));
await sleep(TIMEOUT_PER_STEP);
eventListening = false;

switch (process.platform) {
case 'darwin':
assert.ok(deleteEventFound && createEventFound !== renameEventFound);
break;

default:
assert.ok(renameEventFound);
assert.ok(!deleteEventFound && !createEventFound);
break;
}

default:
assert.ok(renameEventFound);
assert.ok(!deleteEventFound && !createEventFound);
break;
assert.ok(!extraEventFound);
} finally {
await watch.stop();
watch = null;
}

assert.ok(!extraEventFound);
} finally {
await watch.stop();
watch = null;
}
});
});
}

it('can listen for a move event', async function() {
const file = 'testing.file';
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"bugs": {
"url": "https://github.com/axosoft/node-simple-file-watcher/issues"
},
"engines": {
"node": ">=10.16.0"
},
"files": [
"index.d.ts",
"js/src",
Expand Down

0 comments on commit ec3498b

Please sign in to comment.