| |
| |
| |
| |
|
|
| import * as os from 'os'; |
| import * as path from 'path'; |
|
|
| |
| |
| |
| export function getWorkspaceRoot(): string { |
| const cwd = process.cwd(); |
| if (cwd.includes('apps/ui')) { |
| return path.resolve(cwd, '../..'); |
| } |
| return cwd; |
| } |
|
|
| |
| export const TEST_BASE_DIR = path.join(getWorkspaceRoot(), 'test'); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function assertSafeProjectPath(projectPath: string): void { |
| const normalized = path.resolve(projectPath); |
| const workspaceRoot = path.resolve(getWorkspaceRoot()); |
| const testBase = path.resolve(TEST_BASE_DIR); |
| const tmpDir = path.resolve(os.tmpdir()); |
|
|
| if (normalized === workspaceRoot) { |
| throw new Error( |
| `E2E project path must not be the workspace root (${workspaceRoot}). ` + |
| 'Use a path under test/ or os.tmpdir() to avoid affecting the main project git state.' |
| ); |
| } |
|
|
| const underTest = normalized.startsWith(testBase + path.sep) || normalized === testBase; |
| const underTmp = normalized.startsWith(tmpDir + path.sep) || normalized === tmpDir; |
| if (!underTest && !underTmp) { |
| throw new Error( |
| `E2E project path must be under test/ or temp directory to avoid affecting main project git. ` + |
| `Got: ${normalized} (workspace root: ${workspaceRoot})` |
| ); |
| } |
| } |
|
|