Skip to content

Commit

Permalink
Update tests skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
agrojean-ledger committed Nov 22, 2024
1 parent cabba3a commit 7b05c3b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
import * as path from "path";
import * as Mocha from "mocha";
import * as glob from "glob";
import Mocha = require("mocha");
import { glob } from "glob";

export function run(): Promise<void> {
// Create the mocha test
export async function run(): Promise<void> {
// Create the Mocha test instance
const mocha = new Mocha({
ui: "tdd",
color: true,
});

const testsRoot = path.resolve(__dirname, "..");

return new Promise((c, e) => {
glob("**/**.test.js", { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}
try {
// Use glob's promise-based API to find test files
const files = await glob("**/*.test.js", { cwd: testsRoot });

// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
// Add each test file to the Mocha test suite
files.forEach(file => mocha.addFile(path.resolve(testsRoot, file)));

try {
// Run the mocha test
mocha.run((failures) => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
}
else {
c();
}
});
}
catch (err) {
console.error(err);
e(err);
}
// Run the tests and handle results
return new Promise((resolve, reject) => {
mocha.run((failures: number) => {
if (failures > 0) {
reject(new Error(`${failures} tests failed.`));
}
else {
resolve();
}
});
});
});
}
catch (err) {
console.error("Error setting up tests:", err);
throw err;
}
}
File renamed without changes.

0 comments on commit 7b05c3b

Please sign in to comment.