|
| 1 | +import '../common/index.mjs'; |
| 2 | +import * as fixtures from '../common/fixtures.mjs'; |
| 3 | +import tmpdir from '../common/tmpdir.js'; |
| 4 | + |
| 5 | +import assert from 'assert'; |
| 6 | +import { execFileSync } from 'child_process'; |
| 7 | +import fs from 'fs'; |
| 8 | +import path from 'path'; |
| 9 | + |
| 10 | +const docToolingDir = path.join(import.meta.dirname, '..', '..', 'tools', 'doc') |
| 11 | +const apilinks = fixtures.path('apilinks'); |
| 12 | + |
| 13 | +tmpdir.refresh(); |
| 14 | + |
| 15 | +fs.readdirSync(apilinks).forEach((fixture) => { |
| 16 | + if (!fixture.endsWith('.js')) return; |
| 17 | + const input = path.join(apilinks, fixture); |
| 18 | + |
| 19 | + const expectedContent = fs.readFileSync(`${input}on`, 'utf8'); |
| 20 | + const outputPath = tmpdir.resolve(`${fixture}on`); |
| 21 | + |
| 22 | + fs.mkdirSync(outputPath); |
| 23 | + |
| 24 | + execFileSync( |
| 25 | + 'npx', |
| 26 | + ['--prefix', docToolingDir, 'api-docs-tooling', 'generate', '-t', 'api-links', '-i', input, '-o', outputPath, '--no-lint'], |
| 27 | + { encoding: 'utf-8' } |
| 28 | + ); |
| 29 | + |
| 30 | + const expectedLinks = JSON.parse(expectedContent); |
| 31 | + const actualLinks = JSON.parse(fs.readFileSync(path.join(outputPath, 'apilinks.json'))); |
| 32 | + |
| 33 | + for (const [k, v] of Object.entries(expectedLinks)) { |
| 34 | + assert.ok(k in actualLinks, `link not found: ${k}`); |
| 35 | + assert.ok(actualLinks[k].endsWith('/' + v), |
| 36 | + `link ${actualLinks[k]} expected to end with ${v}`); |
| 37 | + delete actualLinks[k]; |
| 38 | + } |
| 39 | + |
| 40 | + assert.strictEqual( |
| 41 | + Object.keys(actualLinks).length, 0, |
| 42 | + `unexpected links returned ${JSON.stringify(actualLinks)}`, |
| 43 | + ); |
| 44 | +}) |
0 commit comments