GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: make test-doc-api-json more robust · nodejs/node@8857717

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/doctool
    • test-doc-api-json.mjs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/doctool/test-doc-api-json.mjs‎

Copy file name to clipboardExpand all lines: test/doctool/test-doc-api-json.mjs
+33-2Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,25 @@ function validateMisc(misc) {
2828
assert.strictEqual(typeof misc.textRaw, 'string');
2929
}
3030

31+
// Counts of `deprecated` and `removed` metadata found in the current file's
32+
// JSON output. Reset for each file and compared against the Markdown source.
3133
let numberOfDeprecatedSections = 0;
3234
let numberOfRemovedAPIs = 0;
35+
let totalDeprecatedSections = 0;
36+
let totalRemovedAPIs = 0;
37+
38+
// Counts the YAML metadata blocks in a Markdown source file that declare
39+
// `deprecated` or `removed`, so the JSON output can be checked against them.
40+
const yamlBlockRe = /<!--\s*YAML\r?\n([\s\S]*?)-->/g;
41+
function countSourceMeta(markdown) {
42+
let deprecated = 0;
43+
let removed = 0;
44+
for (const { 1: body } of markdown.matchAll(yamlBlockRe)) {
45+
if (/^\s*deprecated:/m.test(body)) deprecated++;
46+
if (/^\s*removed:/m.test(body)) removed++;
47+
}
48+
return { deprecated, removed };
49+
}
3350

3451
const metaExpectedKeys = new Set([
3552
'added',
@@ -155,8 +172,22 @@ for await (const dirent of await fs.opendir(new URL('../../out/doc/api/', import
155172
'report.md': ['introduced_in', 'meta', 'stability', 'stabilityText', 'miscs'],
156173
}[dirent.name] ?? ['modules'])]);
157174

175+
numberOfDeprecatedSections = 0;
176+
numberOfRemovedAPIs = 0;
158177
assert.partialDeepStrictEqual(allExpectedKeys, findAllKeys(json));
178+
179+
const markdown = await fs.readFile(
180+
new URL(`../../${expectedSource}`, import.meta.url), 'utf8');
181+
assert.deepStrictEqual(
182+
{ deprecated: numberOfDeprecatedSections, removed: numberOfRemovedAPIs },
183+
countSourceMeta(markdown),
184+
`deprecated/removed metadata in ${jsonPath} does not match ${expectedSource}`,
185+
);
186+
totalDeprecatedSections += numberOfDeprecatedSections;
187+
totalRemovedAPIs += numberOfRemovedAPIs;
159188
}
160189

161-
assert.strictEqual(numberOfDeprecatedSections, 52); // Increase this number every time a new API is deprecated.
162-
assert.strictEqual(numberOfRemovedAPIs, 47); // Increase this number every time a section is marked as removed.
190+
// Guard against the source scan and the JSON output both silently finding
191+
// nothing (e.g. if the YAML metadata format changes).
192+
assert.ok(totalDeprecatedSections > 0);
193+
assert.ok(totalRemovedAPIs > 0);

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.