From 8ee40ccbe963a0a5e3e998c1652378e1035dc40d Mon Sep 17 00:00:00 2001 From: vsrs Date: Wed, 20 May 2020 21:03:49 +0300 Subject: vscode client side tests --- editors/code/tests/unit/index.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 editors/code/tests/unit/index.ts (limited to 'editors/code/tests/unit/index.ts') diff --git a/editors/code/tests/unit/index.ts b/editors/code/tests/unit/index.ts new file mode 100644 index 000000000..1deb1c403 --- /dev/null +++ b/editors/code/tests/unit/index.ts @@ -0,0 +1,38 @@ +import * as path from 'path'; +import Mocha from 'mocha'; +import glob from 'glob'; + +export function run(): Promise { + // Create the mocha test + const mocha = new Mocha({ + ui: 'tdd', + color: true + }); + + const testsRoot = __dirname; + + return new Promise((c, e) => { + glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { + if (err) { + return e(err); + } + + // Add files to the test suite + files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); + + try { + // Run the mocha test + mocha.timeout(100000); + mocha.run(failures => { + if (failures > 0) { + e(new Error(`${failures} tests failed.`)); + } else { + c(); + } + }); + } catch (err) { + e(err); + } + }); + }); +} -- cgit v1.2.3 From c41a10c29331127ee830badddae55f3e27c9a6ea Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 21 May 2020 11:34:34 +0300 Subject: Apply suggestions from @Veetaha code review --- editors/code/tests/unit/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'editors/code/tests/unit/index.ts') diff --git a/editors/code/tests/unit/index.ts b/editors/code/tests/unit/index.ts index 1deb1c403..5165720b4 100644 --- a/editors/code/tests/unit/index.ts +++ b/editors/code/tests/unit/index.ts @@ -11,10 +11,10 @@ export function run(): Promise { const testsRoot = __dirname; - return new Promise((c, e) => { + return new Promise((resolve, reject) => { glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { if (err) { - return e(err); + return reject(err); } // Add files to the test suite @@ -25,13 +25,13 @@ export function run(): Promise { mocha.timeout(100000); mocha.run(failures => { if (failures > 0) { - e(new Error(`${failures} tests failed.`)); + reject(new Error(`${failures} tests failed.`)); } else { - c(); + resolve(); } }); } catch (err) { - e(err); + reject(err); } }); }); -- cgit v1.2.3