| 46 | } |
| 47 | |
| 48 | export function createTestDiffFile({ |
| 49 | after = "const alpha = 10;\nconst beta = 2;\nconst gamma = 30;\nconst stable = true;\n", |
| 50 | before = "const alpha = 1;\nconst beta = 2;\nconst gamma = 3;\nconst stable = true;\n", |
| 51 | id = "example", |
| 52 | language = "typescript", |
| 53 | path = "example.ts", |
| 54 | previousPath, |
| 55 | context = 0, |
| 56 | agent = null, |
| 57 | sourceFetcher, |
| 58 | }: { |
| 59 | after?: string; |
| 60 | before?: string; |
| 61 | id?: string; |
| 62 | language?: string; |
| 63 | path?: string; |
| 64 | previousPath?: string; |
| 65 | context?: number; |
| 66 | agent?: DiffFile["agent"] | boolean; |
| 67 | sourceFetcher?: FileSourceFetcher; |
| 68 | } = {}): DiffFile { |
| 69 | const metadata = parseDiffFromFile( |
| 70 | { cacheKey: `${id}:before`, contents: before, name: path }, |
| 71 | { cacheKey: `${id}:after`, contents: after, name: path }, |
| 72 | { context }, |
| 73 | true, |
| 74 | ); |
| 75 | |
| 76 | return { |
| 77 | agent: agent === true ? createTestAgentFileContext(path) : agent === false ? null : agent, |
| 78 | id, |
| 79 | language, |
| 80 | metadata, |
| 81 | patch: "", |
| 82 | path, |
| 83 | previousPath, |
| 84 | sourceFetcher, |
| 85 | stats: collectChangeStats(metadata), |
| 86 | }; |
| 87 | } |
| 88 | |
| 89 | /** Build a promise handle that lets async tests settle work manually. */ |
| 90 | export function createTestDeferred<T>() { |