1
+ "use strict" ;
2
+ import * as vscode from "vscode" ;
3
+ import * as baseTest from "./../unittest/baseTestRunner" ;
4
+ import * as unittest from "./../unittest/unittest" ;
5
+ import * as nosetest from "./../unittest/nosetests" ;
6
+ import * as pytest from "./../unittest/pytest" ;
7
+ import * as settings from "./../common/configSettings" ;
8
+ import * as telemetryHelper from "../common/telemetry" ;
9
+ import * as telemetryContracts from "../common/telemetryContracts" ;
10
+
11
+ let pythonOutputChannel : vscode . OutputChannel ;
12
+ let testProviders : baseTest . BaseTestRunner [ ] = [ ] ;
13
+
14
+ export function activateUnitTestProvider ( context : vscode . ExtensionContext , settings : settings . IPythonSettings , outputChannel : vscode . OutputChannel ) {
15
+ pythonOutputChannel = outputChannel ;
16
+ vscode . commands . registerCommand ( "python.runtests" , ( ) => runUnitTests ( ) ) ;
17
+
18
+ testProviders . push ( new unittest . PythonUnitTest ( settings , outputChannel ) ) ;
19
+ testProviders . push ( new nosetest . NoseTests ( settings , outputChannel ) ) ;
20
+ testProviders . push ( new pytest . PyTestTests ( settings , outputChannel ) ) ;
21
+ }
22
+
23
+ function runUnitTests ( filePath : string = "" ) {
24
+ pythonOutputChannel . clear ( ) ;
25
+
26
+ let promises = testProviders . map ( t => {
27
+ if ( ! t . isEnabled ( ) ) {
28
+ return Promise . resolve ( ) ;
29
+ }
30
+ let delays = new telemetryHelper . Delays ( ) ;
31
+ t . runTests ( filePath ) . then ( ( ) => {
32
+ delays . stop ( ) ;
33
+ telemetryHelper . sendTelemetryEvent ( telemetryContracts . Commands . UnitTests , { UnitTest_Provider : t . Id } , delays . toMeasures ( ) ) ;
34
+ } ) ;
35
+ } ) ;
36
+ Promise . all ( promises ) . then ( ( ) => {
37
+ pythonOutputChannel . show ( ) ;
38
+ } ) ;
39
+ }
0 commit comments