private enlistToTestMapping()

in src/runners/junitRunner/JUnitRunnerResultAnalyzer.ts [193:273]


    private enlistToTestMapping(message: string): void {
        const regExp: RegExp = /([^\\,]|\\\,?)+/gm;
        // See MessageId.TestTree's comment for its format
        const result: RegExpMatchArray | null = message.match(regExp);
        if (result && result.length > 6) {
            const index: string = result[0];
            const testId: string = this.getTestId(result[1]);
            const isSuite: boolean = result[2] === 'true';
            const testCount: number = parseInt(result[3], 10);
            const isDynamic: boolean = result[4] === 'true';
            const parentIndex: string = result[5];
            const displayName: string = result[6].replace(/\\,/g, ',');

            let testItem: TestItem | undefined;
            if (isDynamic) {
                const parentInfo: ITestInfo | undefined = this.testOutputMapping.get(parentIndex);
                const parent: TestItem | undefined = parentInfo?.testItem;
                if (parent) {
                    const parentData: ITestItemData | undefined = dataCache.get(parent);
                    if (parentData?.testLevel === TestLevel.Method) {
                        testItem = createTestItem({
                            children: [],
                            uri: parent.uri?.toString(),
                            range: parent.range,
                            jdtHandler: parentData.jdtHandler,
                            fullName: parentData.fullName,
                            label: this.getTestMethodName(displayName),
                            id: `${INVOCATION_PREFIX}${parent.id}[#${parent.children.size + 1}]`,
                            projectName: parentData.projectName,
                            testKind: parentData.testKind,
                            testLevel: TestLevel.Invocation,
                        }, parent);
                    }
                }
            } else {
                testItem = this.triggeredTestsMapping.get(testId);

                if (this.incompleteTestSuite.length) {
                    const suiteIdx: number = this.incompleteTestSuite.length - 1;
                    const parentSuite: ITestInfo = this.incompleteTestSuite[suiteIdx];
                    parentSuite.testCount--;
                    if (parentSuite.testCount <= 0) {
                        this.incompleteTestSuite.pop();
                    }
                    if (!testItem && parentSuite.testItem) {
                        const itemData: IJavaTestItem | undefined = {
                            children: [],
                            uri: undefined,
                            range: undefined,
                            jdtHandler: '',
                            fullName: testId.substr(testId.indexOf('@') + 1),
                            label: this.getTestMethodName(displayName),
                            id: `${INVOCATION_PREFIX}${testId}`,
                            projectName: this.projectName,
                            testKind: this.testContext.kind,
                            testLevel: TestLevel.Invocation,
                        };
                        testItem = createTestItem(itemData, parentSuite.testItem);
                    }
                }

                if (isSuite && testCount > 0) {
                    this.incompleteTestSuite.push({
                        testId,
                        testCount,
                        testItem,
                    });
                }

                if (testItem && dataCache.get(testItem)?.testKind === TestKind.JUnit5 && testItem.label !== displayName) {
                    testItem.description = displayName;
                }
            }

            this.testOutputMapping.set(index, {
                testId,
                testCount,
                testItem,
            });
        }
    }