Skip to content

Commit 586ae01

Browse files
committed
Use Node test runner
1 parent e9a59cb commit 586ae01

File tree

3 files changed

+88
-93
lines changed

3 files changed

+88
-93
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ jobs:
1717
strategy:
1818
matrix:
1919
node:
20-
- lts/fermium
20+
- lts/gallium
2121
- node

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"unist-util-visit": "^4.0.0"
5353
},
5454
"devDependencies": {
55-
"@types/tape": "^4.0.0",
55+
"@types/node": "^18.0.0",
5656
"c8": "^7.0.0",
5757
"hast-util-from-html": "^1.0.0",
5858
"hastscript": "^7.0.0",
@@ -65,7 +65,6 @@
6565
"prettier": "^2.0.0",
6666
"remark-cli": "^11.0.0",
6767
"remark-preset-wooorm": "^9.0.0",
68-
"tape": "^5.0.0",
6968
"type-coverage": "^2.0.0",
7069
"typescript": "^4.0.0",
7170
"unist-builder": "^3.0.0",

test/index.js

Lines changed: 86 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
import fs from 'node:fs/promises'
66
import process from 'node:process'
7-
import test from 'tape'
7+
import assert from 'node:assert/strict'
8+
import test from 'node:test'
89
import {isHidden} from 'is-hidden'
910
import {h} from 'hastscript'
1011
import {fromHtml} from 'hast-util-from-html'
@@ -18,46 +19,46 @@ import {removePosition} from 'unist-util-remove-position'
1819
import {toMdast} from '../index.js'
1920
import * as mod from '../index.js'
2021

21-
test('core', (t) => {
22-
t.deepEqual(
22+
test('core', () => {
23+
assert.deepEqual(
2324
Object.keys(mod).sort(),
2425
['defaultHandlers', 'defaultNodeHandlers', 'toMdast'],
2526
'should expose the public api'
2627
)
2728

28-
t.deepEqual(
29+
assert.deepEqual(
2930
toMdast(u('root', [h('strong', 'Alpha')])),
3031
u('root', [u('strong', [u('text', 'Alpha')])]),
3132
'should transform hast to mdast'
3233
)
3334

34-
t.deepEqual(
35+
assert.deepEqual(
3536
toMdast(u('doctype', {name: 'html'})),
3637
u('root', []),
3738
'should transform a node w/o mdast representation to an empty root'
3839
)
3940

40-
t.deepEqual(
41+
assert.deepEqual(
4142
toMdast(h('q', 'things')),
4243
{type: 'root', children: [{type: 'text', value: '"things"'}]},
4344
'should transform a node w/o multiple representations to a root'
4445
)
4546

46-
t.deepEqual(
47+
assert.deepEqual(
4748
// @ts-expect-error runtime.
4849
toMdast(u('root', [u('unknown', 'text')])),
4950
u('root', [u('text', 'text')]),
5051
'should transform unknown texts to `text`'
5152
)
5253

53-
t.deepEqual(
54+
assert.deepEqual(
5455
// @ts-expect-error runtime.
5556
toMdast(u('root', [u('unknown', [h('em')])])),
5657
u('root', [u('emphasis', [])]),
5758
'should unwrap unknown parents'
5859
)
5960

60-
t.deepEqual(
61+
assert.deepEqual(
6162
// @ts-expect-error runtime.
6263
toMdast(u('root', [u('unknown')])),
6364
u('root', []),
@@ -69,7 +70,7 @@ test('core', (t) => {
6970
end: {line: 1, column: 6, offset: 5}
7071
}
7172

72-
t.deepEqual(
73+
assert.deepEqual(
7374
toMdast({
7475
type: 'root',
7576
children: [
@@ -97,37 +98,37 @@ test('core', (t) => {
9798
'should support positional information'
9899
)
99100

100-
t.deepEqual(
101+
assert.deepEqual(
101102
toMdast({type: 'element', tagName: 'a', children: []}),
102103
{type: 'link', url: '', title: null, children: []},
103104
'should support an `a` w/o `properties`'
104105
)
105106

106-
t.deepEqual(
107+
assert.deepEqual(
107108
toMdast({type: 'element', tagName: 'iframe', children: []}),
108109
{type: 'root', children: []},
109110
'should support an `iframe` w/o `properties`'
110111
)
111112

112-
t.deepEqual(
113+
assert.deepEqual(
113114
toMdast({type: 'element', tagName: 'img', children: []}),
114115
{type: 'image', url: '', title: null, alt: ''},
115116
'should support an `img` w/o `properties`'
116117
)
117118

118-
t.deepEqual(
119+
assert.deepEqual(
119120
toMdast({type: 'element', tagName: 'input', children: []}),
120121
{type: 'root', children: []},
121122
'should support an `input` w/o `properties`'
122123
)
123124

124-
t.deepEqual(
125+
assert.deepEqual(
125126
toMdast({type: 'element', tagName: 'select', children: []}),
126127
{type: 'root', children: []},
127128
'should support a `select` w/o `properties`'
128129
)
129130

130-
t.deepEqual(
131+
assert.deepEqual(
131132
toMdast({
132133
type: 'element',
133134
tagName: 'select',
@@ -138,27 +139,27 @@ test('core', (t) => {
138139
'should support an `option` w/o `properties`'
139140
)
140141

141-
t.deepEqual(
142+
assert.deepEqual(
142143
toMdast({type: 'element', tagName: 'video', children: []}),
143144
{type: 'link', title: null, url: '', children: []},
144145
'should support a `video` w/o `properties`'
145146
)
146147

147-
t.deepEqual(
148+
assert.deepEqual(
148149
// @ts-expect-error: `children` missing.
149150
toMdast({type: 'root'}),
150151
{type: 'root', children: []},
151152
'should support a `root` node w/o `children`'
152153
)
153154

154-
t.deepEqual(
155+
assert.deepEqual(
155156
// @ts-expect-error: `children` missing.
156157
toMdast({type: 'element', tagName: 'div'}),
157158
{type: 'root', children: []},
158159
'should support an `element` node w/o `children`'
159160
)
160161

161-
t.deepEqual(
162+
assert.deepEqual(
162163
toMdast(h(null, [h('div', 'Alpha')]), {
163164
handlers: {
164165
div() {
@@ -170,13 +171,13 @@ test('core', (t) => {
170171
'should support `handlers`'
171172
)
172173

173-
t.deepEqual(
174+
assert.deepEqual(
174175
toMdast(h(null, h('p', 'Alpha\nBeta'))),
175176
u('root', [u('paragraph', [u('text', 'Alpha Beta')])]),
176177
'should collapse newline to a single space'
177178
)
178179

179-
t.deepEqual(
180+
assert.deepEqual(
180181
toMdast(h(null, h('p', 'Alpha\nBeta')), {newlines: true}),
181182
u('root', [u('paragraph', [u('text', 'Alpha\nBeta')])]),
182183
'should support `newlines: true`'
@@ -189,7 +190,7 @@ test('core', (t) => {
189190
'.'
190191
])
191192

192-
t.deepEqual(
193+
assert.deepEqual(
193194
toMdast(phrasingTree),
194195
u('root', [
195196
u('strong', [u('text', 'Importance')]),
@@ -200,7 +201,7 @@ test('core', (t) => {
200201
'should infer document if not needed'
201202
)
202203

203-
t.deepEqual(
204+
assert.deepEqual(
204205
toMdast(phrasingTree, {document: true}),
205206
u('root', [
206207
u('paragraph', [
@@ -240,7 +241,7 @@ test('core', (t) => {
240241

241242
// Reference check: `text`s are wrapped in `paragraph`s because the unknown
242243
// node is seen as “block”
243-
t.deepEqual(
244+
assert.deepEqual(
244245
referenceTree.type === 'root' &&
245246
referenceTree.children.length === 3 &&
246247
referenceTree.children[0].type === 'paragraph',
@@ -249,18 +250,16 @@ test('core', (t) => {
249250
)
250251

251252
// Actual check: no `paragraph` is added because `hName` is added.
252-
t.deepEqual(
253+
assert.deepEqual(
253254
explicitTree.type === 'root' &&
254255
explicitTree.children.length === 3 &&
255256
explicitTree.children[0].type !== 'paragraph',
256257
true,
257258
'should support `node.data.hName` to infer phrasing (2)'
258259
)
259-
260-
t.end()
261260
})
262261

263-
test('fixtures', async (t) => {
262+
test('fixtures', async () => {
264263
const fixtures = new URL('fixtures/', import.meta.url)
265264
const folders = await fs.readdir(fixtures)
266265

@@ -269,72 +268,69 @@ test('fixtures', async (t) => {
269268
continue
270269
}
271270

272-
t.test(folder, async (t) => {
273-
const configUrl = new URL(folder + '/index.json', fixtures)
274-
const inputUrl = new URL(folder + '/index.html', fixtures)
275-
const expectedUrl = new URL(folder + '/index.md', fixtures)
276-
const input = String(await fs.readFile(inputUrl))
277-
// Replace middots with spaces (useful for trailing spaces).
278-
.replace(/·/g, ' ')
279-
/** @type {({stringify?: boolean, tree?: boolean} & Options) | undefined} */
280-
let config
281-
282-
try {
283-
config = JSON.parse(String(await fs.readFile(configUrl)))
284-
} catch {}
285-
286-
const hast = fromHtml(input)
287-
const mdast = toMdast(hast, config)
288-
removePosition(mdast, true)
289-
290-
t.doesNotThrow(() => {
291-
mdastAssert(mdast)
292-
}, 'should produce valid mdast nodes')
293-
294-
// Ignore the invalid base test.
295-
if (folder === 'base-invalid') {
296-
t.end()
297-
return
298-
}
299-
300-
const actual = toMarkdown(mdast, {
301-
extensions: [gfmToMarkdown()],
302-
fences: true
303-
})
304-
/** @type {string} */
305-
let expected
271+
const configUrl = new URL(folder + '/index.json', fixtures)
272+
const inputUrl = new URL(folder + '/index.html', fixtures)
273+
const expectedUrl = new URL(folder + '/index.md', fixtures)
274+
const input = String(await fs.readFile(inputUrl))
275+
// Replace middots with spaces (useful for trailing spaces).
276+
.replace(/·/g, ' ')
277+
/** @type {({stringify?: boolean, tree?: boolean} & Options) | undefined} */
278+
let config
279+
280+
try {
281+
config = JSON.parse(String(await fs.readFile(configUrl)))
282+
} catch {}
283+
284+
const hast = fromHtml(input)
285+
const mdast = toMdast(hast, config)
286+
removePosition(mdast, true)
287+
288+
assert.doesNotThrow(() => {
289+
mdastAssert(mdast)
290+
}, folder + ': should produce valid mdast nodes')
291+
292+
// Ignore the invalid base test.
293+
if (folder === 'base-invalid') {
294+
continue
295+
}
306296

307-
try {
308-
if ('UPDATE' in process.env) {
309-
throw new Error('Update!')
310-
}
297+
const actual = toMarkdown(mdast, {
298+
extensions: [gfmToMarkdown()],
299+
fences: true
300+
})
301+
/** @type {string} */
302+
let expected
311303

312-
expected = String(await fs.readFile(expectedUrl))
313-
} catch {
314-
expected = actual
315-
await fs.writeFile(expectedUrl, actual)
304+
try {
305+
if ('UPDATE' in process.env) {
306+
throw new Error('Update!')
316307
}
317308

318-
if (!config || config.stringify !== false) {
319-
t.deepEqual(actual, expected, 'should produce the same documents')
320-
}
309+
expected = String(await fs.readFile(expectedUrl))
310+
} catch {
311+
expected = actual
312+
await fs.writeFile(expectedUrl, actual)
313+
}
321314

322-
if (!config || config.tree !== false) {
323-
const expectedMdast = fromMarkdown(expected, {
324-
extensions: [gfm()],
325-
mdastExtensions: [gfmFromMarkdown()]
326-
})
327-
removePosition(expectedMdast, true)
328-
t.deepEqual(
329-
mdast,
330-
expectedMdast,
331-
'should produce the same tree as remark'
332-
)
333-
}
315+
if (!config || config.stringify !== false) {
316+
assert.deepEqual(
317+
actual,
318+
expected,
319+
folder + ': should produce the same documents'
320+
)
321+
}
334322

335-
t.end()
336-
})
323+
if (!config || config.tree !== false) {
324+
const expectedMdast = fromMarkdown(expected, {
325+
extensions: [gfm()],
326+
mdastExtensions: [gfmFromMarkdown()]
327+
})
328+
removePosition(expectedMdast, true)
329+
assert.deepEqual(
330+
mdast,
331+
expectedMdast,
332+
folder + ': should produce the same tree as remark'
333+
)
334+
}
337335
}
338-
339-
t.end()
340336
})

0 commit comments

Comments
 (0)