flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
53 lines • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const run_1 = require("./run");
const fs = require("fs");
const path = require("path");
const crypto = require("crypto");
const files = {};
const hash = (input) => {
return crypto
.createHash("md5")
.update(input)
.digest("hex");
};
let fsWait = null;
let changeCount = 0;
exports.watch = (suiteNames, tag) => {
const packageJson = require(`${process.cwd()}/package.json`);
const entryPoint = packageJson.main;
const distFolder = path.dirname(entryPoint);
console.log(`Watching for updates to: ${distFolder}`);
fs.watch(distFolder, { recursive: true }, (eventType, fileName) => {
if (fileName) {
if (typeof files[fileName] == "undefined") {
files[fileName] = {
contentMd5: null,
fileWait: null
};
}
if (files[fileName].fileWait !== null) {
return;
}
files[fileName].fileWait = setTimeout(() => {
files[fileName].fileWait = null;
}, 100);
const md5Current = hash(fs.readFileSync(`${distFolder}/${fileName}`));
if (md5Current === files[fileName].contentMd5) {
return;
}
files[fileName].contentMd5 = md5Current;
changeCount++;
if (fsWait !== null) {
return;
}
fsWait = setTimeout(() => {
changeCount = 0;
fsWait = null;
console.log(`${changeCount} files changed. Running tests...`);
run_1.run(suiteNames, tag);
}, 1000);
}
});
};
//# sourceMappingURL=watch.js.map