-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsetup.ts
More file actions
45 lines (39 loc) · 1.06 KB
/
Copy pathsetup.ts
File metadata and controls
45 lines (39 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { cp } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { simpleGit } from 'simple-git';
import { nxTargetProject } from '@code-pushup/test-nx-utils';
import {
E2E_ENVIRONMENTS_DIR,
TEST_OUTPUT_DIR,
initGitRepo,
restoreNxIgnoredFiles,
simulateGitFetch,
teardownTestFolder,
} from '@code-pushup/test-utils';
export type TestRepo = Awaited<ReturnType<typeof setupTestRepo>>;
export async function setupTestRepo(folder: string) {
const fixturesDir = path.join(
fileURLToPath(path.dirname(import.meta.url)),
'fixtures',
folder,
);
const baseDir = path.join(
process.cwd(),
E2E_ENVIRONMENTS_DIR,
nxTargetProject(),
TEST_OUTPUT_DIR,
folder,
);
await cp(fixturesDir, baseDir, { recursive: true });
await restoreNxIgnoredFiles(baseDir);
const git = await initGitRepo(simpleGit, { baseDir });
await simulateGitFetch(git);
await git.add('.');
await git.commit('Initial commit');
return {
git,
baseDir,
cleanup: () => teardownTestFolder(baseDir),
};
}