Use should for better test readability

This commit is contained in:
Saoud Rizwan 2024-12-24 18:11:11 -08:00
parent d8080d7209
commit 06dab2c3df
5 changed files with 128 additions and 54 deletions

73
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "claude-dev",
"version": "2.2.2",
"version": "3.0.4",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "claude-dev",
"version": "2.2.2",
"version": "3.0.4",
"license": "Apache-2.0",
"dependencies": {
"@anthropic-ai/bedrock-sdk": "^0.10.2",
@ -48,6 +48,7 @@
"@types/diff": "^5.2.1",
"@types/mocha": "^10.0.7",
"@types/node": "20.x",
"@types/should": "^11.2.0",
"@types/vscode": "^1.84.0",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.11.0",
@ -57,6 +58,7 @@
"eslint": "^8.57.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.3.3",
"should": "^13.2.3",
"typescript": "^5.4.5"
},
"engines": {
@ -4589,6 +4591,13 @@
"integrity": "sha512-7i+zxXdPD0T4cKDuxCUXJ4wHcsJLwENa6Z3dCu8cfCK743OGy5Nu1RmAGqDPsoTDINVEcdXKRvR/zre+P2Ku1A==",
"license": "MIT"
},
"node_modules/@types/should": {
"version": "11.2.0",
"resolved": "https://registry.npmjs.org/@types/should/-/should-11.2.0.tgz",
"integrity": "sha512-+J77XoXmKIXcLK5fWS5B3j31F4wfdclzk+lRxFcKfXTHzZfd153u8w96W30dQBIT4kwKobjvYa0kIb0BWJX21Q==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/turndown": {
"version": "5.0.5",
"resolved": "https://registry.npmjs.org/@types/turndown/-/turndown-5.0.5.tgz",
@ -10365,6 +10374,66 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/should": {
"version": "13.2.3",
"resolved": "https://registry.npmjs.org/should/-/should-13.2.3.tgz",
"integrity": "sha512-ggLesLtu2xp+ZxI+ysJTmNjh2U0TsC+rQ/pfED9bUZZ4DKefP27D+7YJVVTvKsmjLpIi9jAa7itwDGkDDmt1GQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"should-equal": "^2.0.0",
"should-format": "^3.0.3",
"should-type": "^1.4.0",
"should-type-adaptors": "^1.0.1",
"should-util": "^1.0.0"
}
},
"node_modules/should-equal": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/should-equal/-/should-equal-2.0.0.tgz",
"integrity": "sha512-ZP36TMrK9euEuWQYBig9W55WPC7uo37qzAEmbjHz4gfyuXrEUgF8cUvQVO+w+d3OMfPvSRQJ22lSm8MQJ43LTA==",
"dev": true,
"license": "MIT",
"dependencies": {
"should-type": "^1.4.0"
}
},
"node_modules/should-format": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/should-format/-/should-format-3.0.3.tgz",
"integrity": "sha512-hZ58adtulAk0gKtua7QxevgUaXTTXxIi8t41L3zo9AHvjXO1/7sdLECuHeIN2SRtYXpNkmhoUP2pdeWgricQ+Q==",
"dev": true,
"license": "MIT",
"dependencies": {
"should-type": "^1.3.0",
"should-type-adaptors": "^1.0.1"
}
},
"node_modules/should-type": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/should-type/-/should-type-1.4.0.tgz",
"integrity": "sha512-MdAsTu3n25yDbIe1NeN69G4n6mUnJGtSJHygX3+oN0ZbO3DTiATnf7XnYJdGT42JCXurTb1JI0qOBR65shvhPQ==",
"dev": true,
"license": "MIT"
},
"node_modules/should-type-adaptors": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/should-type-adaptors/-/should-type-adaptors-1.1.0.tgz",
"integrity": "sha512-JA4hdoLnN+kebEp2Vs8eBe9g7uy0zbRo+RMcU0EsNy+R+k049Ki+N5tT5Jagst2g7EAja+euFuoXFCa8vIklfA==",
"dev": true,
"license": "MIT",
"dependencies": {
"should-type": "^1.3.0",
"should-util": "^1.0.0"
}
},
"node_modules/should-util": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/should-util/-/should-util-1.0.1.tgz",
"integrity": "sha512-oXF8tfxx5cDk8r2kYqlkUJzZpDBqVY/II2WhvU0n9Y3XYvAYRmeaf1PvvIvTgPnv4KJ+ES5M0PyDq5Jp+Ygy2g==",
"dev": true,
"license": "MIT"
},
"node_modules/side-channel": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz",

View file

@ -133,7 +133,7 @@
"watch:esbuild": "node esbuild.js --watch",
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
"package": "npm run build:webview && npm run check-types && npm run lint && node esbuild.js --production",
"compile-tests": "tsc -p ./tsconfig.test.json --outDir out",
"compile-tests": "tsc -p ./tsconfig.test.json --outDir out",
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "npm run compile-tests && npm run compile && npm run lint",
"check-types": "tsc --noEmit",
@ -151,6 +151,7 @@
"@types/diff": "^5.2.1",
"@types/mocha": "^10.0.7",
"@types/node": "20.x",
"@types/should": "^11.2.0",
"@types/vscode": "^1.84.0",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.11.0",
@ -160,6 +161,7 @@
"eslint": "^8.57.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.3.3",
"should": "^13.2.3",
"typescript": "^5.4.5"
},
"dependencies": {

View file

@ -1,28 +1,25 @@
import * as assert from "assert"
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from "vscode"
// import * as myExtension from '../../extension';
import { readFile } from "fs/promises"
import { describe, it, after } from "mocha"
import path from "path"
import "should"
import * as vscode from "vscode"
const packagePath = path.join(__dirname, "..", "..", "..", "package.json")
suite("Extension Test Suite", () => {
suiteTeardown(() => {
describe("Cline Extension", () => {
after(() => {
vscode.window.showInformationMessage("All tests done!")
})
test("Sanity check", async () => {
it("should verify extension ID matches package.json", async () => {
const packageJSON = JSON.parse(await readFile(packagePath, "utf8"))
const id = packageJSON.publisher + "." + packageJSON.name
const clineExtensionApi = vscode.extensions.getExtension(id)
assert.equal(clineExtensionApi?.id, id)
clineExtensionApi?.id.should.equal(id)
})
test("Ensure that the extension is correctly loaded by running a command", async () => {
it("should successfully execute the plus button command", async () => {
await new Promise((resolve) => setTimeout(resolve, 400))
await vscode.commands.executeCommand("cline.plusButtonClicked")
})

View file

@ -1,48 +1,53 @@
import * as assert from "assert"
import * as path from "path"
import { describe, it } from "mocha"
import * as os from "os"
import * as path from "path"
import "should"
import { arePathsEqual, getReadablePath } from "./path"
suite("Path Utils", () => {
test("arePathsEqual handles undefined paths", () => {
assert.strictEqual(arePathsEqual(undefined, undefined), true)
assert.strictEqual(arePathsEqual("foo", undefined), false)
assert.strictEqual(arePathsEqual(undefined, "foo"), false)
describe("Path Utilities", () => {
describe("arePathsEqual", () => {
it("should handle undefined paths", () => {
arePathsEqual(undefined, undefined).should.be.true()
arePathsEqual("foo", undefined).should.be.false()
arePathsEqual(undefined, "foo").should.be.false()
})
it("should handle case sensitivity based on platform", () => {
if (process.platform === "win32") {
arePathsEqual("FOO/BAR", "foo/bar").should.be.true()
} else {
arePathsEqual("FOO/BAR", "foo/bar").should.be.false()
}
})
it("should handle normalized paths", () => {
arePathsEqual("/tmp/./dir", "/tmp/../tmp/dir").should.be.true()
arePathsEqual("/tmp/./dir", "/tmp/../dir").should.be.false()
})
})
test("arePathsEqual handles case sensitivity based on platform", () => {
if (process.platform === "win32") {
assert.strictEqual(arePathsEqual("FOO/BAR", "foo/bar"), true)
} else {
assert.strictEqual(arePathsEqual("FOO/BAR", "foo/bar"), false)
}
})
describe("getReadablePath", () => {
it("should handle desktop path", () => {
const desktop = path.join(os.homedir(), "Desktop")
const testPath = path.join(desktop, "test.txt")
getReadablePath(desktop, "test.txt").should.equal(testPath.replace(/\\/g, "/"))
})
test("arePathsEqual handles normalized paths", () => {
assert.strictEqual(arePathsEqual("/tmp/./dir", "/tmp/../tmp/dir"), true)
assert.strictEqual(arePathsEqual("/tmp/./dir", "/tmp/../dir"), false)
})
it("should show relative paths within cwd", () => {
const cwd = "/home/user/project"
const filePath = "/home/user/project/src/file.txt"
getReadablePath(cwd, filePath).should.equal("src/file.txt")
})
test("getReadablePath handles desktop path", () => {
const desktop = path.join(os.homedir(), "Desktop")
const testPath = path.join(desktop, "test.txt")
assert.strictEqual(getReadablePath(desktop, "test.txt"), testPath.replace(/\\/g, "/"))
})
it("should show basename when path equals cwd", () => {
const cwd = "/home/user/project"
getReadablePath(cwd, cwd).should.equal("project")
})
test("getReadablePath shows relative paths within cwd", () => {
const cwd = "/home/user/project"
const filePath = "/home/user/project/src/file.txt"
assert.strictEqual(getReadablePath(cwd, filePath), "src/file.txt")
})
test("getReadablePath shows basename when path equals cwd", () => {
const cwd = "/home/user/project"
assert.strictEqual(getReadablePath(cwd, cwd), "project")
})
test("getReadablePath shows absolute path when outside cwd", () => {
const cwd = "/home/user/project"
const filePath = "/home/user/other/file.txt"
assert.strictEqual(getReadablePath(cwd, filePath), filePath)
it("should show absolute path when outside cwd", () => {
const cwd = "/home/user/project"
const filePath = "/home/user/other/file.txt"
getReadablePath(cwd, filePath).should.equal(filePath)
})
})
})

View file

@ -7,7 +7,8 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node"
"moduleResolution": "node",
"types": ["node", "mocha", "vscode"]
},
"include": ["src/**/*.test.ts"]
}