UNPKG

hackages

Version:

CLI tool for learning software development concepts through test-driven development

34 lines (33 loc) โ€ข 1.22 kB
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(); }); }); }