Skip to content

Commit cf0d028

Browse files
vaclavHalaVáclav HálaCopilotdmitrivMS
authored
Listen for added workspace folders to also testing.activateLegacyWorkspace() them (microsoft#26012)
Fixes microsoft#26011 --------- Co-authored-by: Václav Hála <vaclav.hala@codasip.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Dmitriy Vasyura <dmitriv@microsoft.com>
1 parent 757def8 commit cf0d028

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

src/client/testing/testController/controller.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,13 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
266266
workspaces.forEach((workspace) => {
267267
this.activateLegacyWorkspace(workspace);
268268
});
269+
this.disposables.push(
270+
this.workspaceService.onDidChangeWorkspaceFolders((evt) => {
271+
evt.added.forEach((workspace) => {
272+
this.activateLegacyWorkspace(workspace);
273+
});
274+
}),
275+
);
269276
}
270277

271278
/**

src/test/testing/testController/controller.unit.test.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ suite('PythonTestController', () => {
4646
sandbox.restore();
4747
});
4848

49-
function createController(options?: { unittestEnabled?: boolean; interpreter?: any }): any {
49+
function createController(options?: { unittestEnabled?: boolean; interpreter?: any; workspaceService?: any }): any {
5050
const unittestEnabled = options?.unittestEnabled ?? false;
5151
const interpreter =
5252
options?.interpreter ??
@@ -57,7 +57,7 @@ suite('PythonTestController', () => {
5757
sysPrefix: '/usr',
5858
} as any);
5959

60-
const workspaceService = ({ workspaceFolders: [] } as unknown) as any;
60+
const workspaceService = options?.workspaceService ?? (({ workspaceFolders: [] } as unknown) as any);
6161
const configSettings = ({
6262
getSettings: sandbox.stub().returns({
6363
testing: {
@@ -223,6 +223,35 @@ suite('PythonTestController', () => {
223223
assert.strictEqual(projects[0].projectUri.toString(), workspaceUri.toString());
224224
});
225225

226+
test('Tests can be discovered in workspace folder added after the extension has been activated', async () => {
227+
const addedFolder = vscode.Uri.file('/addedFolder');
228+
const addedWf: vscode.WorkspaceFolder = { uri: addedFolder } as any;
229+
const onDidChangeWorkspaceFolders = new vscode.EventEmitter<vscode.WorkspaceFoldersChangeEvent>();
230+
sandbox.stub(envExtApiInternal, 'useEnvExtension').returns(false);
231+
const fakeDiscoveryAdapter = sandbox.stub().resolves(undefined);
232+
sandbox.stub(projectUtils, 'createTestAdapters').returns({
233+
discoveryAdapter: { discoverTests: fakeDiscoveryAdapter },
234+
} as any);
235+
236+
const controller: PythonTestController = createController({
237+
unittestEnabled: true,
238+
workspaceService: {
239+
workspaceFolders: [],
240+
onDidChangeWorkspaceFolders: onDidChangeWorkspaceFolders.event,
241+
getWorkspaceFolder: (uri: vscode.Uri) => (uri === addedFolder ? addedWf : undefined),
242+
},
243+
});
244+
await controller.activate();
245+
246+
onDidChangeWorkspaceFolders.fire({
247+
added: [addedWf],
248+
removed: [],
249+
});
250+
251+
await controller.refreshTestData(addedFolder, { forceRefresh: true });
252+
assert.strictEqual(fakeDiscoveryAdapter.calledWith(addedFolder), true);
253+
});
254+
226255
test('filters Python projects to workspace and creates adapters for each', async () => {
227256
const workspaceUri: Uri = vscode.Uri.file('/workspace/root');
228257

0 commit comments

Comments
 (0)