derw
Version:
An Elm-inspired language that transpiles to TypeScript
93 lines (92 loc) • 3.73 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runTests = void 0;
const bach_1 = require("@eeue56/bach/build/bach");
const baner_1 = require("@eeue56/baner");
const chokidar = __importStar(require("chokidar"));
const path_1 = __importDefault(require("path"));
const compile_1 = require("./compile");
const testingParser = (0, baner_1.parser)([
(0, baner_1.longFlag)("watch", "Watch Derw files for changes", (0, baner_1.empty)()),
(0, baner_1.longFlag)("function", "A particular function name to run", (0, baner_1.string)()),
(0, baner_1.longFlag)("file", "A particular file name to run", (0, baner_1.string)()),
(0, baner_1.longFlag)("only-fails", "Only log failing tests", (0, baner_1.empty)()),
(0, baner_1.bothFlag)("h", "help", "This help text", (0, baner_1.empty)()),
]);
function showTestingHelp() {
console.log("To run tests, run `derw test` from the package directory");
console.log("To watch use the --watch flag");
console.log((0, baner_1.help)(testingParser));
}
async function runTests(isInPackageDirectory, argv) {
const program = (0, baner_1.parse)(testingParser, argv);
if (program.flags["h/help"].isPresent) {
showTestingHelp();
return;
}
const errors = (0, baner_1.allErrors)(program);
if (errors.length > 0) {
console.log("Errors:");
console.log(errors.join("\n"));
process.exit(1);
}
if (!isInPackageDirectory) {
console.log("Must run tests from the root of a package directory.");
process.exit(1);
}
if (program.flags.watch.isPresent) {
console.log("Watching src and derw-packages...");
argv.push("--clean-exit");
let timer;
chokidar
.watch([
path_1.default.join(process.cwd(), "src"),
path_1.default.join(process.cwd(), "derw-packages"),
])
.on("error", () => {
console.log("Got an error");
})
.on("all", async (event, path) => {
if (path.endsWith(".derw")) {
if (timer !== null) {
clearTimeout(timer);
}
timer = setTimeout(async () => {
await (0, compile_1.compileFiles)(isInPackageDirectory, argv);
await (0, bach_1.runner)();
}, 300);
}
});
}
else {
await (0, compile_1.compileFiles)(isInPackageDirectory, argv);
await (0, bach_1.runner)();
}
}
exports.runTests = runTests;