-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c641538
commit ee82d02
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}); | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as path from 'path'; | ||
import * as Mocha from 'mocha'; | ||
import { glob } from 'glob'; | ||
|
||
export async function run(): Promise<void> { | ||
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<void>((resolve, reject) => { | ||
mocha.run((failures) => { | ||
if (failures > 0) { | ||
reject(new Error(`${failures} tests failed.`)); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} |