mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
cc18ed67b7
* fix: sync package-lock.json with package.json dependencies
package-lock.json was missing @emnapi/core@1.9.2 and
@emnapi/runtime@1.9.2 (transitive deps of @emnapi/wasi-threads),
causing `npm ci` to fail on all CI jobs.
* fix: resolve remaining CI failures after TS-to-JS adapter migration
- vitest.config.ts: update adapter project include/exclude from .test.ts
to .test.{ts,js} to match converted adapter test files
- check-doc-coverage.sh: skip adapter directories containing only utility
files (prefixed with _), fixing false positive for clis/slock/
- linux-do/topic-content.test.js: fix hardcoded reference to topic.ts
(now topic.js after PR #928 migration)
60 lines
2.6 KiB
JavaScript
60 lines
2.6 KiB
JavaScript
import { getRegistry } from '@jackwener/opencli/registry';
|
|
import fs from 'node:fs';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { __test__ } from './topic-content.js';
|
|
describe('linux-do topic-content', () => {
|
|
it('prefers raw markdown when the topic payload includes it', () => {
|
|
const result = __test__.extractTopicContent({
|
|
title: 'Hello Linux.do',
|
|
post_stream: {
|
|
posts: [
|
|
{
|
|
post_number: 1,
|
|
username: 'neo',
|
|
raw: '## Heading\n\n- one\n- two',
|
|
cooked: '<h2>Heading</h2><ul><li>one</li><li>two</li></ul>',
|
|
like_count: 7,
|
|
created_at: '2025-04-05T10:00:00.000Z',
|
|
},
|
|
],
|
|
},
|
|
}, 1234);
|
|
expect(result.content).toContain('---');
|
|
expect(result.content).toContain('title: Hello Linux.do');
|
|
expect(result.content).toContain('author: neo');
|
|
expect(result.content).toContain('likes: 7');
|
|
expect(result.content).toContain('url: https://linux.do/t/1234');
|
|
expect(result.content).toContain('## Heading');
|
|
expect(result.content).toContain('- one');
|
|
});
|
|
it('falls back to cooked html and converts it to markdown', () => {
|
|
const result = __test__.extractTopicContent({
|
|
title: 'Converted Topic',
|
|
post_stream: {
|
|
posts: [
|
|
{
|
|
post_number: 1,
|
|
username: 'trinity',
|
|
cooked: '<p>Hello <strong>world</strong></p><blockquote><p>quoted</p></blockquote>',
|
|
like_count: 3,
|
|
created_at: '2025-04-05T10:00:00.000Z',
|
|
},
|
|
],
|
|
},
|
|
}, 42);
|
|
expect(result.content).toContain('Hello **world**');
|
|
expect(result.content).toContain('> quoted');
|
|
});
|
|
it('registers topic-content with plain default output for markdown body rendering', () => {
|
|
const command = getRegistry().get('linux-do/topic-content');
|
|
expect(command?.defaultFormat).toBe('plain');
|
|
expect(command?.columns).toEqual(['content']);
|
|
});
|
|
it('keeps topic adapter as a summarized first-page reader after the split', () => {
|
|
const topicTs = fs.readFileSync(new URL('./topic.js', import.meta.url), 'utf8');
|
|
expect(topicTs).not.toContain('main_only');
|
|
expect(topicTs).toContain('slice(0, 200)');
|
|
expect(topicTs).toContain('帖子首页摘要和回复');
|
|
});
|
|
});
|