Skip to content

Commit

Permalink
chore: update to latest bun + add custom flag support
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgja committed Oct 19, 2024
1 parent c52fdba commit b7f2ee7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/bun-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
"type": "string",
"default": "**/*.{test,spec}.{js,ts,tsx,jsx}",
"description": "Glob pattern to match test files (e.g., **/*.test.{js,ts,tsx,jsx})"
},
"bun.test.customFlag": {
"type": "string",
"default": "",
"description": "Custom flag added to the end of test command"
}
}
},
Expand Down
10 changes: 8 additions & 2 deletions packages/bun-vscode/src/features/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export function registerTestCodeLens(context: vscode.ExtensionContext) {
const codeLensProvider = new TestCodeLensProvider();

// Get the user-defined file pattern from the settings, or use the default
// Setting is: bun.test.filePattern
// Setting is:
// bun.test.filePattern
const pattern = vscode.workspace.getConfiguration("bun.test").get("filePattern", DEFAULT_FILE_PATTERN);
const options = { scheme: "file", pattern };

Expand All @@ -102,10 +103,15 @@ let activeTerminal: vscode.Terminal | null = null;
*/
export function registerTestRunner(context: vscode.ExtensionContext) {



// Register the "Run Test" command
const runTestCommand = vscode.commands.registerCommand(
"extension.bun.runTest",
async (fileName?: string, testName?: string, watchMode: boolean = false) => {

// Get custom flag
const customFlag = vscode.workspace.getConfiguration("bun.test").get("customFlag", "");
// 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 @@ -124,7 +130,7 @@ export function registerTestRunner(context: vscode.ExtensionContext) {
activeTerminal.show();
const watchFlag = watchMode ? "--watch" : "";
const testNameIfExist = testName ? ` -t "${testName}"` : "";
activeTerminal.sendText(`bun test ${fileName} ${testNameIfExist} ${watchFlag}`);
activeTerminal.sendText(`bun test ${fileName} ${testNameIfExist} ${watchFlag} ${customFlag}`);
},
);

Expand Down

0 comments on commit b7f2ee7

Please sign in to comment.