22
33'use strict' ;
44import * as path from 'path' ;
5- import { execPythonFile } from './../../common/utils' ;
65import { createDeferred , createTemporaryFile } from '../../common/helpers' ;
76import { TestFile , TestsToRun , TestSuite , TestFunction , FlattenedTestFunction , Tests , TestStatus , FlattenedTestSuite } from '../common/contracts' ;
87import { extractBetweenDelimiters , flattenTestFiles , updateResults , convertFileToPackage } from '../common/testUtils' ;
@@ -66,18 +65,54 @@ export function runTest(rootDirectory: string, tests: Tests, args: string[], tes
6665 for ( let counter = 0 ; counter < testPaths . length ; counter ++ ) {
6766 testPaths [ counter ] = '-t' + testPaths [ counter ] . trim ( ) ;
6867 }
69- let testArgs = buildTestArgs ( args ) ;
70- testArgs = [ testLauncherFile ] . concat ( testArgs ) . concat ( `--result-port=${ port } ` ) . concat ( testPaths ) ;
71- return run ( settings . pythonPath , testArgs , rootDirectory , token , outChannel ) ;
68+ const startTestDiscoveryDirectory = getStartDirectory ( args ) ;
69+
70+ function runTest ( testFile : string = '' , testId : string = '' ) {
71+ let testArgs = buildTestArgs ( args ) ;
72+ testArgs . push ( `--result-port=${ port } ` ) ;
73+ testArgs . push ( `--us=${ startTestDiscoveryDirectory } ` ) ;
74+ if ( testId . length > 0 ) {
75+ testArgs . push ( `-t${ testId } ` ) ;
76+ }
77+ if ( testFile . length > 0 ) {
78+ testArgs . push ( `--testFile=${ testFile } ` ) ;
79+ }
80+ return run ( settings . pythonPath , [ testLauncherFile ] . concat ( testArgs ) , rootDirectory , token , outChannel ) ;
81+ }
82+
83+ // Test everything
84+ if ( testPaths . length === 0 ) {
85+ return runTest ( ) ;
86+ }
87+
88+ // Ok, the ptvs test runner can only work with one test at a time
89+ let promise = Promise . resolve < string > ( '' ) ;
90+ if ( Array . isArray ( testsToRun . testFile ) ) {
91+ testsToRun . testFile . forEach ( testFile => {
92+ promise = promise . then ( ( ) => runTest ( testFile . fullPath , testFile . nameToRun ) ) ;
93+ } ) ;
94+ }
95+ if ( Array . isArray ( testsToRun . testSuite ) ) {
96+ testsToRun . testSuite . forEach ( testSuite => {
97+ const testFileName = tests . testSuits . find ( t => t . testSuite === testSuite ) . parentTestFile . fullPath ;
98+ promise = promise . then ( ( ) => runTest ( testFileName , testSuite . nameToRun ) ) ;
99+ } ) ;
100+ }
101+ if ( Array . isArray ( testsToRun . testFunction ) ) {
102+ testsToRun . testFunction . forEach ( testFn => {
103+ const testFileName = tests . testFunctions . find ( t => t . testFunction === testFn ) . parentTestFile . fullPath ;
104+ promise = promise . then ( ( ) => runTest ( testFileName , testFn . nameToRun ) ) ;
105+ } ) ;
106+ }
107+ return promise ;
72108 } ) . then ( ( ) => {
73109 updateResults ( tests ) ;
74110 return tests ;
75111 } ) ;
76112}
77113
78- function buildTestArgs ( args : string [ ] ) : string [ ] {
114+ function getStartDirectory ( args : string [ ] ) : string {
79115 let startDirectory = '.' ;
80- let pattern = 'test*.py' ;
81116 const indexOfStartDir = args . findIndex ( arg => arg . indexOf ( '-s' ) === 0 || arg . indexOf ( '--start-directory' ) === 0 ) ;
82117 if ( indexOfStartDir >= 0 ) {
83118 const startDir = args [ indexOfStartDir ] . trim ( ) ;
@@ -93,6 +128,11 @@ function buildTestArgs(args: string[]): string[] {
93128 }
94129 }
95130 }
131+ return startDirectory ;
132+ }
133+ function buildTestArgs ( args : string [ ] ) : string [ ] {
134+ const startTestDiscoveryDirectory = getStartDirectory ( args ) ;
135+ let pattern = 'test*.py' ;
96136 const indexOfPattern = args . findIndex ( arg => arg . indexOf ( '-p' ) === 0 || arg . indexOf ( '--pattern' ) === 0 ) ;
97137 if ( indexOfPattern >= 0 ) {
98138 const patternValue = args [ indexOfPattern ] . trim ( ) ;
@@ -110,7 +150,7 @@ function buildTestArgs(args: string[]): string[] {
110150 }
111151 const failFast = args . some ( arg => arg . trim ( ) === '-f' || arg . trim ( ) === '--failfast' ) ;
112152 const verbosity = args . some ( arg => arg . trim ( ) . indexOf ( '-v' ) === 0 ) ? 2 : 1 ;
113- const testArgs = [ `--us=${ startDirectory } ` , `--up=${ pattern } ` , `--uvInt=${ verbosity } ` ] ;
153+ const testArgs = [ `--us=${ startTestDiscoveryDirectory } ` , `--up=${ pattern } ` , `--uvInt=${ verbosity } ` ] ;
114154 if ( failFast ) {
115155 testArgs . push ( '--uf' ) ;
116156 }
0 commit comments