UNPKG

anyfetch-file-watcher

Version:

Watch for file changes, and send them to anyFetch.

54 lines (45 loc) 1.8 kB
"use strict"; require('should'); var fs = require("fs"); var path = require("path"); var listFiles = require('../../lib/helpers/list-files'); var getCursorFromDirectory = listFiles.getCursorFromDirectory; var retrieveFiles = listFiles.retrieveFiles; describe("getCursorFromDirectory()", function() { it("should list the files inside the sample directory", function(done) { GLOBAL.WATCHED_DIR = path.resolve("test/sample-directory"); getCursorFromDirectory(function(err, res) { if(err) { throw err; } Object.keys(res).should.include('/txt1.txt'); Object.keys(res).should.include('/txt2.txt'); Object.keys(res).should.include('/txt3.txt'); Object.keys(res).should.include('/test/txt1.doc'); Object.keys(res).should.include('/test/txt2.txt'); Object.keys(res).should.have.lengthOf(5); done(); }); }); }); describe("Retrieve file", function () { it("should return the new file that are updated", function(done) { GLOBAL.WATCHED_DIR = path.resolve("test/sample-directory"); var cursor = { '/txt1.txt': fs.statSync(__dirname + '/../sample-directory/txt1.txt').mtime.getTime(), '/txt2.txt': fs.statSync(__dirname + '/../sample-directory/txt2.txt').mtime.getTime(), '/test/txt1.doc': fs.statSync(__dirname + '/../sample-directory/test/txt1.doc').mtime.getTime() - 500, }; retrieveFiles(cursor, function(err, filesToUpload) { if(err) { throw err; } // Should contain new files and updated files filesToUpload.should.have.property('/txt3.txt'); filesToUpload.should.have.property('/test/txt1.doc'); filesToUpload.should.have.property('/test/txt2.txt'); Object.keys(filesToUpload).should.have.lengthOf(3); done(); }); }); });