[lldb-dap][ext] Setup tests for lldb-dap extension (#174641)

This add the basic unit test support for the dap-extension. 
It also 
- adds a .prettierignore file to exclude folder not to format.
- Includes the test folder in when formatting.

uses `vscode-test` from
https://code.visualstudio.com/api/working-with-extensions/testing-extension#quick-setup-the-test-cli
Follow up from
https://github.com/llvm/llvm-project/pull/162635#discussion_r2486112688
This commit is contained in:
Ebuka Ezike 2026-01-08 09:56:46 +00:00 committed by GitHub
parent efe6aaeeed
commit 2573c0bcee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 78 additions and 15 deletions

View File

@ -0,0 +1,9 @@
# ignore build artefacts
node_folder/
out/
.vscode-test/
# user settings
.vscode
package-lock.json

View File

@ -0,0 +1,8 @@
import { defineConfig } from "@vscode/test-cli";
export default defineConfig([
{
label: "unitTests",
files: "out/test/unit/**/*.test.js",
},
]);

View File

@ -33,11 +33,15 @@
"devDependencies": {
"@types/node": "^18.19.41",
"@types/tabulator-tables": "^6.2.10",
"@types/mocha": "^10.0.10",
"@types/vscode": "1.75.0",
"@types/vscode-webview": "^1.57.5",
"@vscode/debugprotocol": "^1.68.0",
"@vscode/test-cli": "^0.0.12",
"@vscode/test-electron": "^2.5.2",
"@vscode/vsce": "^3.2.2",
"esbuild": "^0.25.9",
"mocha": "^10.2.0",
"prettier": "^3.4.2",
"prettier-plugin-curly": "^0.3.1",
"prettier-plugin-organize-imports": "^4.3.0",
@ -56,9 +60,12 @@
"bundle-webview": "npm run bundle-symbols-table-view && npm run bundle-tabulator",
"vscode:prepublish": "npm run bundle-webview && npm run bundle-extension",
"watch": "npm run bundle-webview && tsc -watch -p ./",
"format": "npx prettier './src/' --write",
"format": "npx prettier . --write",
"package": "rm -rf ./out && vsce package --out ./out/lldb-dap.vsix",
"compile": "tsc -p ./",
"publish": "vsce publish",
"pretest": "npm run compile",
"test": "vscode-test",
"vscode-uninstall": "code --uninstall-extension llvm-vs-code-extensions.lldb-dap",
"vscode-install": "code --install-extension ./out/lldb-dap.vsix"
},

View File

@ -5,7 +5,7 @@ import * as path from "path";
* Expands the character `~` to the user's home directory
*/
export function expandUser(file_path: string): string {
if (os.platform() == "win32") {
if (os.platform() === "win32") {
return file_path;
}
@ -18,22 +18,22 @@ export function expandUser(file_path: string): string {
}
const path_len = file_path.length;
if (path_len == 1) {
if (path_len === 1) {
return os.homedir();
}
if (file_path.charAt(1) == path.sep) {
if (file_path.charAt(1) === path.sep) {
return path.join(os.homedir(), file_path.substring(1));
}
const sep_index = file_path.indexOf(path.sep);
const user_name_end = sep_index == -1 ? file_path.length : sep_index;
const user_name_end = sep_index === -1 ? file_path.length : sep_index;
const user_name = file_path.substring(1, user_name_end);
try {
if (user_name == os.userInfo().username) {
if (user_name === os.userInfo().username) {
return path.join(os.homedir(), file_path.substring(user_name_end));
}
} catch (err) {
} catch (error) {
return file_path;
}

View File

@ -0,0 +1,44 @@
import * as assert from "assert";
import * as os from "os";
import * as process from "process";
import { expandUser } from "../../src/utils";
suite("expandUser Test", function () {
const home_env: { [key: string]: string | undefined } = {};
const local_username = os.userInfo().username;
suiteSetup(function () {
if (os.platform() === "win32") {
this.skip();
}
home_env.HOME = process.env.HOME;
process.env.HOME = "/home/buildbot";
});
suiteTeardown(function () {
process.env.HOME = home_env.HOME;
});
test("tilde ", function () {
assert.equal(expandUser("~"), "/home/buildbot");
assert.equal(expandUser("~/"), "/home/buildbot/");
assert.equal(expandUser("~/worker"), "/home/buildbot/worker");
});
test("tilde with username", function () {
assert.equal(expandUser(`~${local_username}`), "/home/buildbot");
assert.equal(expandUser(`~${local_username}/`), "/home/buildbot/");
assert.equal(expandUser(`~${local_username}/dev`), "/home/buildbot/dev");
// test unknown user
assert.notEqual(expandUser("~not_a_user"), "/home/build/bot");
});
test("empty", function () {
assert.equal(expandUser(""), "");
});
test("no tilde", function () {
assert.equal(expandUser("/home/buildbot/worker"), "/home/buildbot/worker");
});
});

View File

@ -3,16 +3,11 @@
"moduleResolution": "node",
"module": "commonjs",
"outDir": "out",
"rootDir": "src",
"rootDir": ".",
"sourceMap": true,
"strict": true,
"target": "es6"
},
"include": [
"src"
],
"exclude": [
"node_modules",
"src/webview",
]
"include": ["src", "test"],
"exclude": [".vscode-test", "node_modules", "src/webview"]
}