Skip to content

Commit 2b2fcf9

Browse files
Copilotdmichon-msft
andcommitted
Add tests for VersionPolicyProjectSelectorParser and SubspaceSelectorParser
Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com>
1 parent d54f4bb commit 2b2fcf9

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

libraries/rush-lib/src/logic/selectors/test/SelectorParsers.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { RushConfiguration } from '../../../api/RushConfiguration';
99
import { NamedProjectSelectorParser } from '../NamedProjectSelectorParser';
1010
import { TagProjectSelectorParser } from '../TagProjectSelectorParser';
1111
import { PathProjectSelectorParser } from '../PathProjectSelectorParser';
12+
import { VersionPolicyProjectSelectorParser } from '../VersionPolicyProjectSelectorParser';
13+
import { SubspaceSelectorParser } from '../SubspaceSelectorParser';
1214

1315
describe('SelectorParsers', () => {
1416
let rushConfiguration: RushConfiguration;
@@ -192,4 +194,54 @@ describe('SelectorParsers', () => {
192194
expect(completions).toHaveLength(0);
193195
});
194196
});
197+
198+
describe(VersionPolicyProjectSelectorParser.name, () => {
199+
let parser: VersionPolicyProjectSelectorParser;
200+
201+
beforeEach(() => {
202+
parser = new VersionPolicyProjectSelectorParser(rushConfiguration);
203+
});
204+
205+
it('should return empty completions when no version policies exist', () => {
206+
// The test fixture doesn't have version policies configured
207+
const completions = Array.from(parser.getCompletions());
208+
expect(completions).toHaveLength(0);
209+
});
210+
211+
it('should throw error for non-existent version policy', async () => {
212+
await expect(
213+
parser.evaluateSelectorAsync({
214+
unscopedSelector: 'nonexistent-policy',
215+
terminal,
216+
parameterName: '--only'
217+
})
218+
).rejects.toThrow();
219+
});
220+
});
221+
222+
describe(SubspaceSelectorParser.name, () => {
223+
let parser: SubspaceSelectorParser;
224+
225+
beforeEach(() => {
226+
parser = new SubspaceSelectorParser(rushConfiguration);
227+
});
228+
229+
it('should return completions based on configuration', () => {
230+
const completions = Array.from(parser.getCompletions());
231+
// The test fixture doesn't have subspaces configured, so completions may be empty
232+
expect(Array.isArray(completions)).toBe(true);
233+
});
234+
235+
it('should select projects from default subspace', async () => {
236+
const result = await parser.evaluateSelectorAsync({
237+
unscopedSelector: 'default',
238+
terminal,
239+
parameterName: '--only'
240+
});
241+
242+
const projects = Array.from(result);
243+
// Should get projects from the default subspace
244+
expect(projects.length).toBeGreaterThan(0);
245+
});
246+
});
195247
});

0 commit comments

Comments
 (0)