Skip to content

Commit

Permalink
Use should for better test readability
Browse files Browse the repository at this point in the history
  • Loading branch information
saoudrizwan committed Dec 25, 2024
1 parent d8080d7 commit 06dab2c
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 52 deletions.
73 changes: 71 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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": {
Expand Down
21 changes: 9 additions & 12 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
@@ -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")
})
Expand Down
77 changes: 41 additions & 36 deletions src/utils/path.test.ts
Original file line number Diff line number Diff line change
@@ -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()
})

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)
}
})
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()
}
})

test("arePathsEqual handles normalized paths", () => {
assert.strictEqual(arePathsEqual("/tmp/./dir", "/tmp/../tmp/dir"), true)
assert.strictEqual(arePathsEqual("/tmp/./dir", "/tmp/../dir"), false)
it("should handle normalized paths", () => {
arePathsEqual("/tmp/./dir", "/tmp/../tmp/dir").should.be.true()
arePathsEqual("/tmp/./dir", "/tmp/../dir").should.be.false()
})
})

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, "/"))
})
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("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")
})
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 shows basename when path equals cwd", () => {
const cwd = "/home/user/project"
assert.strictEqual(getReadablePath(cwd, cwd), "project")
})
it("should show basename when path equals cwd", () => {
const cwd = "/home/user/project"
getReadablePath(cwd, cwd).should.equal("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)
})
})
})
3 changes: 2 additions & 1 deletion tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node"
"moduleResolution": "node",
"types": ["node", "mocha", "vscode"]
},
"include": ["src/**/*.test.ts"]
}

0 comments on commit 06dab2c

Please sign in to comment.