first
This commit is contained in:
298
run-tests-simple.js
Normal file
298
run-tests-simple.js
Normal file
@@ -0,0 +1,298 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* @fileoverview Simple test execution script for Laravel Healthcare MCP Server
|
||||
* Provides basic command-line interface without external dependencies
|
||||
*/
|
||||
|
||||
import { spawn } from "child_process";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
/**
|
||||
* Simple argument parser
|
||||
*/
|
||||
function parseArgs() {
|
||||
const args = process.argv.slice(2);
|
||||
const command = args[0] || "help";
|
||||
const options = {};
|
||||
|
||||
// Parse options
|
||||
for (let i = 1; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
if (arg === "--coverage" || arg === "-c") {
|
||||
options.coverage = true;
|
||||
} else if (arg === "--verbose" || arg === "-v") {
|
||||
options.verbose = true;
|
||||
} else if (arg === "--watch" || arg === "-w") {
|
||||
options.watch = true;
|
||||
}
|
||||
}
|
||||
|
||||
return { command, options };
|
||||
}
|
||||
|
||||
/**
|
||||
* Test suite configurations
|
||||
*/
|
||||
const testSuites = {
|
||||
public: {
|
||||
name: "Public Tools Tests",
|
||||
pattern: "tests/public/**/*.test.js",
|
||||
description: "Tests for public authentication and registration tools",
|
||||
},
|
||||
provider: {
|
||||
name: "Provider Tools Tests",
|
||||
pattern: "tests/provider/**/*.test.js",
|
||||
description: "Tests for provider EMR, prescription, and appointment tools",
|
||||
},
|
||||
patient: {
|
||||
name: "Patient Tools Tests",
|
||||
pattern: "tests/patient/**/*.test.js",
|
||||
description: "Tests for patient portal and data management tools",
|
||||
},
|
||||
business: {
|
||||
name: "Business Operations Tests",
|
||||
pattern: "tests/partner-affiliate-network/**/*.test.js",
|
||||
description: "Tests for partner, affiliate, and network business tools",
|
||||
},
|
||||
healthcare: {
|
||||
name: "Healthcare-Specific Tests",
|
||||
pattern: "tests/healthcare-specific/**/*.test.js",
|
||||
description: "Tests for HIPAA compliance and clinical workflows",
|
||||
},
|
||||
errors: {
|
||||
name: "Error Handling Tests",
|
||||
pattern: "tests/error-handling/**/*.test.js",
|
||||
description: "Tests for authentication, API, and network error scenarios",
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Execute Jest command
|
||||
*/
|
||||
async function executeJest(args) {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(
|
||||
`🧪 Running: node --experimental-vm-modules ./node_modules/jest/bin/jest.js ${args.join(
|
||||
" "
|
||||
)}\n`
|
||||
);
|
||||
|
||||
const jest = spawn(
|
||||
"node",
|
||||
["--experimental-vm-modules", "./node_modules/jest/bin/jest.js", ...args],
|
||||
{
|
||||
stdio: "inherit",
|
||||
shell: true,
|
||||
}
|
||||
);
|
||||
|
||||
jest.on("close", (code) => {
|
||||
if (code === 0) {
|
||||
console.log("\n✅ Tests completed successfully!");
|
||||
resolve(code);
|
||||
} else if (code === 1) {
|
||||
console.log("\n⚠️ Some tests failed, but Jest ran successfully.");
|
||||
resolve(code);
|
||||
} else {
|
||||
console.log(`\n❌ Jest failed with exit code ${code}`);
|
||||
reject(new Error(`Jest failed with code ${code}`));
|
||||
}
|
||||
});
|
||||
|
||||
jest.on("error", (error) => {
|
||||
console.error("❌ Failed to start Jest:", error.message);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all tests
|
||||
*/
|
||||
async function runAllTests(options = {}) {
|
||||
console.log("🏥 Laravel Healthcare MCP Server - All Tests");
|
||||
console.log("=".repeat(50));
|
||||
|
||||
const jestArgs = [];
|
||||
|
||||
if (options.coverage) {
|
||||
jestArgs.push("--coverage");
|
||||
}
|
||||
|
||||
if (options.verbose) {
|
||||
jestArgs.push("--verbose");
|
||||
}
|
||||
|
||||
if (options.watch) {
|
||||
jestArgs.push("--watch");
|
||||
}
|
||||
|
||||
try {
|
||||
const exitCode = await executeJest(jestArgs);
|
||||
process.exit(exitCode);
|
||||
} catch (error) {
|
||||
console.error("❌ Test execution failed:", error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run specific test suite
|
||||
*/
|
||||
async function runTestSuite(suiteName, options = {}) {
|
||||
const suite = testSuites[suiteName];
|
||||
|
||||
if (!suite) {
|
||||
console.error(`❌ Unknown test suite: ${suiteName}`);
|
||||
console.log("\nAvailable suites:");
|
||||
Object.keys(testSuites).forEach((name) => {
|
||||
console.log(` - ${name}: ${testSuites[name].description}`);
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`🧪 ${suite.name}`);
|
||||
console.log(`📝 ${suite.description}`);
|
||||
console.log("=".repeat(50));
|
||||
|
||||
const jestArgs = ["--testPathPattern", suite.pattern];
|
||||
|
||||
if (options.coverage) {
|
||||
jestArgs.push("--coverage");
|
||||
}
|
||||
|
||||
if (options.verbose) {
|
||||
jestArgs.push("--verbose");
|
||||
}
|
||||
|
||||
if (options.watch) {
|
||||
jestArgs.push("--watch");
|
||||
}
|
||||
|
||||
try {
|
||||
const exitCode = await executeJest(jestArgs);
|
||||
process.exit(exitCode);
|
||||
} catch (error) {
|
||||
console.error("❌ Test execution failed:", error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run quick test suite
|
||||
*/
|
||||
async function runQuickTests() {
|
||||
console.log("⚡ Laravel Healthcare MCP Server - Quick Tests");
|
||||
console.log("📝 Running essential tests only (no coverage)");
|
||||
console.log("=".repeat(50));
|
||||
|
||||
const essentialSuites = ["public", "provider", "patient"];
|
||||
const pattern = essentialSuites
|
||||
.map((suite) => testSuites[suite].pattern)
|
||||
.join("|");
|
||||
|
||||
const jestArgs = ["--testPathPattern", `(${pattern})`];
|
||||
|
||||
try {
|
||||
const exitCode = await executeJest(jestArgs);
|
||||
process.exit(exitCode);
|
||||
} catch (error) {
|
||||
console.error("❌ Test execution failed:", error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate coverage report
|
||||
*/
|
||||
async function runCoverage() {
|
||||
console.log("📊 Laravel Healthcare MCP Server - Coverage Report");
|
||||
console.log("=".repeat(50));
|
||||
|
||||
const jestArgs = ["--coverage", "--silent"];
|
||||
|
||||
try {
|
||||
const exitCode = await executeJest(jestArgs);
|
||||
console.log("\n📊 Coverage report generated in ./coverage/");
|
||||
process.exit(exitCode);
|
||||
} catch (error) {
|
||||
console.error("❌ Coverage generation failed:", error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show help
|
||||
*/
|
||||
function showHelp() {
|
||||
console.log("🏥 Laravel Healthcare MCP Server Test Suite");
|
||||
console.log("=".repeat(50));
|
||||
console.log("\nUsage: node run-tests-simple.js <command> [options]");
|
||||
console.log("\nCommands:");
|
||||
console.log(" all Run all test suites");
|
||||
console.log(" quick Run essential tests only");
|
||||
console.log(" coverage Generate coverage report");
|
||||
console.log(" suite <name> Run specific test suite");
|
||||
console.log(" help Show this help message");
|
||||
|
||||
console.log("\nTest Suites:");
|
||||
Object.entries(testSuites).forEach(([name, suite]) => {
|
||||
console.log(` ${name.padEnd(12)} ${suite.description}`);
|
||||
});
|
||||
|
||||
console.log("\nOptions:");
|
||||
console.log(" -c, --coverage Generate coverage report");
|
||||
console.log(" -v, --verbose Verbose output");
|
||||
console.log(" -w, --watch Watch mode");
|
||||
|
||||
console.log("\nExamples:");
|
||||
console.log(" node run-tests-simple.js all --coverage");
|
||||
console.log(" node run-tests-simple.js suite provider --verbose");
|
||||
console.log(" node run-tests-simple.js quick");
|
||||
console.log(" node run-tests-simple.js coverage");
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
async function main() {
|
||||
const { command, options } = parseArgs();
|
||||
|
||||
try {
|
||||
switch (command) {
|
||||
case "all":
|
||||
await runAllTests(options);
|
||||
break;
|
||||
case "suite":
|
||||
const suiteName = process.argv[3];
|
||||
if (!suiteName) {
|
||||
console.error("❌ Please specify a suite name");
|
||||
showHelp();
|
||||
process.exit(1);
|
||||
}
|
||||
await runTestSuite(suiteName, options);
|
||||
break;
|
||||
case "quick":
|
||||
await runQuickTests();
|
||||
break;
|
||||
case "coverage":
|
||||
await runCoverage();
|
||||
break;
|
||||
case "help":
|
||||
default:
|
||||
showHelp();
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("❌ Unexpected error:", error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Run the main function
|
||||
main().catch((error) => {
|
||||
console.error("❌ Unexpected error:", error);
|
||||
process.exit(1);
|
||||
});
|
Reference in New Issue
Block a user