Skip to content

Commit 99d55e8

Browse files
committed
Fix unit test
1 parent eccd5ec commit 99d55e8

1 file changed

Lines changed: 28 additions & 7 deletions

File tree

src/solutions/active-solution-tracker.test.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { WorkspaceFolder } from 'vscode';
2121
import { URI } from 'vscode-uri';
2222
import * as path from 'path';
2323
import { waitForEvent, waitTimeout } from '../__test__/test-waits';
24+
import { waitForCondition } from '../__test__/wait-for-condition';
2425
import { messageProviderFactory } from '../vscode-api/message-provider.factories';
2526
import { commandsProviderFactory, MockCommandsProvider } from '../vscode-api/commands-provider.factories';
2627
import { MockFileWatcherProvider, fileWatcherProviderFactory } from '../vscode-api/file-watcher-provider.factories';
@@ -99,7 +100,11 @@ describe('ActiveSolutionTracker', () => {
99100

100101
it('searches for solution files on activation', async () => {
101102
await activeSolutionTracker.activate(context as unknown as vscode.ExtensionContext);
102-
await waitTimeout();
103+
await waitForCondition(
104+
async () => (vscode.workspace.findFiles as jest.Mock).mock.calls.length > 0,
105+
'solution file search to be triggered after activation',
106+
200,
107+
);
103108

104109
expect(vscode.workspace.findFiles).toHaveBeenCalledTimes(1);
105110
expect(vscode.workspace.findFiles).toHaveBeenCalledWith(ActiveSolutionTrackerImpl.GLOB_PATTERN, undefined);
@@ -110,15 +115,23 @@ describe('ActiveSolutionTracker', () => {
110115
configurationProvider.getConfigVariable.mockImplementation((name: string) => name === manifest.CONFIG_EXCLUDE ? testGlobPattern : undefined);
111116

112117
await activeSolutionTracker.activate(context as unknown as vscode.ExtensionContext);
113-
await waitTimeout();
118+
await waitForCondition(
119+
async () => (vscode.workspace.findFiles as jest.Mock).mock.calls.length > 0,
120+
'solution file search to be triggered with configured exclude glob',
121+
200,
122+
);
114123

115124
expect(vscode.workspace.findFiles).toHaveBeenCalledTimes(1);
116125
expect(vscode.workspace.findFiles).toHaveBeenCalledWith(ActiveSolutionTrackerImpl.GLOB_PATTERN, testGlobPattern);
117126
});
118127

119128
it('updates when the configured glob pattern changes', async () => {
120129
await activeSolutionTracker.activate(context as unknown as vscode.ExtensionContext);
121-
await waitTimeout();
130+
await waitForCondition(
131+
async () => (vscode.workspace.findFiles as jest.Mock).mock.calls.length > 0,
132+
'initial solution file search to complete',
133+
200,
134+
);
122135

123136
(vscode.workspace.findFiles as jest.Mock).mockClear();
124137

@@ -128,7 +141,11 @@ describe('ActiveSolutionTracker', () => {
128141
const testGlobPattern = faker.word.words();
129142
configurationProvider.getConfigVariable.mockImplementation((name: string) => name === manifest.CONFIG_EXCLUDE ? testGlobPattern : undefined);
130143
configurationProvider.onChangeConfiguration.mock.calls[0][0]();
131-
await waitTimeout();
144+
await waitForCondition(
145+
async () => (vscode.workspace.findFiles as jest.Mock).mock.calls.length > 0,
146+
'solution file search to run after configuration change',
147+
200,
148+
);
132149

133150
expect(vscode.workspace.findFiles).toHaveBeenCalledTimes(1);
134151
expect(vscode.workspace.findFiles).toHaveBeenCalledWith(ActiveSolutionTrackerImpl.GLOB_PATTERN, testGlobPattern);
@@ -139,7 +156,11 @@ describe('ActiveSolutionTracker', () => {
139156
(vscode.workspace.findFiles as jest.Mock).mockResolvedValue([]);
140157

141158
await activeSolutionTracker.activate(context as unknown as vscode.ExtensionContext);
142-
await waitTimeout();
159+
await waitForCondition(
160+
async () => (vscode.workspace.findFiles as jest.Mock).mock.calls.length > 0,
161+
'solution file search to complete in empty workspace',
162+
200,
163+
);
143164
});
144165

145166
it('has no solutions or active solution', () => {
@@ -227,7 +248,7 @@ describe('ActiveSolutionTracker', () => {
227248

228249
it('selects no active solution', async () => {
229250
await activeSolutionTracker.activate(context as unknown as vscode.ExtensionContext);
230-
await waitTimeout();
251+
await waitForEvent(activeSolutionTracker.onDidChangeSolutions);
231252

232253
expect(activeSolutionTracker.solutions).toEqual([
233254
SOLUTION_URI_BAR.fsPath,
@@ -489,7 +510,7 @@ describe('ActiveSolutionTracker solution file watching', () => {
489510
);
490511

491512
await tracker.activate(context as unknown as vscode.ExtensionContext);
492-
await waitTimeout();
513+
await waitForEvent(tracker.onDidChangeActiveSolution);
493514

494515
changeListener = jest.fn();
495516
tracker.onActiveSolutionFilesChanged(changeListener);

0 commit comments

Comments
 (0)