Skip to content

Commit

Permalink
Add an event for test discovery being done
Browse files Browse the repository at this point in the history
  • Loading branch information
juliasilge committed Feb 25, 2025
1 parent 836e742 commit 17c8b70
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 5 additions & 4 deletions extensions/positron-r/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { quickPickRuntime } from './runtime-quickpick';
import { MINIMUM_RENV_VERSION, MINIMUM_R_VERSION } from './constants';
import { RRuntimeManager } from './runtime-manager';
import { RMetadataExtra } from './r-installation';
import { onDidDiscoverTestFiles } from './testing/testing';

export async function registerCommands(context: vscode.ExtensionContext, runtimeManager: RRuntimeManager) {

Expand Down Expand Up @@ -127,10 +128,10 @@ export async function registerCommands(context: vscode.ExtensionContext, runtime
}),

vscode.commands.registerCommand('r.packageTestExplorer', async () => {
vscode.commands.executeCommand('workbench.view.testing.focus');
// Wait for the test explorer to set up before running tests
await delay(500);
vscode.commands.executeCommand('testing.runAll');
await vscode.commands.executeCommand('workbench.view.testing.focus');
onDidDiscoverTestFiles(event => {
vscode.commands.executeCommand('testing.runAll');
});
}),

vscode.commands.registerCommand('r.useTestthat', async () => {
Expand Down
10 changes: 10 additions & 0 deletions extensions/positron-r/src/testing/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ import { detectRPackage, getRPackageName } from '../contexts';

let controller: vscode.TestController | undefined;

const _onDidDiscoverTestFiles = new vscode.EventEmitter<void>();

/**
* An event that fires after the test files are discovered.
*/
export const onDidDiscoverTestFiles = _onDidDiscoverTestFiles.event;


export async function setupTestExplorer(context: vscode.ExtensionContext) {
if (testExplorerEnabled()) {
return discoverTests(context);
Expand Down Expand Up @@ -64,6 +72,7 @@ export async function discoverTests(context: vscode.ExtensionContext) {
'R Package Test Explorer'
);
context.subscriptions.push(controller);
context.subscriptions.push(_onDidDiscoverTestFiles);

const testItemData = new WeakMap<vscode.TestItem, ItemType>();
const testingTools: TestingTools = {
Expand All @@ -86,6 +95,7 @@ export async function discoverTests(context: vscode.ExtensionContext) {
for (const watcher of watchers) {
context.subscriptions.push(watcher);
}
_onDidDiscoverTestFiles.fire();
LOGGER.info('Testthat file watchers are in place.');
}
};
Expand Down

0 comments on commit 17c8b70

Please sign in to comment.