-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,70 @@ | ||
import test from 'tape' | ||
import assert from 'node:assert/strict' | ||
import test from 'node:test' | ||
import {rehype} from 'rehype' | ||
import rehypeSlug from './index.js' | ||
|
||
test('rehypeSlug', (t) => { | ||
t.plan(4) | ||
test('rehypeSlug', async function (t) { | ||
await t.test('should work', async function () { | ||
const file = await rehype() | ||
.data('settings', {fragment: true}) | ||
.use(rehypeSlug) | ||
.process( | ||
[ | ||
'<section>', | ||
' <h1>Lorem ipsum 😪</h1>', | ||
' <h2>dolor—sit—amet</h2>', | ||
' <h3>consectetur & adipisicing</h3>', | ||
' <h4>elit</h4>', | ||
' <h5>elit</h5>', | ||
' <p>sed</p>', | ||
'</section>' | ||
].join('\n') | ||
) | ||
|
||
rehype() | ||
.data('settings', {fragment: true}) | ||
.use(rehypeSlug) | ||
.process( | ||
assert.equal( | ||
String(file), | ||
[ | ||
'<section>', | ||
' <h1>Lorem ipsum 😪</h1>', | ||
' <h2>dolor—sit—amet</h2>', | ||
' <h3>consectetur & adipisicing</h3>', | ||
' <h4>elit</h4>', | ||
' <h5>elit</h5>', | ||
' <h1 id="lorem-ipsum-">Lorem ipsum 😪</h1>', | ||
' <h2 id="dolorsitamet">dolor—sit—amet</h2>', | ||
' <h3 id="consectetur--adipisicing">consectetur & adipisicing</h3>', | ||
' <h4 id="elit">elit</h4>', | ||
' <h5 id="elit-1">elit</h5>', | ||
' <p>sed</p>', | ||
'</section>' | ||
].join('\n'), | ||
(error, file) => { | ||
t.ifErr(error, 'shouldn’t throw') | ||
|
||
t.equal( | ||
String(file), | ||
[ | ||
'<section>', | ||
' <h1 id="lorem-ipsum-">Lorem ipsum 😪</h1>', | ||
' <h2 id="dolorsitamet">dolor—sit—amet</h2>', | ||
' <h3 id="consectetur--adipisicing">consectetur & adipisicing</h3>', | ||
' <h4 id="elit">elit</h4>', | ||
' <h5 id="elit-1">elit</h5>', | ||
' <p>sed</p>', | ||
'</section>' | ||
].join('\n'), | ||
'should match' | ||
) | ||
} | ||
].join('\n') | ||
) | ||
}) | ||
|
||
await t.test('should support `options.prefix`', async function () { | ||
const file = await rehype() | ||
.data('settings', {fragment: true}) | ||
.use(rehypeSlug, {prefix: 'test-'}) | ||
.process( | ||
[ | ||
'<section>', | ||
' <h1>Lorem ipsum 😪</h1>', | ||
' <h2>dolor—sit—amet</h2>', | ||
' <h3>consectetur & adipisicing</h3>', | ||
' <h4>elit</h4>', | ||
' <h5>elit</h5>', | ||
' <p>sed</p>', | ||
'</section>' | ||
].join('\n') | ||
) | ||
|
||
rehype() | ||
.data('settings', {fragment: true}) | ||
.use(rehypeSlug, {prefix: 'test-'}) | ||
.process( | ||
assert.equal( | ||
String(file), | ||
[ | ||
'<section>', | ||
' <h1>Lorem ipsum 😪</h1>', | ||
' <h2>dolor—sit—amet</h2>', | ||
' <h3>consectetur & adipisicing</h3>', | ||
' <h4>elit</h4>', | ||
' <h5>elit</h5>', | ||
' <h1 id="test-lorem-ipsum-">Lorem ipsum 😪</h1>', | ||
' <h2 id="test-dolorsitamet">dolor—sit—amet</h2>', | ||
' <h3 id="test-consectetur--adipisicing">consectetur & adipisicing</h3>', | ||
' <h4 id="test-elit">elit</h4>', | ||
' <h5 id="test-elit-1">elit</h5>', | ||
' <p>sed</p>', | ||
'</section>' | ||
].join('\n'), | ||
(error, file) => { | ||
t.ifErr(error, 'shouldn’t throw') | ||
|
||
t.equal( | ||
String(file), | ||
[ | ||
'<section>', | ||
' <h1 id="test-lorem-ipsum-">Lorem ipsum 😪</h1>', | ||
' <h2 id="test-dolorsitamet">dolor—sit—amet</h2>', | ||
' <h3 id="test-consectetur--adipisicing">consectetur & adipisicing</h3>', | ||
' <h4 id="test-elit">elit</h4>', | ||
' <h5 id="test-elit-1">elit</h5>', | ||
' <p>sed</p>', | ||
'</section>' | ||
].join('\n'), | ||
'should match' | ||
) | ||
} | ||
].join('\n') | ||
) | ||
}) | ||
}) |