Skip to content

Commit

Permalink
fix: Workspaces for update-versions script (#4783)
Browse files Browse the repository at this point in the history
* Fix workspaces for update-versions script

* Add unit test
  • Loading branch information
sw-joelmut authored Nov 1, 2024
1 parent 38e4678 commit 3dd1c6a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion libraries/botbuilder-repo-utils/src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface Package {
deprecated?: boolean;
internal?: boolean;

workspaces?: string[];
workspaces?: { packages: string[] };

dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-repo-utils/src/updateVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const command = (argv: string[], quiet = false) => async (): Promise<Resu
const commitSha = JSON.parse(flags.git) ? await gitSha('HEAD') : undefined;

// Collect all workspaces from the repo root. Returns workspaces with absolute paths.
const workspaces = await collectWorkspacePackages(repoRoot, packageFile.workspaces);
const workspaces = await collectWorkspacePackages(repoRoot, packageFile.workspaces?.packages);

// Build an object mapping a package name to its new, updated version
const workspaceVersions = workspaces.reduce<Record<string, string>>(
Expand Down
41 changes: 35 additions & 6 deletions libraries/botbuilder-repo-utils/tests/updateVersions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('updateVersions', function () {
dependsOn?: string[];
}>,
args: string[] = [],
{ commitSha = '' } = {}
{ commitSha = '' } = {},
) => {
const root = 'root';

Expand Down Expand Up @@ -200,7 +200,7 @@ describe('updateVersions', function () {
.withArgs(path.join(root, 'package.json'))
.resolves({
version: packageVersion,
workspaces: workspacePaths.map((workspace) => path.posix.join(...workspace.relPath)),
workspaces: { packages: workspacePaths.map((workspace) => path.posix.join(...workspace.relPath)) },
});

sandbox
Expand All @@ -219,14 +219,14 @@ describe('updateVersions', function () {
deprecated: workspace.deprecated,
dependencies: (workspace.dependsOn ?? []).reduce(
(acc, name) => ({ ...acc, [name]: dummyVersion }),
{}
{},
),
});

let packageMatch = sinon.match.hasOwn('version', workspace.expectedVersion);
if (workspace.expectedDependencies) {
packageMatch = packageMatch.and(
sinon.match.hasOwn('dependencies', sinon.match(workspace.expectedDependencies))
sinon.match.hasOwn('dependencies', sinon.match(workspace.expectedDependencies)),
);
}

Expand Down Expand Up @@ -300,7 +300,7 @@ describe('updateVersions', function () {
},
},
],
[expectedVersion]
[expectedVersion],
);
});

Expand Down Expand Up @@ -339,8 +339,37 @@ describe('updateVersions', function () {
},
],
['--buildLabel', 'dev', '--git', 'true', '--date', dateFormat],
{ commitSha: 'COMMIT' }
{ commitSha: 'COMMIT' },
);
});

it('runs properly', async function () {
const writeFileStub = sandbox.stub(file, 'writeJsonFile').returns(Promise.resolve());
const version = '4.24.0';
await command(
[
version,
'--buildLabel',
'dev',
'--internal',
'internal',
'--preview',
'preview',
'--deprecated',
'deprecated',
'--date',
'YYYYMMDD',
'--git',
'false',
],
true,
)();

assert.ok(writeFileStub.called);
const packagesAssertion = (writeFileStub.args as [string, Package][])
.filter(([, pkg]) => !pkg.private)
.every(([, pkg]) => pkg.version.startsWith(version));
assert.ok(packagesAssertion);
});
});
});

0 comments on commit 3dd1c6a

Please sign in to comment.