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

Fix multi-variable substitution #1040

Merged
merged 1 commit into from Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 4 additions & 14 deletions src/DebugConfigurationProvider.ts
Expand Up @@ -109,20 +109,10 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
if (typeof arg !== 'string') {
return arg;
}
switch (true) {
case testFileRegex.test(arg): {
return arg.replace(testFileRegex, toFilePath(this.fileNameToRun));
}
case testFilePatternRegex.test(arg): {
return arg.replace(testFilePatternRegex, escapeRegExp(this.fileNameToRun));
}
case testNamePatternRegex.test(arg): {
return arg.replace(testNamePatternRegex, this.testToRun);
}

default:
return arg;
}
return arg
.replace(testFileRegex, toFilePath(this.fileNameToRun))
.replace(testFilePatternRegex, escapeRegExp(this.fileNameToRun))
.replace(testNamePatternRegex, this.testToRun);
});
debugConfiguration.args = args;

Expand Down
20 changes: 20 additions & 0 deletions tests/DebugConfigurationProvider.test.ts
Expand Up @@ -128,6 +128,26 @@ describe('DebugConfigurationProvider', () => {
expect(configuration).toBeDefined();
expect(configuration.args).toEqual(expected);
});
it('will translate multiple variables in a single arg', () => {
(toFilePath as unknown as jest.Mock<{}>).mockReturnValueOnce(fileName);
(escapeRegExp as unknown as jest.Mock<{}>).mockReturnValueOnce(fileNamePattern);

let configuration: any = {
name: 'vscode-jest-tests.v2',
args: ['--testNamePattern "${jest.testNamePattern}" --runTestsByPath "${jest.testFile}"'],
};

const sut = new DebugConfigurationProvider();
const ws = makeWorkspaceFolder('whatever');
sut.prepareTestRun(fileName, testName, ws);

configuration = sut.resolveDebugConfiguration(undefined, configuration);

expect(configuration).toBeDefined();
expect(configuration.args).toEqual([
`--testNamePattern "${testName}" --runTestsByPath "${fileName}"`,
]);
});
});
describe('can generate debug config with jestCommandLine and rootPath', () => {
const canRunTest = (isWin32: boolean) =>
Expand Down