diff --git a/package.json b/package.json index 02513ac..bbdbc89 100644 --- a/package.json +++ b/package.json @@ -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" } } } diff --git a/src/jestRunner.ts b/src/jestRunner.ts index 3597673..7935baf 100644 --- a/src/jestRunner.ts +++ b/src/jestRunner.ts @@ -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) { @@ -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) {