@@ -28,8 +28,25 @@ function validateMisc(misc) { |
28 | 28 | assert.strictEqual(typeof misc.textRaw, 'string'); |
29 | 29 | } |
30 | 30 |
|
| 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. |
31 | 33 | let numberOfDeprecatedSections = 0; |
32 | 34 | 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 | +} |
33 | 50 |
|
34 | 51 | const metaExpectedKeys = new Set([ |
35 | 52 | 'added', |
@@ -155,8 +172,22 @@ for await (const dirent of await fs.opendir(new URL('../../out/doc/api/', import |
155 | 172 | 'report.md': ['introduced_in', 'meta', 'stability', 'stabilityText', 'miscs'], |
156 | 173 | }[dirent.name] ?? ['modules'])]); |
157 | 174 |
|
| 175 | + numberOfDeprecatedSections = 0; |
| 176 | + numberOfRemovedAPIs = 0; |
158 | 177 | 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; |
159 | 188 | } |
160 | 189 |
|
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); |