-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.js
44 lines (39 loc) · 1.14 KB
/
index.test.js
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
import { unified } from "unified"
import remark from "remark-parse"
import remark2rehype from "remark-rehype"
import stringify from "rehype-stringify"
import codeTitle from "./index.js"
import assert from "assert"
import * as vfile from "to-vfile"
function compile(file, opt) {
return unified()
.use(remark)
.use(remark2rehype)
.use(codeTitle, opt)
.use(stringify)
.processSync(vfile.readSync("./__example__/" + file))
.toString()
}
describe("Rehype-code-title", () => {
it("No Title", () => {
const got = compile("1.md")
assert.ok(got.match(/<h1>/) === null)
})
it("No Title: Custom class name", () => {
const got = compile("1.md", { className: "my-code" })
assert.ok(
got.match(/<h1>/) === null && got.match('class="my-code"') === null
)
})
it("Has title", () => {
const got = compile("2.md")
assert.ok(got.match("<h1>pages/_app.tsx</h1>") !== null)
})
it("Has title: Custom class name", () => {
const got = compile("2.md", { className: "my-code" })
assert.ok(
got.match("<h1>pages/_app.tsx</h1>") !== null &&
got.match('class="my-code"') !== null
)
})
})