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