Skip to content

Commit

Permalink
testing: apply coverage comments for attributable coverage
Browse files Browse the repository at this point in the history
Refs #233709
  • Loading branch information
connor4312 committed Nov 25, 2024
1 parent 092ea0b commit 88343a0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/vs/workbench/api/common/extHostTesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ class TestRunTracker extends Disposable {
if (index === -1) {
return []; // ??
}
testItem = report.fromTests[index];
testItem = report.includesTests[index];
}

const details = testItem
Expand Down Expand Up @@ -755,10 +755,10 @@ class TestRunTracker extends Disposable {
return;
}

const fromTests = coverage instanceof FileCoverage ? coverage.fromTests : [];
if (fromTests.length) {
const includesTests = coverage instanceof FileCoverage ? coverage.includesTests : [];
if (includesTests.length) {
checkProposedApiEnabled(this.extension, 'attributableCoverage');
for (const test of fromTests) {
for (const test of includesTests) {
this.ensureTestIsKnown(test);
}
}
Expand All @@ -769,7 +769,7 @@ class TestRunTracker extends Disposable {
// it's been reported if it's rehomed under a different parent. Record its
// ID at the time when the coverage report is generated so we can reference
// it later if needeed.
this.publishedCoverage.set(id, { report: coverage, extIds: fromTests.map(t => TestId.fromExtHostTestItem(t, ctrlId).toString()) });
this.publishedCoverage.set(id, { report: coverage, extIds: includesTests.map(t => TestId.fromExtHostTestItem(t, ctrlId).toString()) });
this.proxy.$appendCoverage(runId, taskId, Convert.TestCoverage.fromFile(ctrlId, id, coverage));
},
//#region state mutation
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/common/extHostTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2149,8 +2149,8 @@ export namespace TestCoverage {
statement: fromCoverageCount(coverage.statementCoverage),
branch: coverage.branchCoverage && fromCoverageCount(coverage.branchCoverage),
declaration: coverage.declarationCoverage && fromCoverageCount(coverage.declarationCoverage),
testIds: coverage instanceof types.FileCoverage && coverage.fromTests.length ?
coverage.fromTests.map(t => TestId.fromExtHostTestItem(t, controllerId).toString()) : undefined,
testIds: coverage instanceof types.FileCoverage && coverage.includesTests.length ?
coverage.includesTests.map(t => TestId.fromExtHostTestItem(t, controllerId).toString()) : undefined,
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4262,7 +4262,7 @@ export class FileCoverage implements vscode.FileCoverage {
public statementCoverage: vscode.TestCoverageCount,
public branchCoverage?: vscode.TestCoverageCount,
public declarationCoverage?: vscode.TestCoverageCount,
public fromTests: vscode.TestItem[] = [],
public includesTests: vscode.TestItem[] = [],
) {
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/vscode-dts/vscode.proposed.attributableCoverage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ declare module 'vscode' {
* file. If set, then {@link TestRunProfile.loadDetailedCoverageForTest}
* should also be defined in order to retrieve detailed coverage information.
*/
fromTests?: TestItem[]; // TODO: `from` feels weird to me. Maybe `sourceTests` or `contributingTests` or even just `tests`
includesTests?: TestItem[];

constructor(
uri: Uri,
statementCoverage: TestCoverageCount,
branchCoverage?: TestCoverageCount,
declarationCoverage?: TestCoverageCount,
fromTests?: TestItem[],
includesTests?: TestItem[],
);
}

Expand All @@ -26,14 +26,14 @@ declare module 'vscode' {
* An extension-provided function that provides detailed statement and
* function-level coverage for a single test in a file. This is the per-test
* sibling of {@link TestRunProfile.loadDetailedCoverage}, called only if
* a test item is provided in {@link FileCoverage.fromTests} and only for
* files where such data is reported.
* a test item is provided in {@link FileCoverage.includesTests} and only
* for files where such data is reported.
*
* // TODO: clarify how this works with `loadDetailedCoverage`. Does it replace `loadDetailedCoverage` or will it be called in addition to it?
*
* The editor will call this when user asks to view coverage for a test in
* a file, and the returned coverage information is used to display exactly
* what code was run by that test.
* Often {@link TestRunProfile.loadDetailedCoverage} will be called first
* when a user opens a file, and then this method will be called if they
* drill down into specific per-test coverage information. This method
* should then return coverage data only for constructs the given test item
* executed during the test run.
*
* The {@link FileCoverage} object passed to this function is the same
* instance emitted on {@link TestRun.addCoverage} calls associated with this profile.
Expand Down

0 comments on commit 88343a0

Please sign in to comment.