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 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') 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 From d605ec9c321392d9c7ee4b440c560e1e405d92e6 Mon Sep 17 00:00:00 2001 From: veetaha Date: Sun, 31 May 2020 05:13:08 +0300 Subject: Change Runnable.bin -> Runnable.kind As per matklad, we now pass the responsibility for finding the binary to the frontend. Also, added caching for finding the binary path to reduce the amount of filesystem interactions. --- editors/code/tests/unit/launch_config.test.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'editors/code/tests/unit') diff --git a/editors/code/tests/unit/launch_config.test.ts b/editors/code/tests/unit/launch_config.test.ts index d5cf1b74e..68794d53e 100644 --- a/editors/code/tests/unit/launch_config.test.ts +++ b/editors/code/tests/unit/launch_config.test.ts @@ -1,25 +1,25 @@ import * as assert from 'assert'; -import * as cargo from '../../src/cargo'; +import { Cargo } from '../../src/toolchain'; suite('Launch configuration', () => { suite('Lens', () => { test('A binary', async () => { - const args = cargo.artifactSpec(["build", "--package", "pkg_name", "--bin", "pkg_name"]); + 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"]); + 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"]); + 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); @@ -28,7 +28,7 @@ suite('Launch configuration', () => { suite('QuickPick', () => { test('A binary', async () => { - const args = cargo.artifactSpec(["run", "--package", "pkg_name", "--bin", "pkg_name"]); + 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); @@ -36,14 +36,14 @@ suite('Launch configuration', () => { test('One of Multiple Binaries', async () => { - const args = cargo.artifactSpec(["run", "--package", "pkg_name", "--bin", "bin2"]); + 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"]); + 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