Skip to content

Commit 804f194

Browse files
Add test to catch fallthrough TODO condition in generated docs. (#1101)
1 parent 5d73b61 commit 804f194

File tree

5 files changed

+88
-2
lines changed

5 files changed

+88
-2
lines changed

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ jobs:
1717

1818
- run: npm ci
1919
- run: npm run test:unit
20+
- run: npm run test:generated-api

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"test:integration": "npm run test:integration -w lit-dev-tests",
2222
"test:integration:update-golden-screenshots": "npm run test:integration:update-golden-screenshots -w lit-dev-tests",
2323
"test:links": "npm run test:links -w lit-dev-tests",
24+
"test:generated-api": "npm run test:api:no-todos -w lit-dev-tests",
2425
"publish-search-index": "wireit"
2526
},
2627
"wireit": {

packages/lit-dev-content/site/_includes/api.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
ReadonlyArray<string>
149149

150150
{%- else -%}
151-
TODO
151+
<span class="error-fallback-todo">TODO</span>
152152
{# {{ t | dump }} #}
153153
{%- endif -%}
154154

packages/lit-dev-tests/package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"test:integration:update-golden-screenshots": "wireit",
1313
"test:links": "wireit",
1414
"test:links:redirects": "wireit",
15-
"test:links:internal-and-external": "wireit"
15+
"test:links:internal-and-external": "wireit",
16+
"test:api:no-todos": "wireit"
1617
},
1718
"wireit": {
1819
"build": {
@@ -78,6 +79,13 @@
7879
],
7980
"files": [],
8081
"output": []
82+
},
83+
"test:api:no-todos": {
84+
"command": "node lib/check-no-todos.js",
85+
"dependencies": [
86+
"build",
87+
"../lit-dev-content:build"
88+
]
8189
}
8290
},
8391
"dependencies": {
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* @license
3+
* Copyright 2023 Google LLC
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/**
8+
* Our `api.html` generator template fails by rendering a `TODO`. For example
9+
* see issue https://github.com/lit/lit.dev/issues/1097.
10+
*
11+
* This means when upgrading infrastructure, it can sometimes become a subtle
12+
* error that needs manual scavenging for errant TODO's. This test scans built
13+
* HTML files for instances of TODO - and breaks tests if one is found.
14+
*/
15+
16+
import {readFileSync} from 'fs';
17+
import * as pathLib from 'path';
18+
import {fileURLToPath} from 'url';
19+
import ansi from 'ansi-escape-sequences';
20+
21+
const {red, green, yellow, bold, reset} = ansi.style;
22+
23+
const __filename = fileURLToPath(import.meta.url);
24+
const __dirname = pathLib.dirname(__filename);
25+
const siteOutputDir = pathLib.resolve(
26+
__dirname,
27+
'../',
28+
'../',
29+
'lit-dev-content',
30+
'_site'
31+
);
32+
33+
const api_pages_to_check = [
34+
pathLib.resolve(siteOutputDir, 'docs/api/controllers/index.html'),
35+
pathLib.resolve(siteOutputDir, 'docs/api/custom-directives/index.html'),
36+
pathLib.resolve(siteOutputDir, 'docs/api/decorators/index.html'),
37+
pathLib.resolve(siteOutputDir, 'docs/api/directives/index.html'),
38+
pathLib.resolve(siteOutputDir, 'docs/api/LitElement/index.html'),
39+
pathLib.resolve(siteOutputDir, 'docs/api/misc/index.html'),
40+
pathLib.resolve(siteOutputDir, 'docs/api/ReactiveElement/index.html'),
41+
pathLib.resolve(siteOutputDir, 'docs/api/static-html/index.html'),
42+
pathLib.resolve(siteOutputDir, 'docs/api/styles/index.html'),
43+
pathLib.resolve(siteOutputDir, 'docs/api/templates/index.html'),
44+
];
45+
46+
const checkNoTodos = async () => {
47+
console.log('==========================================');
48+
console.log("Checking lit.dev generated API for TODO's");
49+
console.log('==========================================');
50+
console.log();
51+
52+
let fail = false;
53+
54+
for (const page of api_pages_to_check) {
55+
const content = readFileSync(page, {encoding: 'utf8'});
56+
57+
if (content.includes(`"error-fallback-todo"`)) {
58+
fail = true;
59+
console.log(`${bold + red}FOUND TODO${reset} ${yellow + page + reset}`);
60+
}
61+
}
62+
63+
console.log();
64+
if (fail) {
65+
console.log(
66+
`${bold + red}Found TODOs in generated API documentation!${reset}`
67+
);
68+
process.exit(1);
69+
} else {
70+
console.error(
71+
`${bold + green}Generated API does not contain any TODOs!${reset}`
72+
);
73+
}
74+
};
75+
76+
checkNoTodos();

0 commit comments

Comments
 (0)