Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 04:45 UTC
| 1 | /** |
| 2 | * Simplified e2e test API with auto-inferred cwd and suiteName. |
| 3 | */ |
| 4 | |
| 5 | import { dirname, relative } from 'node:path'; |
| 6 | import { fileURLToPath } from 'node:url'; |
| 7 | import type { E2EConfig } from './types'; |
| 8 | import { getRepoRoot } from './config'; |
| 9 | import { runE2E } from './runner'; |
| 10 | |
| 11 | /** |
| 12 | * Validate that the provided import.meta.url is a valid file:// URL. |
| 13 | */ |
| 14 | function validateImportMetaUrl(url: string): void { |
| 15 | if (!url) { |
| 16 | throw new Error('e2e(): import.meta.url is required as first argument'); |
| 17 | } |
| 18 | if (!url.startsWith('file://')) { |
| 19 | throw new Error( |
| 20 | `e2e(): import.meta.url must be a file:// URL, got: ${url}\n` + |
| 21 | 'Ensure you are calling e2e(import.meta.url, ...) from an ES module' |
| 22 | ); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Infer the working directory (cwd) from the caller's import.meta.url. |
| 28 | * Returns a path relative to the repository root. |
| 29 | */ |
| 30 | function inferCwd(importMetaUrl: string, repoRoot: string): string { |
| 31 | const callerPath = fileURLToPath(importMetaUrl); |
| 32 | const callerDir = dirname(callerPath); |
| 33 | const relativePath = relative(repoRoot, callerDir); |
| 34 | // Normalize to forward slashes for Docker |
| 35 | return relativePath.split(/[\\/]/).join('/'); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Run e2e tests with full bun:test capabilities. |
| 40 | * |
| 41 | * This function sets up bun:test describe/it blocks internally. |
| 42 | * When the test file is run via `bun test`, the full bun:test API |
| 43 | * is available in your defineTests callback. |
| 44 | * |
| 45 | * @param importMetaUrl - Pass `import.meta.url` from your test file |
| 46 | * @param config - Test configuration with defineTests callback |
| 47 | * |
| 48 | * @example |
| 49 | * ```typescript |
| 50 | * // e2e.test.ts |
| 51 | * import { e2e } from '@e2e-tests/utils'; |
| 52 | * import type { E2ETestResult } from '@e2e-tests/utils'; |
| 53 | * |
| 54 | * e2e(import.meta.url, { |
| 55 | * versions: { node: ['22.23.5', '24.22.3', '26.13.1'] }, |
| 56 | * env: { COMPOSIO_API_KEY: process.env.COMPOSIO_API_KEY }, |
| 57 | * defineTests: ({ describe, it, expect, beforeAll, runFixture }) => { |
| 58 | * let result: E2ETestResult; |
| 59 | * |
| 60 | * beforeAll(async () => { |
| 61 | * result = await runFixture({ filename: 'fixtures/test.mjs' }); |
| 62 | * }, TIMEOUTS.FIXTURE); |
| 63 | * |
| 64 | * describe('output', () => { |
| 65 | * it('exits successfully', () => { |
| 66 | * expect(result.exitCode).toBe(0); |
| 67 | * }); |
| 68 | * }); |
| 69 | * }, |
| 70 | * }); |
| 71 | * ``` |
| 72 | */ |
| 73 | export function e2e(importMetaUrl: string, config: E2EConfig): void { |
| 74 | validateImportMetaUrl(importMetaUrl); |
| 75 | |
| 76 | const repoRoot = getRepoRoot(); |
| 77 | const cwd = inferCwd(importMetaUrl, repoRoot); |
| 78 | const suiteName = cwd.split('/').pop() ?? 'unknown'; |
| 79 | |
| 80 | runE2E({ ...config, cwd, suiteName }); |
| 81 | } |