2024-11-28 23:22:31 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google LLC All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
|
|
|
|
*/
|
|
|
|
|
|
2025-07-24 19:26:09 +00:00
|
|
|
import {resolve} from 'path';
|
2024-10-22 04:46:26 +00:00
|
|
|
import {readFile} from 'fs/promises';
|
|
|
|
|
import {JSDOM} from 'jsdom';
|
2025-05-06 20:59:30 +00:00
|
|
|
import {getRenderable} from '../processing.mjs';
|
|
|
|
|
import {renderEntry} from '../rendering.mjs';
|
2025-08-25 01:59:16 +00:00
|
|
|
import {initHighlighter} from '../../../shared/shiki.mjs';
|
|
|
|
|
import {setHighlighterInstance} from '../shiki/shiki.mjs';
|
2024-10-22 04:46:26 +00:00
|
|
|
|
|
|
|
|
describe('CLI docs to html', () => {
|
|
|
|
|
let fragment: DocumentFragment;
|
|
|
|
|
let entryJson: any;
|
|
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2025-08-25 01:59:16 +00:00
|
|
|
setHighlighterInstance(await initHighlighter());
|
2024-10-22 04:46:26 +00:00
|
|
|
|
2025-07-24 19:26:09 +00:00
|
|
|
const entryContent = await readFile(resolve('./fake-cli-entries.json'), {
|
2024-10-22 04:46:26 +00:00
|
|
|
encoding: 'utf-8',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
entryJson = JSON.parse(entryContent) as any;
|
2025-05-06 21:17:46 +00:00
|
|
|
const renderableJson = await getRenderable(entryJson, '', 'angular/cli');
|
2024-10-22 04:46:26 +00:00
|
|
|
fragment = JSDOM.fragment(await renderEntry(renderableJson));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should subcommands correctly', async () => {
|
|
|
|
|
const generateComponentSubcommand = entryJson.subcommands.find(
|
|
|
|
|
(subcommand: any) => subcommand.name === 'component',
|
|
|
|
|
);
|
2025-05-06 21:17:46 +00:00
|
|
|
const renderableJson = await getRenderable(generateComponentSubcommand, '', 'angular/cli');
|
2024-10-22 04:46:26 +00:00
|
|
|
fragment = JSDOM.fragment(await renderEntry(renderableJson));
|
|
|
|
|
|
|
|
|
|
const cliTocs = fragment.querySelectorAll('.docs-reference-cli-toc')!;
|
|
|
|
|
expect(cliTocs.length).toBe(2);
|
|
|
|
|
|
2026-01-29 04:53:21 +00:00
|
|
|
expect(cliTocs[0].textContent).toContain('ng component [name] [options]');
|
|
|
|
|
expect(cliTocs[1].textContent).toContain('ng c [name] [options]');
|
2024-10-22 04:46:26 +00:00
|
|
|
});
|
|
|
|
|
});
|