microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
160.22k stars 28.06k forks source link

API: Attributable Test Coverage #212196

Open connor4312 opened 1 month ago

connor4312 commented 1 month ago

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 {
        /**
         * Test {@link TestItem} this file coverage is generated from. If undefined,
         * the editor will assume the coverage is the overall summary coverage for
         * the entire file.
         *
         * If per-test coverage is available, an extension should append multiple
         * `FileCoverage` instances with this property set for each test item. It
         * must also append a `FileCoverage` instance without this property set to
         * represent the overall coverage of the file.
         */
        testItem?: TestItem;

        constructor(
            uri: Uri,
            statementCoverage: TestCoverageCount,
            branchCoverage?: TestCoverageCount,
            declarationCoverage?: TestCoverageCount,
            testItem?: TestItem,
        );
    }
}
connor4312 commented 1 month ago

Peek at initial UI: https://github.com/microsoft/vscode/pull/212403

sanket-bhalerao commented 1 month ago

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

connor4312 commented 1 month ago

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.