forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.ts
More file actions
52 lines (47 loc) · 2.31 KB
/
runner.ts
File metadata and controls
52 lines (47 loc) · 2.31 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
'use strict';
import * as path from 'path';
import {execPythonFile} from './../../common/utils';
import {createDeferred, createTemporaryFile} from '../../common/helpers';
import {OutputChannel, window, CancellationToken} from 'vscode';
import {TestFile, TestsToRun, TestSuite, TestFunction, FlattenedTestFunction, Tests, TestStatus, FlattenedTestSuite} from '../common/contracts';
import * as vscode from 'vscode';
import {extractBetweenDelimiters, convertFileToPackage, flattenTestFiles, updateResults} from '../common/testUtils';
import {BaseTestManager} from '../common/baseTestManager';
import {updateResultsFromXmlLogFile, PassCalculationFormulae} from '../common/xUnitParser';
import {run} from '../common/runner';
export function runTest(rootDirectory: string, tests: Tests, args: string[], testsToRun?: TestsToRun, token?: CancellationToken, outChannel?: OutputChannel): Promise<any> {
let testPaths = [];
if (testsToRun && testsToRun.testFolder) {
testPaths = testPaths.concat(testsToRun.testFolder.map(f => f.nameToRun));
}
if (testsToRun && testsToRun.testFile) {
testPaths = testPaths.concat(testsToRun.testFile.map(f => f.nameToRun));
}
if (testsToRun && testsToRun.testSuite) {
testPaths = testPaths.concat(testsToRun.testSuite.map(f => f.nameToRun));
}
if (testsToRun && testsToRun.testFunction) {
testPaths = testPaths.concat(testsToRun.testFunction.map(f => f.nameToRun));
}
let xmlLogFile = '';
let xmlLogFileCleanup: Function = null;
return createTemporaryFile('.xml').then(xmlLogResult => {
xmlLogFile = xmlLogResult.filePath;
xmlLogFileCleanup = xmlLogResult.cleanupCallback;
return run('nosetests', args.concat(['--with-xunit', `--xunit-file=${xmlLogFile}`]).concat(testPaths), rootDirectory, token, outChannel);
}).then(() => {
return updateResultsFromLogFiles(tests, xmlLogFile);
}).then(result => {
xmlLogFileCleanup();
return result;
}).catch(reason => {
xmlLogFileCleanup();
return Promise.reject(reason);
});
}
export function updateResultsFromLogFiles(tests: Tests, outputXmlFile: string): Promise<any> {
return updateResultsFromXmlLogFile(tests, outputXmlFile, PassCalculationFormulae.nosetests).then(() => {
updateResults(tests);
return tests;
});
}