Skip to content

Commit

Permalink
Refactor to use node:test
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 31, 2023
1 parent 4597690 commit 22f1ee7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 61 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
"@types/tape": "^5.0.0",
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"prettier": "^3.0.0",
"rehype": "^13.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"xo": "^0.56.0"
Expand Down
113 changes: 54 additions & 59 deletions test.js
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 &amp; 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 &amp; 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 &#x26; 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 &#x26; 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 &amp; 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 &amp; 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 &#x26; 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 &#x26; 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')
)
})
})

0 comments on commit 22f1ee7

Please sign in to comment.