mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-11 22:51:26 +00:00
Fix test configuration and add basic tests
This commit is contained in:
parent
6ef15cfdfb
commit
d8080d7209
5 changed files with 85 additions and 7 deletions
|
|
@ -1,5 +1,8 @@
|
|||
import { defineConfig } from "@vscode/test-cli"
|
||||
|
||||
export default defineConfig({
|
||||
files: "out/test/**/*.test.js",
|
||||
files: "out/**/*.test.js",
|
||||
mocha: {
|
||||
timeout: 20000, // Maximum time (in ms) that a test can run before failing
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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 . --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",
|
||||
|
|
|
|||
|
|
@ -5,11 +5,25 @@ import * as assert from "assert"
|
|||
import * as vscode from "vscode"
|
||||
// import * as myExtension from '../../extension';
|
||||
|
||||
suite("Extension Test Suite", () => {
|
||||
vscode.window.showInformationMessage("Start all tests.")
|
||||
import { readFile } from "fs/promises"
|
||||
import path from "path"
|
||||
|
||||
test("Sample test", () => {
|
||||
assert.strictEqual(-1, [1, 2, 3].indexOf(5))
|
||||
assert.strictEqual(-1, [1, 2, 3].indexOf(0))
|
||||
const packagePath = path.join(__dirname, "..", "..", "..", "package.json")
|
||||
|
||||
suite("Extension Test Suite", () => {
|
||||
suiteTeardown(() => {
|
||||
vscode.window.showInformationMessage("All tests done!")
|
||||
})
|
||||
|
||||
test("Sanity check", 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)
|
||||
})
|
||||
|
||||
test("Ensure that the extension is correctly loaded by running a command", async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 400))
|
||||
await vscode.commands.executeCommand("cline.plusButtonClicked")
|
||||
})
|
||||
})
|
||||
|
|
|
|||
48
src/utils/path.test.ts
Normal file
48
src/utils/path.test.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import * as assert from "assert"
|
||||
import * as path from "path"
|
||||
import * as os from "os"
|
||||
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)
|
||||
})
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
|
||||
test("arePathsEqual handles normalized paths", () => {
|
||||
assert.strictEqual(arePathsEqual("/tmp/./dir", "/tmp/../tmp/dir"), true)
|
||||
assert.strictEqual(arePathsEqual("/tmp/./dir", "/tmp/../dir"), 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, "/"))
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
13
tsconfig.test.json
Normal file
13
tsconfig.test.json
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
// This separate tsconfig is necessary because VS Code's test runner requires CommonJS modules,
|
||||
// while our main project uses ES Modules (ESM). This config inherits most settings from the base
|
||||
// tsconfig.json but overrides the module system for test files only. This doesn't affect how
|
||||
// tests interact with the main codebase - it only changes how the test files themselves are
|
||||
// compiled to make them compatible with VS Code's test runner.
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"include": ["src/**/*.test.ts"]
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue