From 28a52ccbbfae86cfea242f25de6ad66af2d2c0cf Mon Sep 17 00:00:00 2001 From: Alexis Grojean Date: Fri, 22 Nov 2024 11:14:18 +0100 Subject: [PATCH] Update tests skeleton --- .gitignore | 1 + package-lock.json | 25 ++---------- package.json | 2 - src/test/suite/index.ts | 51 ++++++++++++------------- webpack.config.js => webpack.config.cjs | 3 +- 5 files changed, 30 insertions(+), 52 deletions(-) rename webpack.config.js => webpack.config.cjs (85%) diff --git a/.gitignore b/.gitignore index b947077..2a2f022 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ dist/ +.vscode-test/ diff --git a/package-lock.json b/package-lock.json index 0728eee..a00d33a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,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", @@ -601,17 +600,6 @@ "@types/send": "*" } }, - "node_modules/@types/glob": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@types/glob/-/glob-8.1.0.tgz", - "integrity": "sha512-IO+MJPVhoqz+28h1qLAcBEH2+xHMK6MTyHJc7MTnnYb6wsoLR29POVGJ7LycmVXIqyy/4/2ShP5sUwTXuOwb/w==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/minimatch": "^5.1.2", - "@types/node": "*" - } - }, "node_modules/@types/http-errors": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.4.tgz", @@ -643,13 +631,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/minimatch": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", - "integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/mocha": { "version": "10.0.10", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.10.tgz", @@ -2283,9 +2264,9 @@ "license": "MIT" }, "node_modules/electron-to-chromium": { - "version": "1.5.63", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.63.tgz", - "integrity": "sha512-ddeXKuY9BHo/mw145axlyWjlJ1UBt4WK3AlvkT7W2AbqfRQoacVoRUCF6wL3uIx/8wT9oLKXzI+rFqHHscByaA==", + "version": "1.5.64", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.64.tgz", + "integrity": "sha512-IXEuxU+5ClW2IGEYFC2T7szbyVgehupCWQe5GNh+H065CD6U6IFN0s4KeAMFGNmQolRU4IV7zGBWSYMmZ8uuqQ==", "dev": true, "license": "ISC" }, diff --git a/package.json b/package.json index 0b97e0a..1a2e669 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "type": "git", "url": "https://github.com/LedgerHQ/ledger-vscode-extension/" }, - "type": "module", "engines": { "vscode": "^1.79.0" }, @@ -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", diff --git a/src/test/suite/index.ts b/src/test/suite/index.ts index 2e7c5f2..9eb5ffa 100644 --- a/src/test/suite/index.ts +++ b/src/test/suite/index.ts @@ -1,9 +1,9 @@ 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 { - // Create the mocha test +export async function run(): Promise { + // Create the Mocha test instance const mocha = new Mocha({ ui: "tdd", color: true, @@ -11,30 +11,27 @@ export function run(): Promise { 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; + } } diff --git a/webpack.config.js b/webpack.config.cjs similarity index 85% rename from webpack.config.js rename to webpack.config.cjs index 4085f19..c0fef98 100644 --- a/webpack.config.js +++ b/webpack.config.cjs @@ -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