Commit 7ecb7796be7 for nodejs

commit 7ecb7796be722f09247cb07ff060eba9c5aabdd0
Author: James M Snell <jasnell@gmail.com>
Date:   Tue Nov 24 08:52:50 2026 -0800

    test: make test-doc-api-json more robust

    The test hard coded the number of deprecated apis
    so whenever one is added or removed it always needs
    to be updated. This makes the check more robust by
    calculating the values on each run.

    Signed-off-by: James M Snell <jasnell@gmail.com>
    PR-URL: https://github.com/nodejs/node/pull/67701
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: LiviaMedeiros <livia@cirno.name>

diff --git a/test/doctool/test-doc-api-json.mjs b/test/doctool/test-doc-api-json.mjs
index ac56a415811..2e15173bdc2 100644
--- a/test/doctool/test-doc-api-json.mjs
+++ b/test/doctool/test-doc-api-json.mjs
@@ -28,8 +28,25 @@ function validateMisc(misc) {
   assert.strictEqual(typeof misc.textRaw, 'string');
 }

+// Counts of `deprecated` and `removed` metadata found in the current file's
+// JSON output. Reset for each file and compared against the Markdown source.
 let numberOfDeprecatedSections = 0;
 let numberOfRemovedAPIs = 0;
+let totalDeprecatedSections = 0;
+let totalRemovedAPIs = 0;
+
+// Counts the YAML metadata blocks in a Markdown source file that declare
+// `deprecated` or `removed`, so the JSON output can be checked against them.
+const yamlBlockRe = /<!--\s*YAML\r?\n([\s\S]*?)-->/g;
+function countSourceMeta(markdown) {
+  let deprecated = 0;
+  let removed = 0;
+  for (const { 1: body } of markdown.matchAll(yamlBlockRe)) {
+    if (/^\s*deprecated:/m.test(body)) deprecated++;
+    if (/^\s*removed:/m.test(body)) removed++;
+  }
+  return { deprecated, removed };
+}

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

+  numberOfDeprecatedSections = 0;
+  numberOfRemovedAPIs = 0;
   assert.partialDeepStrictEqual(allExpectedKeys, findAllKeys(json));
+
+  const markdown = await fs.readFile(
+    new URL(`../../${expectedSource}`, import.meta.url), 'utf8');
+  assert.deepStrictEqual(
+    { deprecated: numberOfDeprecatedSections, removed: numberOfRemovedAPIs },
+    countSourceMeta(markdown),
+    `deprecated/removed metadata in ${jsonPath} does not match ${expectedSource}`,
+  );
+  totalDeprecatedSections += numberOfDeprecatedSections;
+  totalRemovedAPIs += numberOfRemovedAPIs;
 }

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