Skip to content

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

TypeScript

test(cli): check the two-docs components report in two tests, one doctor run each (#9225)

Cindy Zhangfaf600717ab1
diff --git a/packages/cli/clients/cli/commands/doctor-integration.test.mjs b/packages/cli/clients/cli/commands/doctor-integration.test.mjs
index b74e8e3652..d06ae94e96 100644
--- a/packages/cli/clients/cli/commands/doctor-integration.test.mjs
+++ b/packages/cli/clients/cli/commands/doctor-integration.test.mjs
@@ -1124,7 +1124,11 @@ describe('doctor integration — command', () => {
]);
});
- it('components counts two docs of one name as two components, and compares a .doc.ts beside a .doc.mjs', async () => {
+ /**
+ * Two docs named AcmeTwin (a .doc.mjs and a .doc.ts) and one AcmeX doc in
+ * each of two folders, every doc naming a prop its component lacks.
+ */
+ function writeTwinDocs() {
writeComponentIntegration('AcmeTwin');
const dir = path.join(tmpDir, 'components');
const doc = (/** @type {string} */ name, /** @type {string} */ prop) =>
@@ -1153,22 +1157,28 @@ describe('doctor integration — command', () => {
);
}
process.chdir(tmpDir);
- const run = async (/** @type {string[]} */ flags) => {
- logCalls.length = 0;
- await createProgram().parseAsync([
- 'node',
- 'astryx',
- ...flags,
- 'doctor',
- 'integration',
- 'components',
- ]);
- return logCalls.join('\n');
- };
+ }
- const report = JSON.parse(await run(['--json'])).data.propDrift;
- const output = await run([]);
+ /** Run `doctor integration components` with `flags` and return its output. */
+ async function runComponents(/** @type {string[]} */ flags) {
+ logCalls.length = 0;
+ await createProgram().parseAsync([
+ 'node',
+ 'astryx',
+ ...flags,
+ 'doctor',
+ 'integration',
+ 'components',
+ ]);
+ return logCalls.join('\n');
+ }
+ // Each run reads every component's props with the project's TypeScript, so
+ // the JSON and the text report are checked in separate tests: one run each
+ // keeps a test well inside its time limit on a busy runner.
+ it('components counts two docs of one name as two components, and compares a .doc.ts beside a .doc.mjs', async () => {
+ writeTwinDocs();
+ const report = JSON.parse(await runComponents(['--json'])).data.propDrift;
expect(
report.findings
.filter(f => f.kind === 'not_in_code')
@@ -1180,7 +1190,13 @@ describe('doctor integration — command', () => {
'components/a/AcmeX.doc.mjs a',
'components/b/AcmeX.doc.mjs b',
]);
- expect(output).toMatch(/ in 4 of 4 component\(s\) compared /);
+ });
+
+ it('components counts those four docs as four compared components in its text report', async () => {
+ writeTwinDocs();
+ expect(await runComponents([])).toMatch(
+ / in 4 of 4 component\(s\) compared /,
+ );
});
it('components prints every field of the props comparison that JSON carries', async () => {