From a3b01e830ea69a20ed141012c399bac49d123869 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 3 Jun 2021 16:53:55 +0200 Subject: [PATCH] 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 --- dev-infra/release/publish/test/test-utils.ts | 6 +++--- dev-infra/utils/testing/virtual-git-client.ts | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/dev-infra/release/publish/test/test-utils.ts b/dev-infra/release/publish/test/test-utils.ts index 43a65eb2323..ddbc36e8477 100644 --- a/dev-infra/release/publish/test/test-utils.ts +++ b/dev-infra/release/publish/test/test-utils.ts @@ -68,9 +68,6 @@ export function getTestingMocksForReleaseAction() { export function setupReleaseActionForTesting( actionCtor: ReleaseActionConstructor, active: ActiveReleaseTrains, isNextPublishedToNpm = true): TestReleaseAction { - installVirtualGitClientSpies(); - installMockReleaseNotes(); - // Reset existing HTTP interceptors. nock.cleanAll(); @@ -78,6 +75,9 @@ export function setupReleaseActionForTesting( 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 diff --git a/dev-infra/utils/testing/virtual-git-client.ts b/dev-infra/utils/testing/virtual-git-client.ts index 363a53bee9b..b67fba69c37 100644 --- a/dev-infra/utils/testing/virtual-git-client.ts +++ b/dev-infra/utils/testing/virtual-git-client.ts @@ -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); }