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 98d2ef6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 52 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
dist/
.vscode-test/
25 changes: 3 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"type": "git",
"url": "https://github.com/LedgerHQ/ledger-vscode-extension/"
},
"type": "module",
"engines": {
"vscode": "^1.79.0"
},
Expand Down Expand Up @@ -277,7 +276,6 @@
"devDependencies": {
"@ltd/j-toml": "^1.38.0",
"@stylistic/eslint-plugin": "^2.11.0",
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.10",
"@types/node": "22.9.1",
"@types/vscode": "^1.95.0",
Expand Down
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;
}
}
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ const extensionConfig = {
libraryTarget: "commonjs2",
},
externals: {
vscode: "commonjs vscode", // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
"vscode": "commonjs vscode", // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
// modules added here also need to be added in the .vscodeignore file
"@ltd/j-toml": "commonjs @ltd/j-toml",
},
resolve: {
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
Expand Down

0 comments on commit 98d2ef6

Please sign in to comment.