Skip to content

Test: test results api #117307

@connor4312

Description

@connor4312

Refs: #107467

Complexity: 5

Authors: @connor4312

Create Issue


As part of testing, we have an API that allows extensions to read and publish test results. Namely:

/**
* Inserts custom test results into the VS Code UI. The results are
* inserted and sorted based off the `completedAt` timestamp. If the
* results are being read from a file, for example, the `completedAt`
* time should generally be the modified time of the file if not more
* specific time is available.
*
* This will no-op if the inserted results are deeply equal to an
* existing result.
*
* @param results test results
* @param persist whether the test results should be saved by VS Code
* and persisted across reloads. Defaults to true.
*/
export function publishTestResult(results: TestResults, persist?: boolean): void;
/**
* List of test results stored by VS Code, sorted in descnding
* order by their `completedAt` time.
*/
export const testResults: ReadonlyArray<TestResults>;
/**
* Event that fires when the {@link testResults} array is updated.
*/
export const onDidChangeTestResults: Event<void>;

The intention is for this API to be useful if, for example:

  • An extension can publishTestResults that it reads test results off the disk
  • An extension can publishTestResults if it detects that tests results were run outside of the TestProvider.runTests API
  • An extension can react to test passes or failures

Note that test results are associated with the "living" test items through their ID, so if you publish a test result for a test that a provider isn't providing anywhere, you won't see any UI for it.

Please build an extension to give these APIs and shot and let me know how it goes! For example you might build an extension that pops a toast notification if tests fail or lets the user open test results from a well-known format off disk. Let me know if you run into any problems or ambiguities while doing so.

You might find the sample test provider useful as a foundation to build against, or the more complex selfhost test provider if you feel ambitious.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions