Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(cli): the docs-scan case reads the scan's walk, not every doc (#10060)

Christopher Chedeau159aceb8e6db
diff --git a/packages/cli/clients/cli/commands/import-hint-correctness.test.mjs b/packages/cli/clients/cli/commands/import-hint-correctness.test.mjs
index 2d0b7026b0..87221371c3 100644
--- a/packages/cli/clients/cli/commands/import-hint-correctness.test.mjs
+++ b/packages/cli/clients/cli/commands/import-hint-correctness.test.mjs
@@ -216,13 +216,21 @@ describe('import hint correctness', () => {
it('builds its fixture where a scan of the repo\u2019s docs running at the same time never finds it', async () => {
// The docs-drift scan walks packages/cli/clients/cli/commands for
// .doc.mjs files. A fixture built there handed it this test's Widget
- // doc, which could vanish before the scan imported it.
+ // doc, which could vanish before the scan imported it. The scan's walk
+ // decides what it finds, so the case reads the walk and imports no doc.
const fixtureDir = createIntegrationFixture();
try {
- const {collectDocs} = await import('../../../test/drift/docs-drift.mjs');
- const found = (await collectDocs())
- .map(({file}) => path.resolve(REPO_ROOT, file))
- .filter(file => file.startsWith(fixtureDir + path.sep));
+ const {docFiles} = await import('../../../test/drift/docs-drift.mjs');
+ const files = docFiles();
+ expect(files).toContain(
+ path.join(
+ REPO_ROOT,
+ 'packages/cli/clients/cli/commands/component.doc.mjs',
+ ),
+ );
+ const found = files.filter(file =>
+ file.startsWith(fixtureDir + path.sep),
+ );
expect(found).toEqual([]);
} finally {
fs.rmSync(fixtureDir, {recursive: true, force: true});
diff --git a/packages/cli/test/drift/docs-drift.mjs b/packages/cli/test/drift/docs-drift.mjs
index d3086a7ce3..af30a977a6 100644
--- a/packages/cli/test/drift/docs-drift.mjs
+++ b/packages/cli/test/drift/docs-drift.mjs
@@ -50,9 +50,18 @@ function walk(dir) {
});
}
+/**
+ * Every `*.doc.mjs` file under the doc roots, as absolute paths. Listing them
+ * imports none.
+ * @returns {string[]}
+ */
+export function docFiles() {
+ return DOC_ROOTS.flatMap(walk);
+}
+
/** @returns {Promise<{file: string, doc: any}[]>} */
export async function collectDocs() {
- const files = DOC_ROOTS.flatMap(walk);
+ const files = docFiles();
const out = [];
for (const f of files) {
const mod = await import(pathToFileURL(f).href);