|
1 | 1 | import { QuickPickItem, window } from 'vscode'; |
2 | 2 | import * as vscode from 'vscode'; |
3 | | -import { Tests, TestFunction, FlattenedTestFunction, TestStatus } from '../common/contracts'; |
| 3 | +import { Tests, TestFile, TestFunction, FlattenedTestFunction, TestStatus } from '../common/contracts'; |
4 | 4 | import { getDiscoveredTests } from '../common/testUtils'; |
5 | 5 | import * as constants from '../../common/constants'; |
6 | 6 | import * as path from 'path'; |
@@ -30,6 +30,17 @@ export class TestDisplay { |
30 | 30 | }, reject); |
31 | 31 | }); |
32 | 32 | } |
| 33 | + public selectTestFile(rootDirectory: string, tests: Tests): Promise<TestFile> { |
| 34 | + return new Promise<TestFile>((resolve, reject) => { |
| 35 | + window.showQuickPick(buildItemsForTestFiles(rootDirectory, tests.testFiles), { matchOnDescription: true, matchOnDetail: true }) |
| 36 | + .then(item => { |
| 37 | + if (item && item.testFile) { |
| 38 | + return resolve(item.testFile); |
| 39 | + } |
| 40 | + return reject(); |
| 41 | + }, reject); |
| 42 | + }); |
| 43 | + } |
33 | 44 | public displayFunctionTestPickerUI(rootDirectory: string, fileName: string, testFunctions: TestFunction[], debug?: boolean) { |
34 | 45 | const tests = getDiscoveredTests(); |
35 | 46 | if (!tests) { |
@@ -73,6 +84,10 @@ interface TestItem extends QuickPickItem { |
73 | 84 | type: Type; |
74 | 85 | fn?: FlattenedTestFunction; |
75 | 86 | } |
| 87 | +interface TestFileItem extends QuickPickItem { |
| 88 | + type: Type; |
| 89 | + testFile?: TestFile; |
| 90 | +} |
76 | 91 | function getSummary(tests?: Tests) { |
77 | 92 | if (!tests || !tests.summary) { |
78 | 93 | return ''; |
@@ -150,6 +165,27 @@ function buildItemsForFunctions(rootDirectory: string, tests: FlattenedTestFunct |
150 | 165 | }); |
151 | 166 | return functionItems; |
152 | 167 | } |
| 168 | +function buildItemsForTestFiles(rootDirectory: string, testFiles: TestFile[]): TestFileItem[] { |
| 169 | + let fileItems: TestFileItem[] = testFiles.map(testFile => { |
| 170 | + return { |
| 171 | + description: '', |
| 172 | + detail: path.relative(rootDirectory, testFile.fullPath), |
| 173 | + type: Type.RunFile, |
| 174 | + label: path.basename(testFile.fullPath), |
| 175 | + testFile: testFile |
| 176 | + } |
| 177 | + }) |
| 178 | + fileItems.sort((a, b) => { |
| 179 | + if (a.detail < b.detail) { |
| 180 | + return -1; |
| 181 | + } |
| 182 | + if (a.detail > b.detail) { |
| 183 | + return 1; |
| 184 | + } |
| 185 | + return 0; |
| 186 | + }) |
| 187 | + return fileItems; |
| 188 | +} |
153 | 189 | function onItemSelected(selection: TestItem, debug?: boolean) { |
154 | 190 | if (!selection || typeof selection.type !== 'number') { |
155 | 191 | return; |
|
0 commit comments