forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.ts
More file actions
51 lines (48 loc) · 1.93 KB
/
helper.ts
File metadata and controls
51 lines (48 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import { IServiceContainer } from '../../ioc/types';
import { Tests, TestsToRun } from '../common/types';
import { IArgumentsHelper, IUnitTestHelper } from '../types';
@injectable()
export class UnitTestHelper implements IUnitTestHelper {
private readonly argsHelper: IArgumentsHelper;
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
this.argsHelper = serviceContainer.get<IArgumentsHelper>(IArgumentsHelper);
}
public getStartDirectory(args: string[]): string {
const shortValue = this.argsHelper.getOptionValues(args, '-s');
if (typeof shortValue === 'string') {
return shortValue;
}
const longValue = this.argsHelper.getOptionValues(args, '--start-directory');
if (typeof longValue === 'string') {
return longValue;
}
return '.';
}
public getIdsOfTestsToRun(tests: Tests, testsToRun: TestsToRun): string[] {
const testIds: string[] = [];
if (testsToRun && testsToRun.testFolder) {
// Get test ids of files in these folders.
testsToRun.testFolder.forEach(folder => {
tests.testFiles.forEach(f => {
if (f.fullPath.startsWith(folder.name)) {
testIds.push(f.nameToRun);
}
});
});
}
if (testsToRun && testsToRun.testFile) {
testIds.push(...testsToRun.testFile.map(f => f.nameToRun));
}
if (testsToRun && testsToRun.testSuite) {
testIds.push(...testsToRun.testSuite.map(f => f.nameToRun));
}
if (testsToRun && testsToRun.testFunction) {
testIds.push(...testsToRun.testFunction.map(f => f.nameToRun));
}
return testIds;
}
}