Enable the play button or codelens for tests -Testing API

Viewed 114

We migrated to the vscode testing api from Test Explorer UI. But we are not able to get code lens (like in the Test Explorer UI) or a play button against each identified test in the editor. We add the tests like below:

const filepath = "file:///" + test.sourceLocation?.file + "#" + test.sourceLocation?.line;
testItem.children.add(controller.createTestItem(test.id, test.labelName, Uri.parse(filepath)));

The navigation to the individual test works, but we don't see any possibility to trigger a test run from the editor.

1 Answers

Found the solution! We were wrong how we provided the URI. And Range had to be provided explicitly

const filepath = test.sourceLocation?.file!;
const line = testCase.sourceLocation?.line;
const testItem = controller.createTestItem(testCase.id, name, filepath ? Uri.file(filepath) : undefined);
 if (line) {
    testItem.range = new Range(new Position(line - 1, 0), new Position(line - 1, 0));
  }
testItem.children.add(testItem);

Related