| 1 | import { execFileSync } from 'node:child_process'; |
| 2 | import { mkdirSync, mkdtempSync |
| 3 | import { tmpdir } |
| 4 | import path from 'node:path |
| 5 | import { afterEach, beforeEach |
| 6 | |
| 7 | import { MAX_BLOB_BYTES, readBlob |
| 8 | |
| 9 | describe('readBlob', () |
| 10 | let root: |
| 11 | let gitDir: |
| 12 | |
| 13 | beforeEach(() => |
| 14 | root = mkdtempSync( |
| 15 | gitDir = path. |
| 16 | const env = |
| 17 | delete env.GIT_DIR; |
| 18 | const git = |
| 19 | execFileSync('git', |
| 20 | |
| 21 | execFileSync('git', |
| 22 | git('config', |
| 23 | git('config', |
| 24 | mkdirSync(path.join |
| 25 | writeFileSync(path.join |
| 26 | writeFileSync(path.join |
| 27 | writeFileSync(path.join |
| 28 | git('add', |
| 29 | git('commit', |
| 30 | }); |
| 31 | |
| 32 | afterEach(() => |
| 33 | |
| 34 | it('reads a file at a ref', |
| 35 | const blob = |
| 36 | |
| 37 | expect(blob?.size |
| 38 | expect(blob?.content |
| 39 | }); |
| 40 | |
| 41 | it('reads binary contents byte for byte', |
| 42 | const blob = |
| 43 | |
| 44 | expect([...(blob |
| 45 | }); |
| 46 | |
| 47 | it('reports size but no contents past the inline limit', |
| 48 | const blob = |
| 49 | |
| 50 | expect(blob?.size |
| 51 | expect(blob?.content |
| 52 | }); |
| 53 | |
| 54 | it('streams bytes past the inline limit', |
| 55 | const big = |
| 56 | const chunks: |
| 57 | for await (const |
| 58 | chunks.push(chunk |
| 59 | } |
| 60 | |
| 61 | expect(Buffer.concat |
| 62 | }); |
| 63 | |
| 64 | it('returns null for a directory, a missing path, and a missing ref', |
| 65 | expect(await readBlob |
| 66 | expect(await readBlob |
| 67 | expect( |
| 68 | await readBlob({ |
| 69 | ).toBeNull(); |
| 70 | }); |
| 71 | }); |