From 7b46cb7b7bce7d3b2983c57fde0f4cf457d435b7 Mon Sep 17 00:00:00 2001 From: Tal Sapan Date: Mon, 18 Jan 2021 18:48:34 +0200 Subject: [PATCH] test: remove unnecessary test, add new test, fix coverage on windows The unnecessary test fails in environments where mbt is installed, and it only passed because the check for mbt existance returned false. Coverage does not work on Windows when Mocha runs in parallel: https://github.com/mochajs/mocha/issues/4372 --- package.json | 4 ++-- tests/commands/mtaBuildCommand.spec.ts | 6 ------ tests/utils/utils.spec.ts | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 4f3fed1..233be94 100644 --- a/package.json +++ b/package.json @@ -136,8 +136,8 @@ "format:validate": "prettier --check --ignore-path .gitignore \"**/*.@(ts|js|json|md|yml)\"", "lint": "eslint . --ext .ts --fix --max-warnings=0", "build": "vsce package", - "test": "nyc mocha -p tsconfig.json", - "coverage:check": "nyc mocha -p tsconfig.json", + "test": "nyc mocha", + "coverage:check": "nyc mocha", "vscode:prepublish": "webpack --mode production", "webpack": "webpack --mode development", "webpack:watch": "webpack --mode development --watch" diff --git a/tests/commands/mtaBuildCommand.spec.ts b/tests/commands/mtaBuildCommand.spec.ts index 9a23220..8a54840 100644 --- a/tests/commands/mtaBuildCommand.spec.ts +++ b/tests/commands/mtaBuildCommand.spec.ts @@ -217,10 +217,4 @@ describe("MTA build command unit tests", () => { windowMock.expects("showErrorMessage").withExactArgs(messages.INSTALL_MBT); await mtaBuildCommand.mtaBuildCommand(selected as Uri, swa); }); - - it("mtaBuildCommand - tracking throws error", async () => { - sandbox.stub(SWATracker.prototype, "track").throws(new Error("error")); - tasksMock.expects("executeTask").never(); - await mtaBuildCommand.mtaBuildCommand(selected as Uri, swa); - }); }); diff --git a/tests/utils/utils.spec.ts b/tests/utils/utils.spec.ts index 70d2f74..4bebecd 100644 --- a/tests/utils/utils.spec.ts +++ b/tests/utils/utils.spec.ts @@ -6,6 +6,7 @@ import * as sinon from "sinon"; import { Utils } from "../../src/utils/utils"; import { SelectionItem } from "../../src/utils/selectionItem"; import { IChildLogger } from "@vscode-logging/logger"; +import * as fsExtra from "fs-extra"; describe("Utils unit tests", () => { const path1 = "some/path/to/file1"; @@ -94,6 +95,23 @@ describe("Utils unit tests", () => { expect(response).to.equal(undefined); }); + it("getConfigFileField - fetch field from existing config file", async () => { + utilsMock + .expects("getConfigFilePath") + .once() + .returns("path/to/existing/file"); + // Converting SinonStub because it takes the wrong overload + ((sinon.stub(fsExtra, "readFile") as unknown) as sinon.SinonStub< + [string, string], + Promise + >) + .withArgs("path/to/existing/file", "utf8") + .resolves(`{"field1":"field1_value"}`); + + const response = await Utils.getConfigFileField("field1", loggerImpl); + expect(response).to.equal("field1_value"); + }); + it("getFilePaths - get paths of a non windows platform", () => { const filePaths = [{ path: path1 } as Uri, { path: path2 } as Uri]; sandbox.stub(Utils, "isWindows").returns(false);