From ee82d029de30f25b2ca1f188ec4091d2898dbac5 Mon Sep 17 00:00:00 2001 From: Benson Cheng Date: Mon, 23 Sep 2024 03:08:44 -0400 Subject: [PATCH] from ubuntu WSL --- test/suite/extensions.test.ts | 27 +++++++++++++++++++++++++++ test/suite/index.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/test/suite/extensions.test.ts b/test/suite/extensions.test.ts index e69de29b..953adc6f 100644 --- a/test/suite/extensions.test.ts +++ b/test/suite/extensions.test.ts @@ -0,0 +1,27 @@ +// Import the Mocha test framework +import * as Mocha from 'mocha'; +// Import Node.js path module to handle file paths +import * as path from 'path'; +// Import the glob module to find test files +import { glob } from 'glob'; +// Import the run function from your test runner +import { run } from './index'; + +// Define a Mocha test suite +suite('Extension Test Suite', () => { + // A test case within the suite + test('Sample Test', () => { + // Example assertion using Chai or Node's assert + const expected = -1; + const actual = [1, 2, 3].indexOf(4); + if (actual !== expected) { + throw new Error(`Expected indexOf(4) to be ${expected}, but got ${actual}`); + } + }); + + // You can add more tests here or import them from other files +}); + + + + diff --git a/test/suite/index.ts b/test/suite/index.ts index e69de29b..46155057 100644 --- a/test/suite/index.ts +++ b/test/suite/index.ts @@ -0,0 +1,30 @@ +import * as path from 'path'; +import * as Mocha from 'mocha'; +import { glob } from 'glob'; + +export async function run(): Promise { + const mocha = new Mocha({ + ui: 'bdd', + color: true, + }); + + const testsRoot = path.resolve(__dirname); + + try { + const files = await glob('**/*.test.js', { cwd: testsRoot }); + + files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))); + + await new Promise((resolve, reject) => { + mocha.run((failures) => { + if (failures > 0) { + reject(new Error(`${failures} tests failed.`)); + } else { + resolve(); + } + }); + }); + } catch (err) { + return Promise.reject(err); + } +}