Skip to content

Commit ef054bd

Browse files
TestType -> TestDataItemType
1 parent bed432c commit ef054bd

17 files changed

+346
-323
lines changed

src/client/testing/common/services/discoveredTestParser.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import * as path from 'path';
88
import { Uri } from 'vscode';
99
import { IWorkspaceService } from '../../../common/application/types';
1010
import { traceError } from '../../../common/logger';
11-
import { TestDataItem } from '../../types';
12-
import { getParentFile, getParentSuite, getTestType } from '../testUtils';
11+
import { TestDataItem, TestDataItemType } from '../../types';
12+
import { getParentFile, getParentSuite, getTestDataItemType } from '../testUtils';
1313
import * as testing from '../types';
1414
import * as discovery from './types';
1515

@@ -74,17 +74,17 @@ export class TestDiscoveredTestParser implements discovery.ITestDiscoveredTestPa
7474
discoveredTests: discovery.DiscoveredTests,
7575
tests: testing.Tests
7676
) {
77-
const parentType = getTestType(parent);
77+
const parentType = getTestDataItemType(parent);
7878
switch (parentType) {
79-
case testing.TestType.testFolder: {
79+
case TestDataItemType.folder: {
8080
this.processFolder(rootFolder, parent as testing.TestFolder, discoveredTests, tests);
8181
break;
8282
}
83-
case testing.TestType.testFile: {
83+
case TestDataItemType.file: {
8484
this.processFile(rootFolder, parent as testing.TestFile, discoveredTests, tests);
8585
break;
8686
}
87-
case testing.TestType.testSuite: {
87+
case TestDataItemType.suite: {
8888
this.processSuite(rootFolder, parent as testing.TestSuite, discoveredTests, tests);
8989
break;
9090
}
@@ -383,11 +383,11 @@ function createFlattenedParameterizedFunction(
383383
func: testing.TestFunction,
384384
parent: testing.TestFile | testing.TestSuite
385385
): testing.FlattenedTestFunction {
386-
const type = getTestType(parent);
387-
const parentFile = (type && type === testing.TestType.testSuite) ?
386+
const type = getTestDataItemType(parent);
387+
const parentFile = (type && type === TestDataItemType.suite) ?
388388
getParentFile(tests, func) :
389389
parent as testing.TestFile;
390-
const parentSuite = (type && type === testing.TestType.testSuite) ?
390+
const parentSuite = (type && type === TestDataItemType.suite) ?
391391
parent as testing.TestSuite :
392392
undefined;
393393
return {
@@ -403,8 +403,8 @@ function createFlattenedFunction(
403403
func: testing.TestFunction
404404
): testing.FlattenedTestFunction {
405405
const parent = getParentFile(tests, func);
406-
const type = parent ? getTestType(parent) : undefined;
407-
const parentFile = (type && type === testing.TestType.testSuite) ?
406+
const type = parent ? getTestDataItemType(parent) : undefined;
407+
const parentFile = (type && type === TestDataItemType.suite) ?
408408
getParentFile(tests, func) :
409409
parent as testing.TestFile;
410410
const parentSuite = getParentSuite(tests, func);

src/client/testing/common/services/testResultsService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { inject, injectable, named } from 'inversify';
2-
import { TestDataItem } from '../../types';
3-
import { getChildren, getTestType } from '../testUtils';
4-
import { ITestResultsService, ITestVisitor, Tests, TestStatus, TestType } from './../types';
2+
import { TestDataItem, TestDataItemType } from '../../types';
3+
import { getChildren, getTestDataItemType } from '../testUtils';
4+
import { ITestResultsService, ITestVisitor, Tests, TestStatus } from '../types';
55

66
@injectable()
77
export class TestResultsService implements ITestResultsService {
@@ -33,7 +33,7 @@ export class TestResultsService implements ITestResultsService {
3333
}
3434
}
3535
private updateTestItem(test: TestDataItem): void {
36-
if (getTestType(test) === TestType.testFunction) {
36+
if (getTestDataItemType(test) === TestDataItemType.function) {
3737
return;
3838
}
3939
let allChildrenPassed = true;
@@ -42,7 +42,7 @@ export class TestResultsService implements ITestResultsService {
4242

4343
const children = getChildren(test);
4444
children.forEach(child => {
45-
if (getTestType(child) === TestType.testFunction) {
45+
if (getTestDataItemType(child) === TestDataItemType.function) {
4646
if (typeof child.passed === 'boolean') {
4747
noChildrenRan = false;
4848
if (child.passed) {

src/client/testing/common/testUtils.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IApplicationShell, ICommandManager } from '../../common/application/typ
55
import * as constants from '../../common/constants';
66
import { ITestingSettings, Product } from '../../common/types';
77
import { IServiceContainer } from '../../ioc/types';
8-
import { TestDataItem, TestWorkspaceFolder } from '../types';
8+
import { TestDataItem, TestDataItemType, TestWorkspaceFolder } from '../types';
99
import { CommandSource } from './constants';
1010
import { TestFlatteningVisitor } from './testVisitors/flatteningVisitor';
1111
import {
@@ -21,7 +21,6 @@ import {
2121
TestSettingsPropertyNames,
2222
TestsToRun,
2323
TestSuite,
24-
TestType,
2524
UnitTestProduct
2625
} from './types';
2726

@@ -244,21 +243,21 @@ export class TestsHelper implements ITestsHelper {
244243
}
245244
}
246245

247-
export function getTestType(test: TestDataItem): TestType {
246+
export function getTestDataItemType(test: TestDataItem): TestDataItemType {
248247
if (test instanceof TestWorkspaceFolder) {
249-
return TestType.testWorkspaceFolder;
248+
return TestDataItemType.workspaceFolder;
250249
}
251250
if (getTestFile(test)) {
252-
return TestType.testFile;
251+
return TestDataItemType.file;
253252
}
254253
if (getTestFolder(test)) {
255-
return TestType.testFolder;
254+
return TestDataItemType.folder;
256255
}
257256
if (getTestSuite(test)) {
258-
return TestType.testSuite;
257+
return TestDataItemType.suite;
259258
}
260259
if (getTestFunction(test)) {
261-
return TestType.testFunction;
260+
return TestDataItemType.function;
262261
}
263262
throw new Error('Unknown test type');
264263
}
@@ -305,14 +304,14 @@ export function getTestFunction(test: TestDataItem): TestFunction | undefined {
305304
* @returns {(TestDataItem | undefined)}
306305
*/
307306
export function getParent(tests: Tests, data: TestDataItem): TestDataItem | undefined {
308-
switch (getTestType(data)) {
309-
case TestType.testFile: {
307+
switch (getTestDataItemType(data)) {
308+
case TestDataItemType.file: {
310309
return getParentTestFolderForFile(tests, data as TestFile);
311310
}
312-
case TestType.testFolder: {
311+
case TestDataItemType.folder: {
313312
return getParentTestFolder(tests, data as TestFolder);
314313
}
315-
case TestType.testSuite: {
314+
case TestDataItemType.suite: {
316315
const suite = data as TestSuite;
317316
if (isSubtestsParent(suite)) {
318317
const fn = suite.functions[0];
@@ -328,7 +327,7 @@ export function getParent(tests: Tests, data: TestDataItem): TestDataItem | unde
328327
}
329328
return tests.testFiles.find(item => item.suites.indexOf(suite) >= 0);
330329
}
331-
case TestType.testFunction: {
330+
case TestDataItemType.function: {
332331
const fn = data as TestFunction;
333332
if (fn.subtestParent) {
334333
return fn.subtestParent.asSuite;
@@ -354,7 +353,7 @@ export function getParent(tests: Tests, data: TestDataItem): TestDataItem | unde
354353
* @returns {(TestFolder | undefined)}
355354
*/
356355
function getParentTestFolder(tests: Tests, item: TestFolder | TestFile): TestFolder | undefined {
357-
if (getTestType(item) === TestType.testFolder) {
356+
if (getTestDataItemType(item) === TestDataItemType.folder) {
358357
return getParentTestFolderForFolder(tests, item as TestFolder);
359358
}
360359
return getParentTestFolderForFile(tests, item as TestFile);
@@ -370,7 +369,7 @@ function getParentTestFolder(tests: Tests, item: TestFolder | TestFile): TestFol
370369
export function getParentFile(tests: Tests, suite: TestSuite | TestFunction): TestFile {
371370
let parent = getParent(tests, suite);
372371
while (parent) {
373-
if (getTestType(parent) === TestType.testFile) {
372+
if (getTestDataItemType(parent) === TestDataItemType.file) {
374373
return parent as TestFile;
375374
}
376375
parent = getParent(tests, parent);
@@ -387,7 +386,7 @@ export function getParentFile(tests: Tests, suite: TestSuite | TestFunction): Te
387386
export function getParentSuite(tests: Tests, suite: TestSuite | TestFunction): TestSuite | undefined {
388387
let parent = getParent(tests, suite);
389388
while (parent) {
390-
if (getTestType(parent) === TestType.testSuite) {
389+
if (getTestDataItemType(parent) === TestDataItemType.suite) {
391390
return parent as TestSuite;
392391
}
393392
parent = getParent(tests, parent);
@@ -453,22 +452,22 @@ export function findFlattendTestSuite(tests: Tests, suite: TestSuite): Flattened
453452
* @returns {TestDataItem[]}
454453
*/
455454
export function getChildren(item: TestDataItem): TestDataItem[] {
456-
switch (getTestType(item)) {
457-
case TestType.testFolder: {
455+
switch (getTestDataItemType(item)) {
456+
case TestDataItemType.folder: {
458457
return [
459458
...(item as TestFolder).folders,
460459
...(item as TestFolder).testFiles
461460
];
462461
}
463-
case TestType.testFile: {
462+
case TestDataItemType.file: {
464463
const [subSuites, functions] = divideSubtests((item as TestFile).functions);
465464
return [
466465
...functions,
467466
...(item as TestFile).suites,
468467
...subSuites
469468
];
470469
}
471-
case TestType.testSuite: {
470+
case TestDataItemType.suite: {
472471
let subSuites: TestSuite[] = [];
473472
let functions = (item as TestSuite).functions;
474473
if (!isSubtestsParent((item as TestSuite))) {
@@ -480,7 +479,7 @@ export function getChildren(item: TestDataItem): TestDataItem[] {
480479
...subSuites
481480
];
482481
}
483-
case TestType.testFunction: {
482+
case TestDataItemType.function: {
484483
return [];
485484
}
486485
default: {

src/client/testing/common/types.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ export type TestsToRun = {
6969
// test results
7070

7171
export enum TestType {
72-
testFile = 'testFile',
73-
testFolder = 'testFolder',
74-
testSuite = 'testSuite',
75-
testFunction = 'testFunction',
76-
testWorkspaceFolder = 'testWorkspaceFolder'
72+
folder = 'testFolder',
73+
file = 'testFile',
74+
suite = 'testSuite',
75+
function = 'testFunction'
7776
}
7877

7978
export enum TestStatus {

src/client/testing/explorer/commandHandlers.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,18 @@ import { traceDecorators } from '../../common/logger';
1010
import { IDisposable } from '../../common/types';
1111
import { swallowExceptions } from '../../common/utils/decorators';
1212
import { CommandSource } from '../common/constants';
13-
import { getTestType } from '../common/testUtils';
13+
import { getTestDataItemType } from '../common/testUtils';
1414
import {
15-
TestFile, TestFolder, TestFunction,
16-
TestsToRun, TestSuite, TestType
15+
TestFile, TestFolder, TestFunction, TestsToRun, TestSuite
1716
} from '../common/types';
1817
import { ITestExplorerCommandHandler } from '../navigation/types';
19-
import { ITestDataItemResource, TestDataItem } from '../types';
18+
import { ITestDataItemResource, TestDataItem, TestDataItemType } from '../types';
2019

2120
type NavigationCommands = typeof Commands.navigateToTestFile | typeof Commands.navigateToTestFunction | typeof Commands.navigateToTestSuite;
2221
const testNavigationCommandMapping: { [key: string]: NavigationCommands } = {
23-
[TestType.testFile]: Commands.navigateToTestFile,
24-
[TestType.testFunction]: Commands.navigateToTestFunction,
25-
[TestType.testSuite]: Commands.navigateToTestSuite
22+
[TestDataItemType.file]: Commands.navigateToTestFile,
23+
[TestDataItemType.function]: Commands.navigateToTestFunction,
24+
[TestDataItemType.suite]: Commands.navigateToTestSuite
2625
};
2726

2827
@injectable()
@@ -53,8 +52,8 @@ export class TestExplorerCommandHandler implements ITestExplorerCommandHandler {
5352
@swallowExceptions('Open test node in Editor')
5453
@traceDecorators.error('Open test node in editor failed')
5554
protected async onOpenTestNodeInEditor(item: TestDataItem): Promise<void> {
56-
const testType = getTestType(item);
57-
if (testType === TestType.testFolder) {
55+
const testType = getTestDataItemType(item);
56+
if (testType === TestDataItemType.folder) {
5857
throw new Error('Unknown Test Type');
5958
}
6059
const command = testNavigationCommandMapping[testType];
@@ -68,20 +67,20 @@ export class TestExplorerCommandHandler implements ITestExplorerCommandHandler {
6867
protected async runDebugTestNode(item: TestDataItem, runType: 'run' | 'debug'): Promise<void> {
6968
let testToRun: TestsToRun;
7069

71-
switch (getTestType(item)) {
72-
case TestType.testFile: {
70+
switch (getTestDataItemType(item)) {
71+
case TestDataItemType.file: {
7372
testToRun = { testFile: [item as TestFile] };
7473
break;
7574
}
76-
case TestType.testFolder: {
75+
case TestDataItemType.folder: {
7776
testToRun = { testFolder: [item as TestFolder] };
7877
break;
7978
}
80-
case TestType.testSuite: {
79+
case TestDataItemType.suite: {
8180
testToRun = { testSuite: [item as TestSuite] };
8281
break;
8382
}
84-
case TestType.testFunction: {
83+
case TestDataItemType.function: {
8584
testToRun = { testFunction: [item as TestFunction] };
8685
break;
8786
}

src/client/testing/explorer/failedTestHandler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { Commands } from '../../common/constants';
1111
import '../../common/extensions';
1212
import { IDisposable, IDisposableRegistry } from '../../common/types';
1313
import { debounceAsync } from '../../common/utils/decorators';
14-
import { getTestType } from '../common/testUtils';
15-
import { ITestCollectionStorageService, TestStatus, TestType } from '../common/types';
16-
import { TestDataItem } from '../types';
14+
import { getTestDataItemType } from '../common/testUtils';
15+
import { ITestCollectionStorageService, TestStatus } from '../common/types';
16+
import { TestDataItem, TestDataItemType } from '../types';
1717

1818
@injectable()
1919
export class FailedTestHandler implements IExtensionSingleActivationService, IDisposable {
@@ -32,7 +32,7 @@ export class FailedTestHandler implements IExtensionSingleActivationService, IDi
3232
}
3333
public onDidChangeTestData(args: { uri: Uri; data?: TestDataItem }): void {
3434
if (args.data && (args.data.status === TestStatus.Error || args.data.status === TestStatus.Fail) &&
35-
getTestType(args.data) === TestType.testFunction) {
35+
getTestDataItemType(args.data) === TestDataItemType.function) {
3636
this.failedItems.push(args.data);
3737
this.revealFailedNodes().ignoreErrors();
3838
}

0 commit comments

Comments
 (0)