Skip to content

Commit 159aceb

Browse files
authored
test(cli): the docs-scan case reads the scan's walk, not every doc (#10060)
test(cli): the docs-scan case reads the scan's walk, not every doc import-hint-correctness's "builds its fixture where a scan of the repo's docs running at the same time never finds it" called collectDocs() only to read the scanned file list, so it imported all 1,482 doc files under the test runner. Earlier cases used to leave many of them loaded. Once they no longer did, the case took 2.9 s alone and over 30 s in a loaded full run. docs-drift.mjs now exports docFiles(), the walk collectDocs() imports from, and the case asserts on it, with a known doc as a positive control. It imports no doc.
1 parent 66f5a07 commit 159aceb

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎packages/cli/clients/cli/commands/import-hint-correctness.test.mjs‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,21 @@ describe('import hint correctness', () => {
216216
it('builds its fixture where a scan of the repo\u2019s docs running at the same time never finds it', async () => {
217217
// The docs-drift scan walks packages/cli/clients/cli/commands for
218218
// .doc.mjs files. A fixture built there handed it this test's Widget
219-
// doc, which could vanish before the scan imported it.
219+
// doc, which could vanish before the scan imported it. The scan's walk
220+
// decides what it finds, so the case reads the walk and imports no doc.
220221
const fixtureDir = createIntegrationFixture();
221222
try {
222-
const {collectDocs} = await import('../../../test/drift/docs-drift.mjs');
223-
const found = (await collectDocs())
224-
.map(({file}) => path.resolve(REPO_ROOT, file))
225-
.filter(file => file.startsWith(fixtureDir + path.sep));
223+
const {docFiles} = await import('../../../test/drift/docs-drift.mjs');
224+
const files = docFiles();
225+
expect(files).toContain(
226+
path.join(
227+
REPO_ROOT,
228+
'packages/cli/clients/cli/commands/component.doc.mjs',
229+
),
230+
);
231+
const found = files.filter(file =>
232+
file.startsWith(fixtureDir + path.sep),
233+
);
226234
expect(found).toEqual([]);
227235
} finally {
228236
fs.rmSync(fixtureDir, {recursive: true, force: true});

‎packages/cli/test/drift/docs-drift.mjs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,18 @@ function walk(dir) {
5050
});
5151
}
5252

53+
/**
54+
* Every `*.doc.mjs` file under the doc roots, as absolute paths. Listing them
55+
* imports none.
56+
* @returns {string[]}
57+
*/
58+
export function docFiles() {
59+
return DOC_ROOTS.flatMap(walk);
60+
}
61+
5362
/** @returns {Promise<{file: string, doc: any}[]>} */
5463
export async function collectDocs() {
55-
const files = DOC_ROOTS.flatMap(walk);
64+
const files = docFiles();
5665
const out = [];
5766
for (const f of files) {
5867
const mod = await import(pathToFileURL(f).href);

0 commit comments

Comments
 (0)