chutzpah-watch
Version:
Run chutzpah test cases in watch mode
57 lines • 1.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const watch = require("node-watch");
const fs_1 = require("fs");
const chalkModule = require("chalk");
const chalk = chalkModule.default;
const child_process_1 = require("child_process");
let config;
const js = process.cwd();
const dirsToWatch = [];
function run(args) {
config = args;
getDirectoriesToWatch(js);
startWatchingTests();
informMyJob();
}
exports.run = run;
function onlyDirectory(file) {
return fs_1.statSync(file).isDirectory()
&& config.dirsToSkip.indexOf(file) < 0;
}
function insertFileToWatchList(file) {
dirsToWatch.push(file);
}
function onTestFileChange(evt, name) {
log(chalk.bgBlue(`Running Tests on ${name}`));
const chutzpahExe = `${config.exePath}/chutzpah.console.exe`;
const file = path.resolve(js, name);
const params = ` /path ${file} ${config.cliOptions.map((s) => ` /${s}`).join('')}`;
const script = chutzpahExe + params;
child_process_1.exec(script, (err, data) => {
log(chalk.bgGreen(data.toString()));
if (err) {
log(chalk.bgRed(err.toString()));
}
});
}
function informMyJob() {
log(chalk.bgCyan('---Welcome to Chutzpah-Watch CLI---\nWatching test cases in below listed directories:\n'), dirsToWatch);
}
function writeColor(msg, obj) {
log(chalk.bgGreen.bold(msg), obj || '');
}
function log(msg, obj) {
console.log(msg, obj || '');
}
function getDirectoriesToWatch(workingDir) {
fs_1.readdirSync(workingDir).
filter(onlyDirectory).
forEach(insertFileToWatchList);
}
function startWatchingTests() {
const settings = Object.assign({}, config.watchConfig, { filter: (f) => new RegExp(config.watchConfig.filter).test(f) });
watch(dirsToWatch, settings, onTestFileChange);
}
//# sourceMappingURL=watch-testfiles.js.map