forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
96 lines (93 loc) · 3.54 KB
/
Copy pathmain.ts
File metadata and controls
96 lines (93 loc) · 3.54 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { Uri } from 'vscode';
import { CommandSource } from '../../common/application/types';
import { Product } from '../../common/types';
import { noop } from '../../common/utils/misc';
import { IServiceContainer } from '../../ioc/types';
import { UNITTEST_PROVIDER } from '../common/constants';
import { BaseTestManager } from '../common/managers/baseTestManager';
import {
IArgumentsService,
ITestManagerRunner,
ITestsHelper,
TestDiscoveryOptions,
TestFilter,
TestRunOptions,
Tests,
TestStatus,
TestsToRun,
} from '../common/types';
export class TestManager extends BaseTestManager {
private readonly argsService: IArgumentsService;
private readonly helper: ITestsHelper;
private readonly runner: ITestManagerRunner;
public get enabled() {
return this.settings.testing.unittestEnabled;
}
constructor(workspaceFolder: Uri, rootDirectory: string, serviceContainer: IServiceContainer) {
super(UNITTEST_PROVIDER, Product.unittest, workspaceFolder, rootDirectory, serviceContainer);
this.argsService = this.serviceContainer.get<IArgumentsService>(IArgumentsService, this.testProvider);
this.helper = this.serviceContainer.get<ITestsHelper>(ITestsHelper);
this.runner = this.serviceContainer.get<ITestManagerRunner>(ITestManagerRunner, this.testProvider);
}
public configure() {
noop();
}
public getDiscoveryOptions(ignoreCache: boolean): TestDiscoveryOptions {
const args = this.settings.testing.unittestArgs.slice(0);
return {
workspaceFolder: this.workspaceFolder,
cwd: this.rootDirectory,
args,
token: this.testDiscoveryCancellationToken!,
ignoreCache,
outChannel: this.outputChannel,
};
}
public async runTest(
cmdSource: CommandSource,
testsToRun?: TestsToRun,
runFailedTests?: boolean,
debug?: boolean,
): Promise<Tests> {
if (runFailedTests === true && this.tests) {
testsToRun = { testFile: [], testFolder: [], testSuite: [], testFunction: [] };
testsToRun.testFunction = this.tests.testFunctions
.filter((fn) => {
return fn.testFunction.status === TestStatus.Error || fn.testFunction.status === TestStatus.Fail;
})
.map((fn) => fn.testFunction);
}
return super.runTest(cmdSource, testsToRun, runFailedTests, debug);
}
public async runTestImpl(
tests: Tests,
testsToRun?: TestsToRun,
_runFailedTests?: boolean,
debug?: boolean,
): Promise<Tests> {
let args: string[];
const runAllTests = this.helper.shouldRunAllTests(testsToRun);
if (debug) {
args = this.argsService.filterArguments(
this.settings.testing.unittestArgs,
runAllTests ? TestFilter.debugAll : TestFilter.debugSpecific,
);
} else {
args = this.argsService.filterArguments(
this.settings.testing.unittestArgs,
runAllTests ? TestFilter.runAll : TestFilter.runSpecific,
);
}
const options: TestRunOptions = {
workspaceFolder: this.workspaceFolder,
cwd: this.rootDirectory,
tests,
args,
testsToRun,
debug,
token: this.testRunnerCancellationToken!,
outChannel: this.outputChannel,
};
return this.runner.runTest(this.testResultsService, options, this);
}
}