test(dev-infra): always use same virtual git client instance in publish tests (#42468)

With the recent refactorings to `GitClient`, where singletons
are created and can be retrieved through a static method, the
test has been updated to also install spies for the static methods
of `GitClient`. This commit updates the spy installation so that
the same mock git client is used that is also passed manually to
the release actions. Having two separate instances of the mock
git client could result in false-positive test results.

PR Close #42468
This commit is contained in:
Paul Gschwendtner 2021-06-03 16:53:55 +02:00 committed by Jessica Janiuk
parent 67f65a9d25
commit 1684b70b88
2 changed files with 4 additions and 5 deletions

View File

@ -68,9 +68,6 @@ export function getTestingMocksForReleaseAction() {
export function setupReleaseActionForTesting<T extends ReleaseAction>(
actionCtor: ReleaseActionConstructor<T>, active: ActiveReleaseTrains,
isNextPublishedToNpm = true): TestReleaseAction<T> {
installVirtualGitClientSpies();
installMockReleaseNotes();
// Reset existing HTTP interceptors.
nock.cleanAll();
@ -78,6 +75,9 @@ export function setupReleaseActionForTesting<T extends ReleaseAction>(
const repo = new GithubTestingRepo(githubConfig.owner, githubConfig.name);
const fork = new GithubTestingRepo('some-user', 'fork');
installVirtualGitClientSpies(gitClient);
installMockReleaseNotes();
// The version for the release-train in the next phase does not necessarily need to be
// published to NPM. We mock the NPM package request and fake the state of the next
// version based on the `isNextPublishedToNpm` testing parameter. More details on the

View File

@ -203,8 +203,7 @@ export class VirtualGitClient extends AuthenticatedGitClient {
}
}
export function installVirtualGitClientSpies() {
const mockInstance = VirtualGitClient.createInstance();
export function installVirtualGitClientSpies(mockInstance = VirtualGitClient.createInstance()) {
spyOn(GitClient, 'get').and.returnValue(mockInstance);
spyOn(AuthenticatedGitClient, 'get').and.returnValue(mockInstance);
}