test: refactor to run asynchronously (#174)

This commit is contained in:
hiroki osame
2023-03-27 05:44:16 -04:00
committed by GitHub
parent a0db0f3ece
commit e431444f95
7 changed files with 193 additions and 187 deletions

View File

@@ -1,18 +1,17 @@
import path from 'path';
import { execa, execaNode, type Options } from 'execa';
import {
createFixture as createFixtureBase,
type FileTree,
type FsFixture,
} from 'fs-fixture';
const aicommitsPath = path.resolve('./dist/cli.mjs');
export const createAicommits = ({
cwd,
home,
}: {
cwd?: string;
home: string;
}) => {
const createAicommits = (fixture: FsFixture) => {
const homeEnv = {
HOME: home, // Linux
USERPROFILE: home, // Windows
HOME: fixture.path, // Linux
USERPROFILE: fixture.path, // Windows
};
return (
@@ -20,7 +19,7 @@ export const createAicommits = ({
options?: Options,
) => execaNode(aicommitsPath, args, {
...options,
cwd,
cwd: fixture.path,
extendEnv: false,
env: {
...homeEnv,
@@ -61,3 +60,15 @@ export const createGit = async (cwd: string) => {
return git;
};
export const createFixture = async (
source?: string | FileTree,
) => {
const fixture = await createFixtureBase(source);
const aicommits = createAicommits(fixture);
return {
fixture,
aicommits,
};
};