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 ++++++++++++++++++++ editors/code/tests/unit/launch_config.test.ts | 52 +++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 editors/code/tests/unit/index.ts create mode 100644 editors/code/tests/unit/launch_config.test.ts (limited to 'editors/code/tests/unit') 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); + } + }); + }); +} diff --git a/editors/code/tests/unit/launch_config.test.ts b/editors/code/tests/unit/launch_config.test.ts new file mode 100644 index 000000000..d5cf1b74e --- /dev/null +++ b/editors/code/tests/unit/launch_config.test.ts @@ -0,0 +1,52 @@ +import * as assert from 'assert'; +import * as cargo from '../../src/cargo'; + +suite('Launch configuration', () => { + + suite('Lens', () => { + test('A binary', async () => { + const args = cargo.artifactSpec(["build", "--package", "pkg_name", "--bin", "pkg_name"]); + + assert.deepEqual(args.cargoArgs, ["build", "--package", "pkg_name", "--bin", "pkg_name", "--message-format=json"]); + assert.deepEqual(args.filter, undefined); + }); + + test('One of Multiple Binaries', async () => { + const args = cargo.artifactSpec(["build", "--package", "pkg_name", "--bin", "bin1"]); + + assert.deepEqual(args.cargoArgs, ["build", "--package", "pkg_name", "--bin", "bin1", "--message-format=json"]); + assert.deepEqual(args.filter, undefined); + }); + + test('A test', async () => { + const args = cargo.artifactSpec(["test", "--package", "pkg_name", "--lib", "--no-run"]); + + assert.deepEqual(args.cargoArgs, ["test", "--package", "pkg_name", "--lib", "--no-run", "--message-format=json"]); + assert.notDeepEqual(args.filter, undefined); + }); + }); + + suite('QuickPick', () => { + test('A binary', async () => { + const args = cargo.artifactSpec(["run", "--package", "pkg_name", "--bin", "pkg_name"]); + + assert.deepEqual(args.cargoArgs, ["build", "--package", "pkg_name", "--bin", "pkg_name", "--message-format=json"]); + assert.deepEqual(args.filter, undefined); + }); + + + test('One of Multiple Binaries', async () => { + const args = cargo.artifactSpec(["run", "--package", "pkg_name", "--bin", "bin2"]); + + assert.deepEqual(args.cargoArgs, ["build", "--package", "pkg_name", "--bin", "bin2", "--message-format=json"]); + assert.deepEqual(args.filter, undefined); + }); + + test('A test', async () => { + const args = cargo.artifactSpec(["test", "--package", "pkg_name", "--lib"]); + + assert.deepEqual(args.cargoArgs, ["test", "--package", "pkg_name", "--lib", "--message-format=json", "--no-run"]); + assert.notDeepEqual(args.filter, undefined); + }); + }); +}); -- cgit v1.2.3