node/test/doctool/test-apilinks.mjs
Michaël Zasso de01f475d5
tools: update doctool dependencies, migrate to ESM
- Migrated to ESM because some dependencies now require it.
- Did not update `highlight.js` to v11 because it has many breaking
  changes.
- Used non-deprecated `highlight.js` API.

Refs: https://github.com/highlightjs/highlight.js/issues/2277
Fixes: https://github.com/nodejs/node/issues/38938
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/38966
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2021-06-14 08:22:00 -07:00

44 lines
1.3 KiB
JavaScript

import '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import tmpdir from '../common/tmpdir.js';
import assert from 'assert';
import { execFileSync } from 'child_process';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const script = fileURLToPath(
new URL('../../tools/doc/apilinks.mjs', import.meta.url));
const apilinks = fixtures.path('apilinks');
tmpdir.refresh();
fs.readdirSync(apilinks).forEach((fixture) => {
if (!fixture.endsWith('.js')) return;
const input = path.join(apilinks, fixture);
const expectedContent = fs.readFileSync(`${input}on`, 'utf8');
const outputPath = path.join(tmpdir.path, `${fixture}on`);
execFileSync(
process.execPath,
[script, outputPath, input],
{ encoding: 'utf-8' }
);
const expectedLinks = JSON.parse(expectedContent);
const actualLinks = JSON.parse(fs.readFileSync(outputPath));
for (const [k, v] of Object.entries(expectedLinks)) {
assert.ok(k in actualLinks, `link not found: ${k}`);
assert.ok(actualLinks[k].endsWith('/' + v),
`link ${actualLinks[k]} expected to end with ${v}`);
delete actualLinks[k];
}
assert.strictEqual(
Object.keys(actualLinks).length, 0,
`unexpected links returned ${JSON.stringify(actualLinks)}`
);
});