Skip to content

API: Attributable Test Coverage #212196

Closed

Description

For a variety of reasons, it may be useful to know what tests generated what coverage. So let's add some API for that in the form of a second optional parameter for addCoverage.

declare module 'vscode' {
	export class FileCoverage2 extends FileCoverage {
		/**
		 * A list of {@link TestItem test cases} that generated coverage in this
		 * file. If set, then {@link TestRunProfile.loadDetailedCoverageForTest}
		 * should also be defined in order to retrieve detailed coverage information.
		 */
		fromTests: TestItem[];

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

	export interface TestRunProfile {
		/**
		 * 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.
		 *
		 * 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.
		 *
		 * The {@link FileCoverage} object passed to this function is the same
		 * instance emitted on {@link TestRun.addCoverage} calls associated with this profile.
		 *
		 * @param testRun The test run that generated the coverage data.
		 * @param fileCoverage The file coverage object to load detailed coverage for.
		 * @param fromTestItem The test item to request coverage information for.
		 * @param token A cancellation token that indicates the operation should be cancelled.
		 */
		loadDetailedCoverageForTest?: (testRun: TestRun, fileCoverage: FileCoverage, fromTestItem: TestItem, token: CancellationToken) => Thenable<FileCoverageDetail[]>;
	}
}

Activity

  1. added
    feature-request
    testing
    on May 7, 2024
  2. connor4312 commented on May 10, 2024

    @connor4312
    MemberAuthor

    Peek at initial UI: #212403

  3. sanket-bhalerao commented on May 27, 2024

    @sanket-bhalerao

    is this feature limited to code for vscode or other projects can utilize this for their test coverage?

  4. connor4312 commented on May 28, 2024

    @connor4312
    MemberAuthor

    Once the API is finalized, anyone can use it. It is subject to change until then, but we encourage folks to try it out and let us know how it works for them.

  5. 5 remaining items

  6. added a commit that references this issue on Nov 26, 2024
    1460355
  7. added
    unreleased
    on Nov 26, 2024
  8. added a commit that references this issue on Nov 26, 2024
    436f1e9
  9. added
    insiders-released
    and removed
    unreleased
    on Nov 26, 2024
  10. locked and limited conversation to collaborators on Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

api-finalizationfeature-requestinsiders-releasedon-testplantest-coveragetesting

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions