forked from mxx1111/mdlook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmoke-test.mjs
More file actions
53 lines (41 loc) · 1.45 KB
/
Copy pathsmoke-test.mjs
File metadata and controls
53 lines (41 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Smoke test for the VSCode extension rendering path.
* Verifies initRenderer options used by the extension produce expected HTML.
*
* Run from repo root: pnpm vscode test
*/
import { initRenderer } from '@md/core/renderer'
import { modifyHtmlContent } from '@md/core/utils'
const markdown = `# Hello
Visit [Example Site](https://example.com) for details.
\`\`\`js
console.log('ok')
\`\`\`
`
function assert(condition, message) {
if (!condition)
throw new Error(message)
}
function runCase(name, opts, checks) {
const renderer = initRenderer({ legend: `none`, ...opts })
const html = modifyHtmlContent(markdown, renderer)
for (const [label, fn] of checks) {
assert(fn(html), `${name}: ${label}`)
}
console.log(`✓ ${name}`)
}
runCase(`default renderer`, {}, [
[`contains heading`, html => html.includes(`Hello`)],
[`contains external link`, html => html.includes(`example.com`)],
[`cite disabled`, html => !html.includes(`<sup>[`)],
])
runCase(`citeStatus enabled`, { citeStatus: true }, [
[`converts link to citation`, html => html.includes(`<sup>[`) && html.includes(`example.com`)],
])
runCase(`countStatus enabled`, { countStatus: true }, [
[`includes reading stats`, html => /阅读|分钟|字/.test(html)],
])
runCase(`mac code block`, { isMacCodeBlock: true }, [
[`enables mac-sign style`, html => html.includes(`.mac-sign`) && html.includes(`display: flex`)],
])
console.log(`\nAll VSCode extension smoke tests passed.`)