Skip to content

Commit 89169fa

Browse files
committed
feat: save files on run
1 parent 8b146e2 commit 89169fa

4 files changed

Lines changed: 16 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ dist
104104
.tern-port
105105

106106
yarn.lock
107+
package-lock.json
107108
*.vsix
108109

109110
.DS_Store

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vscode-vitest",
33
"displayName": "Vitest Runner for VSCode that actually work",
4-
"version": "0.0.1",
4+
"version": "0.1.0",
55
"main": "dist/index.js",
66
"icon": "logo.png",
77
"license": "MIT",

src/run.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function buildVitestArgs({ caseName, casePath, sanitize = true }: { caseName: st
1919
caseName = JSON.stringify(caseName);
2020
}
2121

22-
const args = ['vitest', 'run', '-t', caseName, sanitizedCasePath];
22+
const args = ['vitest', 'run', '--testNamePattern', caseName, sanitizedCasePath];
2323

2424
const rootDir = getCwd(casePath);
2525
if (rootDir) {
@@ -31,7 +31,11 @@ function buildVitestArgs({ caseName, casePath, sanitize = true }: { caseName: st
3131

3232
let terminal: vscode.Terminal | undefined;
3333

34-
export function runInTerminal(text: string, filename: string) {
34+
async function saveFile(filePath: string) {
35+
await vscode.workspace.textDocuments.find((doc) => doc.fileName === filePath)?.save();
36+
}
37+
38+
export async function runInTerminal(text: string, filename: string) {
3539
let terminalAlreadyExists = true;
3640
if (!terminal || terminal.exitStatus) {
3741
terminalAlreadyExists = false;
@@ -47,6 +51,8 @@ export function runInTerminal(text: string, filename: string) {
4751
terminal.sendText('\x03');
4852
}
4953

54+
await saveFile(filename);
55+
5056
terminal.sendText(npxArgs.join(' '), true);
5157
terminal.show();
5258
}
@@ -68,7 +74,9 @@ function buildDebugConfig(
6874
};
6975
}
7076

71-
export function debugInTermial(text: string, filename: string) {
77+
export async function debugInTerminal(text: string, filename: string) {
7278
const config = buildDebugConfig(filename, text);
79+
80+
await saveFile(filename);
7381
vscode.debug.startDebugging(undefined, config);
7482
}

src/vscode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from 'vscode';
2-
import { debugInTermial, runInTerminal } from './run';
2+
import { debugInTerminal, runInTerminal } from './run';
33

44
export class RunVitestCommand implements vscode.Command {
55
static ID = 'vitest.runTest';
@@ -26,13 +26,13 @@ export class DebugVitestCommand implements vscode.Command {
2626
vscode.commands.registerCommand(
2727
RunVitestCommand.ID,
2828
(text: string, filename: string) => {
29-
runInTerminal(text, filename);
29+
runInTerminal(text, filename)
3030
}
3131
);
3232

3333
vscode.commands.registerCommand(
3434
DebugVitestCommand.ID,
3535
(text: string, filename: string) => {
36-
debugInTermial(text, filename);
36+
debugInTerminal(text, filename);
3737
}
3838
);

0 commit comments

Comments
 (0)