Skip to content

Commit

Permalink
feat(vscode-extension) adding new helpful commands
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgja committed Oct 19, 2024
1 parent db9011e commit a02b7b0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/bun-vscode/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"scripts": {
"run": "node hello.js",
"start": "hello.js",
"test":"bun test",
"start:bun": "bun hello.js",
"start:bun:quotes": "bun run hello.js"
},
Expand Down
5 changes: 5 additions & 0 deletions packages/bun-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
"type": "string",
"default": "",
"description": "Custom flag added to the end of test command"
},
"bun.test.customScript": {
"type": "string",
"default": "",
"description": "Custom script to use instead of `bun test`, for example script from `package.json`"
}
}
},
Expand Down
3 changes: 0 additions & 3 deletions packages/bun-vscode/scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { buildSync } from "esbuild";
import { execSync } from "node:child_process";
import { cpSync, mkdirSync, rmSync } from "node:fs";
import { dirname } from "node:path";

process.chdir(dirname(import.meta.dirname));

buildSync({
entryPoints: ["src/extension.ts", "src/web-extension.ts"],
Expand Down
26 changes: 22 additions & 4 deletions packages/bun-vscode/src/features/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export function registerTestRunner(context: vscode.ExtensionContext) {
async (fileName?: string, testName?: string, watchMode: boolean = false) => {

// Get custom flag
const customFlag = vscode.workspace.getConfiguration("bun.test").get("customFlag", "");
const customFlag = vscode.workspace.getConfiguration("bun.test").get("customFlag", "").trim();
const customScriptSetting = vscode.workspace.getConfiguration("bun.test").get("customScript", "bun test").trim();
const customScript = customScriptSetting.length ? customScriptSetting : "bun test";
// When this command is called from the command palette, the fileName and testName arguments are not passed (commands in package.json)
// so then fileName is taken from the active text editor and it run for the whole file.
if (!fileName) {
Expand All @@ -128,9 +130,25 @@ export function registerTestRunner(context: vscode.ExtensionContext) {

activeTerminal = vscode.window.createTerminal("Bun Test Runner");
activeTerminal.show();
const watchFlag = watchMode ? "--watch" : "";
const testNameIfExist = testName ? ` -t "${testName}"` : "";
activeTerminal.sendText(`bun test ${fileName} ${testNameIfExist} ${watchFlag} ${customFlag}`);
let command = customScript;
if (fileName.length) {
command += ` ${fileName}`;
}
if (testName.length) {
if (customScriptSetting.length) {
// escape the quotes in the test name
command += ` -t \\"${testName}\\"`;
} else {
command += ` -t "${testName}"`;
}
}
if (watchMode) {
command += ` --watch`;
}
if (customFlag.length) {
command += ` ${customFlag}`;
}
activeTerminal.sendText(command);
},
);

Expand Down

0 comments on commit a02b7b0

Please sign in to comment.