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: Add workspace root substitution for docker containers #335

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@
"default": "yarn-*.*js",
"description": "Command for debugging with Plug'n'Play",
"scope": "window"
},
"jestrunner.testPathSubstitution": {
"type": "string",
"default": "",
"description": "Replaces the workspace root of the test file path. Useful for docker containers.",
"scope": "window"
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/jestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class JestRunner {
const args: string[] = [];
const quoter = withQuotes ? quote : (str) => str;

args.push(quoter(escapeRegExpForPath(normalizePath(filePath))));
args.push(quoter(this.resolveFilePath(filePath)));

const jestConfigPath = this.config.getJestConfigPath(filePath);
if (jestConfigPath) {
Expand All @@ -235,6 +235,16 @@ export class JestRunner {
return args;
}

private resolveFilePath(filePath: string): string {
let path = normalizePath(filePath);
const testPathSubstitution: string = vscode.workspace.getConfiguration().get('jestrunner.testPathSubstitution');
if (testPathSubstitution) {
path = path.replace(this.config.currentWorkspaceFolderPath, testPathSubstitution);
}

return escapeRegExpForPath(path);
}

private async goToCwd() {
const command = `cd ${quote(this.config.cwd)}`;
if (this.config.changeDirectoryToWorkspaceRoot) {
Expand Down