Skip to content

Commit 9071ecf

Browse files
committed
Fix tests.
1 parent bd6d0b1 commit 9071ecf

File tree

11 files changed

+30
-82
lines changed

11 files changed

+30
-82
lines changed

.vscode-test.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from "@vscode/test-cli";
2+
3+
export default defineConfig([
4+
{
5+
label: "unitTests",
6+
files: "out/test/**/*.test.js",
7+
workspaceFolder: "./test-workspaces/npm-buf-workspace",
8+
},
9+
]);

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"--extensionDevelopmentPath=${workspaceFolder}"
1515
],
1616
"outFiles": ["${workspaceFolder}/out/**/*.js"],
17-
"preLaunchTask": "${defaultBuildTask}"
17+
"preLaunchTask": "npm: watch"
1818
},
1919
{
2020
"name": "Extension Tests",

.vscode/tasks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": "2.0.0",
55
"tasks": [
66
{
7+
"label": "npm: watch",
78
"type": "npm",
89
"script": "watch",
910
"problemMatcher": "$tsc-watch",

package-lock.json

Lines changed: 2 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,12 @@
216216
"pretest": "npm run compile && npm run prepworkspaces",
217217
"prepworkspaces": "(cd test-workspaces/npm-buf-workspace && npm install)",
218218
"lint": "eslint --max-warnings 0 .",
219-
"test": "npm run test-compile && node ./out/test/run-test.js",
219+
"test": "vscode-test",
220220
"package": "vsce package",
221221
"format": "prettier --write '**/*.{json,js,jsx,ts,tsx,css,yaml,yml,mjs,mts,md}' --log-level error"
222222
},
223223
"devDependencies": {
224224
"@eslint/js": "^9.23.0",
225-
"@types/glob": "^8.1.0",
226225
"@types/mocha": "^10.0.6",
227226
"@types/node": "^20.x",
228227
"@types/proxyquire": "^1.3.31",
@@ -237,7 +236,6 @@
237236
"@vscode/vsce": "^2.15.0",
238237
"eslint": "^9.23.0",
239238
"eslint-plugin-unicorn": "^58.0.0",
240-
"glob": "^11.0.1",
241239
"globals": "^16.0.0",
242240
"mocha": "^10.2.0",
243241
"prettier": "^3.5.3",
@@ -252,4 +250,4 @@
252250
"vscode-languageclient": "^9.0.1",
253251
"which": "^5.0.0"
254252
}
255-
}
253+
}

test/mocks/mock-context.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as vscode from "vscode";
2+
13
import { Disposable, ExtensionContext } from "vscode";
24

35
export type ExtensionContextPlus = ExtensionContext &
@@ -6,6 +8,8 @@ export type ExtensionContextPlus = ExtensionContext &
68
export class MockExtensionContext implements Partial<ExtensionContext> {
79
subscriptions: Disposable[] = [];
810

11+
globalStorageUri?: vscode.Uri | undefined = vscode.Uri.file("/path/to/buf");
12+
913
static new(): ExtensionContextPlus {
1014
return new this() as unknown as ExtensionContextPlus;
1115
}

test/run-test.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

test/unit/commands/find-buf.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ suite("commands.findBuf", () => {
6262

6363
whichStub = sandbox.stub();
6464

65-
findBufMod = proxyquire("../../../src/commands/findBuf", {
65+
findBufMod = proxyquire("../../../src/commands/find-buf", {
6666
which: whichStub,
6767
});
6868

@@ -112,7 +112,7 @@ suite("commands.findBuf", () => {
112112
const storagePath = "/path/to/storage";
113113
const bufPath = path.join(storagePath, "v1", bufFilename);
114114

115-
sandbox.spy(ctx, "globalStorageUri", ["get"]).get().returns({
115+
sandbox.stub(ctx, "globalStorageUri").value({
116116
fsPath: storagePath,
117117
});
118118
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -132,7 +132,7 @@ suite("commands.findBuf", () => {
132132
whichStub.returns(bufPath);
133133

134134
const storagePath = "/path/to/storage";
135-
sandbox.spy(ctx, "globalStorageUri", ["get"]).get().returns({
135+
sandbox.stub(ctx, "globalStorageUri").value({
136136
fsPath: storagePath,
137137
});
138138

test/unit/commands/install-buf.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ suite("commands.installBuf", () => {
134134
sandbox.stub(github, "findAsset").resolves(dummyAsset);
135135

136136
const storagePath = "/path/to/storage";
137-
sandbox.spy(ctx, "globalStorageUri", ["get"]).get().returns({
137+
sandbox.stub(ctx, "globalStorageUri").value({
138138
fsPath: storagePath,
139139
});
140140

test/unit/status.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "../mocks/mock-context";
1010
import { BufContext } from "../../src/context";
1111

12-
describe("status", function () {
12+
suite("status", function () {
1313
vscode.window.showInformationMessage("Start all status tests.");
1414

1515
let sandbox: sinon.SinonSandbox;
@@ -64,11 +64,11 @@ describe("status", function () {
6464
status.disposeStatusBar();
6565
});
6666

67-
it("activate creates an output channel", function () {
67+
test("activate creates an output channel", function () {
6868
assert.strictEqual(createOutputChannelStub.callCount, 1);
6969
});
7070

71-
it("activate sets up subscriptions", function () {
71+
test("activate sets up subscriptions", function () {
7272
assert.strictEqual(ctx.subscriptions.length, 2);
7373
assert.strictEqual(bufCtxonDidChangeContextSpy.get.calledOnce, true);
7474
});

0 commit comments

Comments
 (0)