Skip to content

Commit

Permalink
Do Not Fully Initialize Assay if Not In Workspace (#134)
Browse files Browse the repository at this point in the history
* If workspace does not exist, do not lint

* prettier

* test

* testing
  • Loading branch information
chrstinalin authored Oct 17, 2024
1 parent 54d6a0a commit 799dfbf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
8 changes: 3 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,9 @@ export async function activate(context: vscode.ExtensionContext) {
// Do not launch commenting system if not in the rootFolder.
// Still allows Assay to be launched to use other commands (setup, installs).
const workspace = vscode.workspace.workspaceFolders;
if (workspace) {
const uri = workspace[0].uri;
if (!(await directoryController.inRoot(uri))) {
return;
}

if (!workspace || !(await directoryController.inRoot(workspace[0].uri))) {
return;
}

await vscode.commands.executeCommand(
Expand Down
39 changes: 26 additions & 13 deletions test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import * as fs from "fs";
import { describe, it, afterEach, beforeEach } from "mocha";
import { describe, it, afterEach } from "mocha";
import * as sinon from "sinon";
import * as vscode from "vscode";

Expand All @@ -20,18 +20,6 @@ function makeContext() {
}

describe("extension.ts", () => {
beforeEach(() => {
const workspaceFoldersStub = sinon.stub(
vscode.workspace,
"workspaceFolders"
);
workspaceFoldersStub.value([
{
uri: vscode.Uri.parse("test-root-uri"),
},
]);
});

afterEach(() => {
sinon.restore();
});
Expand All @@ -42,6 +30,16 @@ describe("extension.ts", () => {
});

it("should load the manifest if launched with the intention to do so.", async () => {
const workspaceFoldersStub = sinon.stub(
vscode.workspace,
"workspaceFolders"
);
workspaceFoldersStub.value([
{
uri: vscode.Uri.parse("test-root-uri"),
},
]);

const directoryControllerStub = sinon.stub(
DirectoryController.prototype,
"getRootFolderPath"
Expand Down Expand Up @@ -73,4 +71,19 @@ describe("extension.ts", () => {
expect(openCachedFileStub.calledOnce).to.be.true;
expect(context.subscriptions.length).to.be.greaterThan(10);
});

it("should return early if no workspace is available", async () => {
const directoryControllerStub = sinon.stub(
DirectoryController.prototype,
"getRootFolderPath"
);
directoryControllerStub.resolves("test");

const context = makeContext();
sinon.stub(context.globalState, "get").withArgs("filePath").returns("test");

const executeCommandStub = sinon.stub(vscode.commands, "executeCommand");
await activate(context);
expect(executeCommandStub.calledOnce).to.be.true;
});
});

0 comments on commit 799dfbf

Please sign in to comment.