Skip to content

Commit 395cc75

Browse files
Copiloticlanton
andcommitted
Address code review feedback: make workingDirectory required and add comprehensive tests
Co-authored-by: iclanton <5010588+iclanton@users.noreply.github.com>
1 parent b597b97 commit 395cc75

9 files changed

Lines changed: 67 additions & 9 deletions

File tree

libraries/rush-lib/src/api/test/RushConfiguration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe(RushConfiguration.name, () => {
7777
expect(rushConfiguration.projectFolderMinDepth).toEqual(1);
7878
expect(rushConfiguration.hotfixChangeEnabled).toEqual(true);
7979

80-
expect(rushConfiguration.projects).toHaveLength(3);
80+
expect(rushConfiguration.projects).toHaveLength(5);
8181

8282
// "approvedPackagesPolicy" feature
8383
const approvedPackagesPolicy: ApprovedPackagesPolicy = rushConfiguration.approvedPackagesPolicy;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "app1",
3+
"version": "1.0.0",
4+
"description": "Test app 1"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "app2",
3+
"version": "1.0.0",
4+
"description": "Test app 2"
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"definitionName": "lockStepVersion",
4+
"policyName": "testPolicy",
5+
"version": "1.0.0",
6+
"nextBump": "minor"
7+
}
8+
]

libraries/rush-lib/src/api/test/repo/rush-npm.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"packageName": "project1",
2929
"projectFolder": "project1",
3030
"reviewCategory": "third-party",
31-
"tags": ["frontend", "ui"]
31+
"tags": ["frontend", "ui"],
32+
"versionPolicyName": "testPolicy"
3233
},
3334

3435
{
@@ -43,7 +44,20 @@
4344
"packageName": "project3",
4445
"projectFolder": "project3",
4546
"reviewCategory": "prototype",
46-
"tags": ["frontend"]
47+
"tags": ["frontend"],
48+
"versionPolicyName": "testPolicy"
49+
},
50+
51+
{
52+
"packageName": "app1",
53+
"projectFolder": "apps/app1",
54+
"reviewCategory": "first-party"
55+
},
56+
57+
{
58+
"packageName": "app2",
59+
"projectFolder": "apps/app2",
60+
"reviewCategory": "first-party"
4761
}
4862
]
4963
}

libraries/rush-lib/src/cli/parsing/SelectionParameterSet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class SelectionParameterSet {
7373
selectorParsers.set('tag', new TagProjectSelectorParser(rushConfiguration));
7474
selectorParsers.set('version-policy', new VersionPolicyProjectSelectorParser(rushConfiguration));
7575
selectorParsers.set('subspace', new SubspaceSelectorParser(rushConfiguration));
76-
selectorParsers.set('path', new PathProjectSelectorParser(rushConfiguration));
76+
selectorParsers.set('path', new PathProjectSelectorParser(rushConfiguration, process.cwd()));
7777

7878
this._selectorParserByScope = selectorParsers;
7979

libraries/rush-lib/src/logic/selectors/PathProjectSelectorParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export class PathProjectSelectorParser implements ISelectorParser<RushConfigurat
1515
private readonly _rushConfiguration: RushConfiguration;
1616
private readonly _workingDirectory: string;
1717

18-
public constructor(rushConfiguration: RushConfiguration, workingDirectory?: string) {
18+
public constructor(rushConfiguration: RushConfiguration, workingDirectory: string) {
1919
this._rushConfiguration = rushConfiguration;
20-
this._workingDirectory = workingDirectory ?? process.cwd();
20+
this._workingDirectory = workingDirectory;
2121
}
2222

2323
public async evaluateSelectorAsync({

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ describe(PathProjectSelectorParser.name, () => {
6262
expect(packageNames).toContain('project3');
6363
});
6464

65+
it('should select multiple projects from a shared subfolder', async () => {
66+
const result = await parser.evaluateSelectorAsync({
67+
unscopedSelector: 'apps',
68+
terminal,
69+
parameterName: '--only'
70+
});
71+
72+
const projects = Array.from(result);
73+
expect(projects).toHaveLength(2);
74+
const packageNames = projects.map((p) => p.packageName).sort();
75+
expect(packageNames).toEqual(['app1', 'app2']);
76+
});
77+
6578
it('should select project from specified directory', async () => {
6679
const project1Path = path.join(rushConfiguration.rushJsonFolder, 'project1');
6780
const parserWithCustomCwd = new PathProjectSelectorParser(rushConfiguration, project1Path);

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,23 @@ describe(VersionPolicyProjectSelectorParser.name, () => {
2222
parser = new VersionPolicyProjectSelectorParser(rushConfiguration);
2323
});
2424

25-
it('should return empty completions when no version policies exist', () => {
26-
// The test fixture doesn't have version policies configured
25+
it('should return completions for version policies', () => {
2726
const completions = Array.from(parser.getCompletions());
28-
expect(completions).toHaveLength(0);
27+
expect(completions.length).toBeGreaterThan(0);
28+
expect(completions).toContain('testPolicy');
29+
});
30+
31+
it('should select projects by version policy', async () => {
32+
const result = await parser.evaluateSelectorAsync({
33+
unscopedSelector: 'testPolicy',
34+
terminal,
35+
parameterName: '--only'
36+
});
37+
38+
const projects = Array.from(result);
39+
expect(projects).toHaveLength(2);
40+
const packageNames = projects.map((p) => p.packageName).sort();
41+
expect(packageNames).toEqual(['project1', 'project3']);
2942
});
3043

3144
it('should throw error for non-existent version policy', async () => {

0 commit comments

Comments
 (0)