Skip to content

Commit

Permalink
feat: save files on run
Browse files Browse the repository at this point in the history
  • Loading branch information
rluvaton committed Aug 3, 2023
1 parent 8b146e2 commit 89169fa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ dist
.tern-port

yarn.lock
package-lock.json
*.vsix

.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-vitest",
"displayName": "Vitest Runner for VSCode that actually work",
"version": "0.0.1",
"version": "0.1.0",
"main": "dist/index.js",
"icon": "logo.png",
"license": "MIT",
Expand Down
14 changes: 11 additions & 3 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function buildVitestArgs({ caseName, casePath, sanitize = true }: { caseName: st
caseName = JSON.stringify(caseName);
}

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

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

let terminal: vscode.Terminal | undefined;

export function runInTerminal(text: string, filename: string) {
async function saveFile(filePath: string) {
await vscode.workspace.textDocuments.find((doc) => doc.fileName === filePath)?.save();
}

export async function runInTerminal(text: string, filename: string) {
let terminalAlreadyExists = true;
if (!terminal || terminal.exitStatus) {
terminalAlreadyExists = false;
Expand All @@ -47,6 +51,8 @@ export function runInTerminal(text: string, filename: string) {
terminal.sendText('\x03');
}

await saveFile(filename);

terminal.sendText(npxArgs.join(' '), true);
terminal.show();
}
Expand All @@ -68,7 +74,9 @@ function buildDebugConfig(
};
}

export function debugInTermial(text: string, filename: string) {
export async function debugInTerminal(text: string, filename: string) {
const config = buildDebugConfig(filename, text);

await saveFile(filename);
vscode.debug.startDebugging(undefined, config);
}
6 changes: 3 additions & 3 deletions src/vscode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import { debugInTermial, runInTerminal } from './run';
import { debugInTerminal, runInTerminal } from './run';

export class RunVitestCommand implements vscode.Command {
static ID = 'vitest.runTest';
Expand All @@ -26,13 +26,13 @@ export class DebugVitestCommand implements vscode.Command {
vscode.commands.registerCommand(
RunVitestCommand.ID,
(text: string, filename: string) => {
runInTerminal(text, filename);
runInTerminal(text, filename)
}
);

vscode.commands.registerCommand(
DebugVitestCommand.ID,
(text: string, filename: string) => {
debugInTermial(text, filename);
debugInTerminal(text, filename);
}
);

0 comments on commit 89169fa

Please sign in to comment.