Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/watch command #74

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,037 changes: 1 addition & 3,036 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/codelens/TestWatchRunnerCodeLens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { CodeLens, Range, WorkspaceFolder } from "vscode";

export default class TestWatchRunnerCodeLens extends CodeLens {
constructor(
rootPath: WorkspaceFolder,
fileName: string,
testName: string,
range: Range
) {
super(range, {
arguments: [rootPath, fileName, testName],
command: "testify.run.watch",
title: "Watch Test"
});
}
}
17 changes: 17 additions & 0 deletions src/commands/watchTestCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { relative } from "path";
import { WorkspaceFolder } from "vscode";

import { getTestRunner } from "../runners/TestRunnerFactory";

async function runWatch(
rootPath: WorkspaceFolder,
fileName: string,
testName: string
) {
const relativeFilename = relative(rootPath.uri.fsPath, fileName);
const testRunner = await getTestRunner(rootPath);

testRunner.runWatch(rootPath, relativeFilename, testName);
}

export default runWatch;
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { commands, ExtensionContext, languages } from "vscode";
import debugTestCommand from "./commands/debugTestCommand";
import runTestCommand from "./commands/runTestCommand";
import watchTestCommand from "./commands/watchTestCommand";
import FILE_SELECTOR from "./constants/fileSelector";
import TestRunnerCodeLensProvider from "./providers/TestRunnerCodeLensProvider";

Expand All @@ -13,5 +14,6 @@ export function activate(context: ExtensionContext) {
);

commands.registerCommand("testify.run.test", runTestCommand);
commands.registerCommand("testify.run.watch", watchTestCommand);
commands.registerCommand("testify.debug.test", debugTestCommand);
}
1 change: 1 addition & 0 deletions src/interfaces/ITestRunnerInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface ITestRunnerInterface {
terminalProvider: TerminalProvider;
configurationProvider: ConfigurationProvider;

runWatch(rootPath: WorkspaceFolder, fileName: string, testName: string): void;
runTest(rootPath: WorkspaceFolder, fileName: string, testName: string): void;
debugTest(
rootPath: WorkspaceFolder,
Expand Down
10 changes: 9 additions & 1 deletion src/providers/TestRunnerCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CodeLens, CodeLensProvider, TextDocument, workspace } from "vscode";

import TestRunnerDebugCodeLens from "../codelens/TestDebugRunnerCodeLens";
import TestRunnerCodeLens from "../codelens/TestRunnerCodeLens";
import TestWatchRunnerCodeLens from '../codelens/TestWatchRunnerCodeLens';
import { codeParser } from "../parser/codeParser";

function getRootPath({ uri }) {
Expand All @@ -15,6 +16,13 @@ function getRootPath({ uri }) {
}

function getCodeLens(rootPath, fileName, testName, startPosition) {
const watchRunnerCodeLens = new TestWatchRunnerCodeLens(
rootPath,
fileName,
testName,
startPosition
);

const testRunnerCodeLens = new TestRunnerCodeLens(
rootPath,
fileName,
Expand All @@ -29,7 +37,7 @@ function getCodeLens(rootPath, fileName, testName, startPosition) {
startPosition
);

return [testRunnerCodeLens, debugRunnerCodeLens];
return [testRunnerCodeLens, debugRunnerCodeLens, watchRunnerCodeLens];
}

export default class TestRunnerCodeLensProvider implements CodeLensProvider {
Expand Down
30 changes: 26 additions & 4 deletions src/runners/AvaTestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,36 @@ export class AvaTestRunner implements ITestRunnerInterface {
}
}

public runWatch(
rootPath: WorkspaceFolder,
fileName: string,
testName: string
) {
const additionalArguments = this.configurationProvider.additionalArguments;
const environmentVariables =
this.configurationProvider.environmentVariables;

const command = `${this.path} ${this.transformFileName(
fileName
)} -m "${testName}" --watch ${additionalArguments}`;

const terminal = this.terminalProvider.get(
{ env: environmentVariables },
rootPath
);

terminal.sendText(command, true);
terminal.show(true);
}

public runTest(
rootPath: WorkspaceFolder,
fileName: string,
testName: string
) {
const additionalArguments = this.configurationProvider.additionalArguments;
const environmentVariables = this.configurationProvider
.environmentVariables;
const environmentVariables =
this.configurationProvider.environmentVariables;

const command = `${this.path} ${this.transformFileName(
fileName
Expand All @@ -52,8 +74,8 @@ export class AvaTestRunner implements ITestRunnerInterface {
testName: string
) {
const additionalArguments = this.configurationProvider.additionalArguments;
const environmentVariables = this.configurationProvider
.environmentVariables;
const environmentVariables =
this.configurationProvider.environmentVariables;
const skipFiles = this.configurationProvider.skipFiles;

debug.startDebugging(rootPath, {
Expand Down
30 changes: 26 additions & 4 deletions src/runners/JestTestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,36 @@ export class JestTestRunner implements ITestRunnerInterface {
}
}

public runWatch(
rootPath: WorkspaceFolder,
fileName: string,
testName: string
) {
const additionalArguments = this.configurationProvider.additionalArguments;
const environmentVariables =
this.configurationProvider.environmentVariables;

const command = `${this.path} ${this.transformFileName(
fileName
)} --testNamePattern="${testName}" --watch ${additionalArguments}`;

const terminal = this.terminalProvider.get(
{ env: environmentVariables },
rootPath
);

terminal.sendText(command, true);
terminal.show(true);
}

public runTest(
rootPath: WorkspaceFolder,
fileName: string,
testName: string
) {
const additionalArguments = this.configurationProvider.additionalArguments;
const environmentVariables = this.configurationProvider
.environmentVariables;
const environmentVariables =
this.configurationProvider.environmentVariables;

const command = `${this.path} ${this.transformFileName(
fileName
Expand All @@ -52,8 +74,8 @@ export class JestTestRunner implements ITestRunnerInterface {
testName: string
) {
const additionalArguments = this.configurationProvider.additionalArguments;
const environmentVariables = this.configurationProvider
.environmentVariables;
const environmentVariables =
this.configurationProvider.environmentVariables;
const skipFiles = this.configurationProvider.skipFiles;

debug.startDebugging(rootPath, {
Expand Down
32 changes: 25 additions & 7 deletions src/runners/MochaTestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,36 @@ export class MochaTestRunner implements ITestRunnerInterface {
}
}

public runWatch(
rootPath: WorkspaceFolder,
fileName: string,
testName: string
) {
const additionalArguments = this.configurationProvider.additionalArguments;
const environmentVariables =
this.configurationProvider.environmentVariables;

const command = `${this.path} ${fileName} --fgrep="${testName}" --watch ${additionalArguments}`;

const terminal = this.terminalProvider.get(
{ env: environmentVariables },
rootPath
);

terminal.sendText(command, true);
terminal.show(true);
}

public runTest(
rootPath: WorkspaceFolder,
fileName: string,
testName: string
) {
const additionalArguments = this.configurationProvider.additionalArguments;
const environmentVariables = this.configurationProvider
.environmentVariables;
const environmentVariables =
this.configurationProvider.environmentVariables;

const command = `${
this.path
} ${fileName} --fgrep="${testName}" ${additionalArguments}`;
const command = `${this.path} ${fileName} --fgrep="${testName}" ${additionalArguments}`;

const terminal = this.terminalProvider.get(
{ env: environmentVariables },
Expand All @@ -52,8 +70,8 @@ export class MochaTestRunner implements ITestRunnerInterface {
testName: string
) {
const additionalArguments = this.configurationProvider.additionalArguments;
const environmentVariables = this.configurationProvider
.environmentVariables;
const environmentVariables =
this.configurationProvider.environmentVariables;
const skipFiles = this.configurationProvider.skipFiles;

debug.startDebugging(rootPath, {
Expand Down
21 changes: 18 additions & 3 deletions src/runners/PlaywrightTestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ export class PlaywrightTestRunner implements ITestRunnerInterface {
}
}

/**
* Playwright test runner executes default test function since it doesn't support watch yet.
* https://github.com/microsoft/playwright/issues/7035
* @param rootPath
* @param fileName
* @param testName
*/
public runWatch(
rootPath: WorkspaceFolder,
fileName: string,
testName: string
) {
this.runTest(rootPath, fileName, testName);
}

public runTest(
rootPath: WorkspaceFolder,
fileName: string,
Expand Down Expand Up @@ -63,18 +78,18 @@ export class PlaywrightTestRunner implements ITestRunnerInterface {
"-g",
testName,
...additionalArguments.split(" "),
this.transformFileName(fileName),
this.transformFileName(fileName)
],
console: "integratedTerminal",
env: {
...{ PLAYWRIGHT_CHROMIUM_DEBUG_PORT: 9222, PWDEBUG: true },
...environmentVariables,
...environmentVariables
},
name: "Debug Test",
program: join(rootPath.uri.fsPath, this.path),
request: "launch",
skipFiles,
type: "node",
type: "node"
});
}

Expand Down