| 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 { findReadmePath } |
| 8 | |
| 9 | describe('findReadmePath', () |
| 10 | let root: |
| 11 | let gitDir: |
| 12 | let git: |
| 13 | |
| 14 | beforeEach(() => |
| 15 | root = mkdtempSync( |
| 16 | gitDir = path. |
| 17 | const env = |
| 18 | delete env.GIT_DIR; |
| 19 | git = (... |
| 20 | execFileSync('git', |
| 21 | |
| 22 | execFileSync('git', |
| 23 | git('config', |
| 24 | git('config', |
| 25 | }); |
| 26 | |
| 27 | afterEach(() => |
| 28 | |
| 29 | const commit = |
| 30 | for (const [file |
| 31 | mkdirSync(path.join |
| 32 | writeFileSync(path.join |
| 33 | } |
| 34 | git('add', |
| 35 | git('commit', |
| 36 | }; |
| 37 | |
| 38 | it('finds the root README', |
| 39 | commit({ 'README.md' |
| 40 | |
| 41 | expect(await findReadmePath |
| 42 | }); |
| 43 | |
| 44 | it('matches any casing', |
| 45 | commit({ 'ReadMe.MD' |
| 46 | |
| 47 | expect(await findReadmePath |
| 48 | }); |
| 49 | |
| 50 | it('prefers the markdown one over the extensionless one', |
| 51 | commit({ README: |
| 52 | |
| 53 | expect(await findReadmePath |
| 54 | }); |
| 55 | |
| 56 | it('ignores a directory named like a README', |
| 57 | commit({ 'readme/notes.txt' |
| 58 | |
| 59 | expect(await findReadmePath |
| 60 | }); |
| 61 | |
| 62 | it('never looks below the directory it was given', |
| 63 | commit({ 'docs/README.md' |
| 64 | |
| 65 | expect(await findReadmePath |
| 66 | expect(await findReadmePath |
| 67 | 'docs/README.md', |
| 68 | ); |
| 69 | }); |
| 70 | |
| 71 | it('is null on a ref that does not exist', |
| 72 | expect(await findReadmePath |
| 73 | }); |
| 74 | }); |