Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sw-joelmut committed Nov 1, 2024
1 parent e51f9ea commit 4e6edad
Showing 1 changed file with 35 additions and 6 deletions.
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 4e6edad

Please sign in to comment.