Skip to content

Commit

Permalink
test: remove unnecessary test, add new test, fix coverage on windows
Browse files Browse the repository at this point in the history
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:
mochajs/mocha#4372
  • Loading branch information
tal-sapan committed Jan 18, 2021
1 parent 9ec6f82 commit 7b46cb7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 0 additions & 6 deletions tests/commands/mtaBuildCommand.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
18 changes: 18 additions & 0 deletions tests/utils/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<string>
>)
.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);
Expand Down

0 comments on commit 7b46cb7

Please sign in to comment.