11'use strict' ;
2- import { createTemporaryFile } from '../../common/helpers' ;
3- import { OutputChannel , CancellationToken } from 'vscode' ;
4- import { TestsToRun , Tests } from '../common/contracts' ;
5- import { updateResults } from '../common/testUtils' ;
6- import { updateResultsFromXmlLogFile , PassCalculationFormulae } from '../common/xUnitParser' ;
7- import { run } from '../common/runner' ;
8- import { PythonSettings } from '../../common/configSettings' ;
2+ import { createTemporaryFile } from '../../common/helpers' ;
3+ import { OutputChannel , CancellationToken } from 'vscode' ;
4+ import { TestsToRun , Tests } from '../common/contracts' ;
5+ import { updateResults } from '../common/testUtils' ;
6+ import { updateResultsFromXmlLogFile , PassCalculationFormulae } from '../common/xUnitParser' ;
7+ import { run } from '../common/runner' ;
8+ import { PythonSettings } from '../../common/configSettings' ;
99
1010const pythonSettings = PythonSettings . getInstance ( ) ;
11+ const WITH_XUNIT = '--with-xunit' ;
12+ const XUNIT_FILE = '--xunit-file' ;
1113
1214export function runTest ( rootDirectory : string , tests : Tests , args : string [ ] , testsToRun ?: TestsToRun , token ?: CancellationToken , outChannel ?: OutputChannel ) : Promise < any > {
1315 let testPaths = [ ] ;
@@ -25,12 +27,39 @@ export function runTest(rootDirectory: string, tests: Tests, args: string[], tes
2527 }
2628
2729 let xmlLogFile = '' ;
28- let xmlLogFileCleanup : Function = null ;
30+ let xmlLogFileCleanup : Function = ( ) => { } ;
2931
30- return createTemporaryFile ( '.xml' ) . then ( xmlLogResult => {
31- xmlLogFile = xmlLogResult . filePath ;
32- xmlLogFileCleanup = xmlLogResult . cleanupCallback ;
33- return run ( pythonSettings . unitTest . nosetestPath , args . concat ( [ '--with-xunit' , `--xunit-file=${ xmlLogFile } ` ] ) . concat ( testPaths ) , rootDirectory , token , outChannel ) ;
32+ // Check if '--with-xunit' is in args list
33+ const noseTestArgs = args . slice ( ) ;
34+ if ( noseTestArgs . indexOf ( WITH_XUNIT ) === - 1 ) {
35+ noseTestArgs . push ( WITH_XUNIT ) ;
36+ }
37+
38+ // Check if '--xunit-file' exists, if not generate random xml file
39+ let indexOfXUnitFile = noseTestArgs . findIndex ( value => value . indexOf ( XUNIT_FILE ) === 0 ) ;
40+ let promiseToGetXmlLogFile : Promise < string > ;
41+ if ( indexOfXUnitFile === - 1 ) {
42+ promiseToGetXmlLogFile = createTemporaryFile ( '.xml' ) . then ( xmlLogResult => {
43+ xmlLogFileCleanup = xmlLogResult . cleanupCallback ;
44+ xmlLogFile = xmlLogResult . filePath ;
45+
46+ noseTestArgs . push ( `${ XUNIT_FILE } =${ xmlLogFile } ` ) ;
47+ return xmlLogResult . filePath ;
48+ } ) ;
49+ }
50+ else {
51+ if ( noseTestArgs [ indexOfXUnitFile ] . indexOf ( '=' ) === - 1 ) {
52+ xmlLogFile = noseTestArgs [ indexOfXUnitFile + 1 ] ;
53+ }
54+ else {
55+ xmlLogFile = noseTestArgs [ indexOfXUnitFile ] . substring ( noseTestArgs [ indexOfXUnitFile ] . indexOf ( '=' ) + 1 ) . trim ( ) ;
56+ }
57+
58+ promiseToGetXmlLogFile = Promise . resolve ( xmlLogFile ) ;
59+ }
60+
61+ return promiseToGetXmlLogFile . then ( ( ) => {
62+ return run ( pythonSettings . unitTest . nosetestPath , noseTestArgs . concat ( testPaths ) , rootDirectory , token , outChannel ) ;
3463 } ) . then ( ( ) => {
3564 return updateResultsFromLogFiles ( tests , xmlLogFile ) ;
3665 } ) . then ( result => {
0 commit comments