From 25f7eac5eced28ee39695d78021c0185f656336e Mon Sep 17 00:00:00 2001 From: Elizabeth Craig Date: Thu, 4 May 2023 15:39:03 -0700 Subject: [PATCH] minor test fixes --- src/__e2e__/change.test.ts | 5 +++-- src/__e2e__/publishRegistry.test.ts | 6 ++---- src/__fixtures__/repository.ts | 9 ++++++++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/__e2e__/change.test.ts b/src/__e2e__/change.test.ts index 714e0f8e0..3238d9194 100644 --- a/src/__e2e__/change.test.ts +++ b/src/__e2e__/change.test.ts @@ -169,6 +169,7 @@ describe('change command', () => { makeMonorepoChanges(repo); const changePromise = change({ path: repo.rootPath, branch: defaultBranchName } as BeachballOptions); + await waitForPrompt(); // use custom values for first package expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: pkg-1'); @@ -212,6 +213,7 @@ describe('change command', () => { branch: defaultBranchName, groupChanges: true, } as BeachballOptions); + await waitForPrompt(); // use custom values for first package expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: pkg-1'); @@ -242,6 +244,7 @@ describe('change command', () => { const repo = repositoryFactory.cloneRepository(); makeMonorepoChanges(repo); + // custom prompt for different packages (only truly doable here because elsewhere it uses combinedOptions) mockBeachballOptions = { changeFilePrompt: { changePrompt: (defaultPrompt, pkg) => { @@ -284,6 +287,4 @@ describe('change command', () => { expect.objectContaining({ packageName: 'pkg-2', type: 'patch', comment: 'commit 2', custom: 'stuff' }), ]); }); - - // custom prompt for different packages (only truly doable here because elsewhere it uses combinedOptions) }); diff --git a/src/__e2e__/publishRegistry.test.ts b/src/__e2e__/publishRegistry.test.ts index eb780a669..98c5f44d5 100644 --- a/src/__e2e__/publishRegistry.test.ts +++ b/src/__e2e__/publishRegistry.test.ts @@ -15,7 +15,7 @@ describe('publish command (registry)', () => { let repositoryFactory: RepositoryFactory | undefined; // show error logs for these tests - const logs = initMockLogs(['error']); + const logs = initMockLogs({ alsoLog: ['error'] }); function getOptions(repo: Repository, overrides: Partial): BeachballOptions { return { @@ -177,8 +177,6 @@ describe('publish command (registry)', () => { ); await expect(publishPromise).rejects.toThrow(); - expect( - logs.mocks.log.mock.calls.some(([arg0]) => typeof arg0 === 'string' && arg0.includes('Retrying... (3/3)')) - ).toBeTruthy(); + expect(logs.getMockLines('log')).toMatch('Retrying... (3/3)'); }); }); diff --git a/src/__fixtures__/repository.ts b/src/__fixtures__/repository.ts index 1cc661c94..991ee0d6c 100644 --- a/src/__fixtures__/repository.ts +++ b/src/__fixtures__/repository.ts @@ -1,8 +1,8 @@ import path from 'path'; import * as fs from 'fs-extra'; -import { tmpdir } from './tmpdir'; import { git } from 'workspace-tools'; import { defaultBranchName, defaultRemoteName, setDefaultBranchName } from './gitDefaults'; +import { tmpdir } from './tmpdir'; /** * Represents a git repository. @@ -72,6 +72,13 @@ ${gitResult.stderr.toString()}`); return gitResult; } + /** Log the results of a git command to non-wrapped console.log (for debugging) */ + async gitConsoleLog(args: string[]) { + realConsole.log(`$ git ${args.join(' ')}`); + const res = await execa('git', args, { cwd: this.rootPath, all: true, reject: false }); + realConsole.log(res.all); + } + /** * Create (or update) and stage a file, creating the intermediate directories if necessary. * Automatically uses root path; do not pass absolute paths here.