hackages
Version:
CLI tool for learning software development concepts through test-driven development
34 lines (33 loc) โข 1.22 kB
JavaScript
import { spawn } from "child_process";
import chalk from "chalk";
import path from "path";
import { findExerciseDirectory } from "./file-manager.js";
export async function runTests() {
console.log(chalk.blue("๐งช Running tests..."));
console.log(chalk.cyan("=".repeat(50)));
const exerciseDir = findExerciseDirectory();
if (exerciseDir !== process.cwd()) {
console.log(chalk.blue(`๐ Running tests in: ${path.basename(exerciseDir)}`));
}
return new Promise((resolve) => {
const testProcess = spawn("npm", ["test"], {
stdio: "inherit",
shell: true,
cwd: exerciseDir,
});
testProcess.on("close", (code) => {
console.log(chalk.cyan("=".repeat(50)));
if (code === 0) {
console.log(chalk.green("โ
Tests completed!"));
}
else {
console.log(chalk.yellow("โ ๏ธ Some tests may have failed. Keep working on your implementation!"));
}
resolve();
});
testProcess.on("error", (error) => {
console.error(chalk.red("โ Error running tests:"), error.message);
resolve();
});
});
}