https://github.com/da-viper created 
https://github.com/llvm/llvm-project/pull/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.


Follow up from 
https://github.com/llvm/llvm-project/pull/162635#discussion_r2486112688

>From 8f0182e1d01e9553c5e409869af70e796c8ed477 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <[email protected]>
Date: Thu, 1 Jan 2026 12:38:54 +0000
Subject: [PATCH] [lldb-dap][ext] Setup test for lldb-dap extension

include the test folder in when formatting
---
 lldb/tools/lldb-dap/extension/.prettierignore |  9 ++++
 .../tools/lldb-dap/extension/.vscode-test.mjs |  8 ++++
 lldb/tools/lldb-dap/extension/package.json    |  9 +++-
 lldb/tools/lldb-dap/extension/src/utils.ts    | 12 ++---
 .../extension/test/unit/expandUser.test.ts    | 44 +++++++++++++++++++
 lldb/tools/lldb-dap/extension/tsconfig.json   | 11 ++---
 6 files changed, 78 insertions(+), 15 deletions(-)
 create mode 100644 lldb/tools/lldb-dap/extension/.prettierignore
 create mode 100644 lldb/tools/lldb-dap/extension/.vscode-test.mjs
 create mode 100644 lldb/tools/lldb-dap/extension/test/unit/expandUser.test.ts

diff --git a/lldb/tools/lldb-dap/extension/.prettierignore 
b/lldb/tools/lldb-dap/extension/.prettierignore
new file mode 100644
index 0000000000000..f553e11245428
--- /dev/null
+++ b/lldb/tools/lldb-dap/extension/.prettierignore
@@ -0,0 +1,9 @@
+# ignore build artefacts
+node_folder/
+out/
+.vscode-test/
+
+# user settings
+.vscode
+
+package-lock.json
diff --git a/lldb/tools/lldb-dap/extension/.vscode-test.mjs 
b/lldb/tools/lldb-dap/extension/.vscode-test.mjs
new file mode 100644
index 0000000000000..bf53eda27f3d8
--- /dev/null
+++ b/lldb/tools/lldb-dap/extension/.vscode-test.mjs
@@ -0,0 +1,8 @@
+import { defineConfig } from "@vscode/test-cli";
+
+export default defineConfig([
+  {
+    label: "unitTests",
+    files: "out/test/unit/**/*.test.js",
+  },
+]);
diff --git a/lldb/tools/lldb-dap/extension/package.json 
b/lldb/tools/lldb-dap/extension/package.json
index 781ab65364bd4..bcc38aec260d6 100644
--- a/lldb/tools/lldb-dap/extension/package.json
+++ b/lldb/tools/lldb-dap/extension/package.json
@@ -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"
   },
diff --git a/lldb/tools/lldb-dap/extension/src/utils.ts 
b/lldb/tools/lldb-dap/extension/src/utils.ts
index efebe0b0f42ba..310642175abae 100644
--- a/lldb/tools/lldb-dap/extension/src/utils.ts
+++ b/lldb/tools/lldb-dap/extension/src/utils.ts
@@ -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;
   }
 
diff --git a/lldb/tools/lldb-dap/extension/test/unit/expandUser.test.ts 
b/lldb/tools/lldb-dap/extension/test/unit/expandUser.test.ts
new file mode 100644
index 0000000000000..566495ec19b66
--- /dev/null
+++ b/lldb/tools/lldb-dap/extension/test/unit/expandUser.test.ts
@@ -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");
+  });
+});
diff --git a/lldb/tools/lldb-dap/extension/tsconfig.json 
b/lldb/tools/lldb-dap/extension/tsconfig.json
index c2d0f2d65a2ad..548fc0202e4d7 100644
--- a/lldb/tools/lldb-dap/extension/tsconfig.json
+++ b/lldb/tools/lldb-dap/extension/tsconfig.json
@@ -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"]
 }

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to