fix: stabilize e2e flow in clean CI env

Signed-off-by: majiayu000 <majiayu000@users.noreply.github.com>
This commit is contained in:
majiayu000
2026-03-27 17:19:31 +08:00
parent bc608e97bd
commit 83f9193749
11 changed files with 146 additions and 92 deletions

View File

@@ -9,6 +9,11 @@ import { rm } from 'fs';
const fsExec = promisify(exec);
const fsRemove = promisify(rm);
const waitForCommitConfirmation = async (findByText: any) => {
expect(await findByText('Generating the commit message')).toBeInTheConsole();
expect(await findByText('Confirm the commit message?')).toBeInTheConsole();
};
/**
* git remote -v
*
@@ -97,7 +102,7 @@ describe('cli flow to push git branch', () => {
[resolve('./out/cli.cjs')],
{ cwd: gitDir }
);
expect(await findByText('Confirm the commit message?')).toBeInTheConsole();
await waitForCommitConfirmation(findByText);
userEvent.keyboard('[Enter]');
expect(
@@ -129,7 +134,7 @@ describe('cli flow to push git branch', () => {
[resolve('./out/cli.cjs')],
{ cwd: gitDir }
);
expect(await findByText('Confirm the commit message?')).toBeInTheConsole();
await waitForCommitConfirmation(findByText);
userEvent.keyboard('[Enter]');
expect(
@@ -162,7 +167,7 @@ describe('cli flow to push git branch', () => {
[resolve('./out/cli.cjs')],
{ cwd: gitDir }
);
expect(await findByText('Confirm the commit message?')).toBeInTheConsole();
await waitForCommitConfirmation(findByText);
userEvent.keyboard('[Enter]');
expect(
@@ -190,7 +195,7 @@ describe('cli flow to push git branch', () => {
[resolve('./out/cli.cjs')],
{ cwd: gitDir }
);
expect(await findByText('Confirm the commit message?')).toBeInTheConsole();
await waitForCommitConfirmation(findByText);
userEvent.keyboard('[Enter]');
expect(await findByText('Choose a remote to push to')).toBeInTheConsole();

View File

@@ -3,6 +3,10 @@ import { render } from 'cli-testing-library';
import 'cli-testing-library/extend-expect';
import { prepareEnvironment, wait } from '../utils';
import path from 'path';
import { execFile } from 'child_process';
import { promisify } from 'util';
const execFileAsync = promisify(execFile);
function getAbsolutePath(relativePath: string) {
// Use process.cwd() which should be the project root during test execution
@@ -27,9 +31,10 @@ async function setupCommitlint(dir: string, ver: 9 | 18 | 19) {
configPath = getAbsolutePath('./data/commitlint_19/commitlint.config.js');
break;
}
await render('cp', ['-r', packagePath, '.'], { cwd: dir });
await render('cp', [packageJsonPath, '.'], { cwd: dir });
await render('cp', [configPath, '.'], { cwd: dir });
await execFileAsync('cp', ['-R', packagePath, path.join(dir, 'node_modules')]);
await execFileAsync('cp', [packageJsonPath, path.join(dir, 'package.json')]);
await execFileAsync('cp', [configPath, path.join(dir, 'commitlint.config.js')]);
await wait(3000); // Avoid flakiness by waiting
}