Skip to content

Commit 169f938

Browse files
committed
Use Node test runner
1 parent 7b3adaf commit 169f938

File tree

3 files changed

+73
-102
lines changed

3 files changed

+73
-102
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
@@ -54,15 +54,14 @@
5454
"unist-util-visit-parents": "^5.1.1"
5555
},
5656
"devDependencies": {
57-
"@types/tape": "^4.0.0",
57+
"@types/node": "^18.0.0",
5858
"c8": "^7.0.0",
5959
"mdast-util-from-markdown": "^1.0.0",
6060
"mdast-util-gfm": "^2.0.0",
6161
"micromark-extension-gfm": "^2.0.0",
6262
"prettier": "^2.0.0",
6363
"remark-cli": "^11.0.0",
6464
"remark-preset-wooorm": "^9.0.0",
65-
"tape": "^5.0.0",
6665
"tsd": "^0.25.0",
6766
"type-coverage": "^2.0.0",
6867
"typescript": "^4.7.0",

test.js

Lines changed: 71 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/**
2-
* @typedef {import('unist').Literal<string>} Literal
32
* @typedef {import('unist').Node} Node
43
* @typedef {import('unist').Parent} Parent
54
*/
65

7-
import assert from 'node:assert'
8-
import test from 'tape'
6+
import assert from 'node:assert/strict'
7+
import test from 'node:test'
98
import {fromMarkdown} from 'mdast-util-from-markdown'
109
import {gfmFromMarkdown} from 'mdast-util-gfm'
1110
import {gfm} from 'micromark-extension-gfm'
@@ -48,8 +47,8 @@ const reverseTypes = [
4847
'text'
4948
]
5049

51-
test('unist-util-visit', (t) => {
52-
t.throws(
50+
test('visit', async (t) => {
51+
assert.throws(
5352
() => {
5453
// @ts-expect-error runtime.
5554
visit()
@@ -58,7 +57,7 @@ test('unist-util-visit', (t) => {
5857
'should fail without tree'
5958
)
6059

61-
t.throws(
60+
assert.throws(
6261
() => {
6362
// @ts-expect-error runtime.
6463
visit(tree)
@@ -67,14 +66,12 @@ test('unist-util-visit', (t) => {
6766
'should fail without visitor'
6867
)
6968

70-
t.test('should iterate over all nodes', (t) => {
69+
await t.test('should iterate over all nodes', () => {
7170
let n = 0
7271

7372
visit(tree, visitor)
7473

75-
t.equal(n, types.length, 'should visit all nodes')
76-
77-
t.end()
74+
assert.equal(n, types.length, 'should visit all nodes')
7875

7976
/**
8077
* @param {Node} node
@@ -85,14 +82,12 @@ test('unist-util-visit', (t) => {
8582
}
8683
})
8784

88-
t.test('should iterate over all nodes, backwards', (t) => {
85+
await t.test('should iterate over all nodes, backwards', () => {
8986
let n = 0
9087

9188
visit(tree, visitor, true)
9289

93-
t.equal(n, reverseTypes.length, 'should visit all nodes in reverse')
94-
95-
t.end()
90+
assert.equal(n, reverseTypes.length, 'should visit all nodes in reverse')
9691

9792
/**
9893
* @param {Node} node
@@ -107,14 +102,12 @@ test('unist-util-visit', (t) => {
107102
}
108103
})
109104

110-
t.test('should only visit a given `type`', (t) => {
105+
await t.test('should only visit a given `type`', () => {
111106
let n = 0
112107

113108
visit(tree, 'text', visitor)
114109

115-
t.equal(n, texts, 'should visit all matching nodes')
116-
117-
t.end()
110+
assert.equal(n, texts, 'should visit all matching nodes')
118111

119112
/**
120113
* @param {Node} node
@@ -125,15 +118,13 @@ test('unist-util-visit', (t) => {
125118
}
126119
})
127120

128-
t.test('should only visit given `type`s', (t) => {
121+
await t.test('should only visit given `type`s', () => {
129122
const types = ['text', 'inlineCode']
130123
let n = 0
131124

132125
visit(tree, types, visitor)
133126

134-
t.equal(n, texts + codes, 'should visit all matching nodes')
135-
136-
t.end()
127+
assert.equal(n, texts + codes, 'should visit all matching nodes')
137128

138129
/**
139130
* @param {Node} node
@@ -144,7 +135,7 @@ test('unist-util-visit', (t) => {
144135
}
145136
})
146137

147-
t.test('should accept any `is`-compatible test function', (t) => {
138+
await t.test('should accept any `is`-compatible test function', () => {
148139
let n = 0
149140

150141
visit(tree, test, (node, index, parent) => {
@@ -153,9 +144,7 @@ test('unist-util-visit', (t) => {
153144
n++
154145
})
155146

156-
t.equal(n, 3, 'should visit all passing nodes')
157-
158-
t.end()
147+
assert.equal(n, 3, 'should visit all passing nodes')
159148

160149
/**
161150
* @param {Node} _
@@ -166,7 +155,7 @@ test('unist-util-visit', (t) => {
166155
}
167156
})
168157

169-
t.test('should accept an array of `is`-compatible tests', (t) => {
158+
await t.test('should accept an array of `is`-compatible tests', () => {
170159
const expected = new Set(['root', 'paragraph', 'emphasis', 'strong'])
171160
const tests = [
172161
/** @param {Node} node */
@@ -185,19 +174,15 @@ test('unist-util-visit', (t) => {
185174
n++
186175
})
187176

188-
t.equal(n, 5, 'should visit all passing nodes')
189-
190-
t.end()
177+
assert.equal(n, 5, 'should visit all passing nodes')
191178
})
192179

193-
t.test('should stop if `visitor` stops', (t) => {
180+
await t.test('should stop if `visitor` stops', () => {
194181
let n = 0
195182

196183
visit(tree, visitor)
197184

198-
t.equal(n, stopIndex, 'should visit nodes until `EXIT` is given')
199-
200-
t.end()
185+
assert.equal(n, stopIndex, 'should visit nodes until `EXIT` is given')
201186

202187
/**
203188
* @param {Node} node
@@ -208,14 +193,12 @@ test('unist-util-visit', (t) => {
208193
}
209194
})
210195

211-
t.test('should stop if `visitor` stops, backwards', (t) => {
196+
await t.test('should stop if `visitor` stops, backwards', () => {
212197
let n = 0
213198

214199
visit(tree, visitor, true)
215200

216-
t.equal(n, stopIndex, 'should visit nodes until `EXIT` is given')
217-
218-
t.end()
201+
assert.equal(n, stopIndex, 'should visit nodes until `EXIT` is given')
219202

220203
/**
221204
* @param {Node} node
@@ -230,20 +213,18 @@ test('unist-util-visit', (t) => {
230213
}
231214
})
232215

233-
t.test('should skip if `visitor` skips', (t) => {
216+
await t.test('should skip if `visitor` skips', () => {
234217
let n = 0
235218
let count = 0
236219

237220
visit(tree, visitor)
238221

239-
t.equal(
222+
assert.equal(
240223
count,
241224
types.length - 1,
242225
'should visit nodes except when `SKIP` is given'
243226
)
244227

245-
t.end()
246-
247228
/**
248229
* @param {Node} node
249230
*/
@@ -258,20 +239,18 @@ test('unist-util-visit', (t) => {
258239
}
259240
})
260241

261-
t.test('should skip if `visitor` skips, backwards', (t) => {
242+
await t.test('should skip if `visitor` skips, backwards', () => {
262243
let n = 0
263244
let count = 0
264245

265246
visit(tree, visitor, true)
266247

267-
t.equal(
248+
assert.equal(
268249
count,
269250
reverseTypes.length - 1,
270251
'should visit nodes except when `SKIP` is given'
271252
)
272253

273-
t.end()
274-
275254
/**
276255
* @param {Node} node
277256
*/
@@ -290,9 +269,9 @@ test('unist-util-visit', (t) => {
290269
}
291270
})
292271

293-
t.test(
272+
await t.test(
294273
'should support a given `index` to iterate over next (`0` to reiterate)',
295-
(t) => {
274+
() => {
296275
let n = 0
297276
let again = false
298277
const expected = [
@@ -317,9 +296,7 @@ test('unist-util-visit', (t) => {
317296

318297
visit(tree, visitor)
319298

320-
t.equal(n, expected.length, 'should visit nodes again')
321-
322-
t.end()
299+
assert.equal(n, expected.length, 'should visit nodes again')
323300

324301
/**
325302
* @param {Node} node
@@ -339,9 +316,9 @@ test('unist-util-visit', (t) => {
339316
}
340317
)
341318

342-
t.test(
319+
await t.test(
343320
'should support a given `index` to iterate over next (`children.length` to skip further children)',
344-
(t) => {
321+
() => {
345322
let n = 0
346323
let again = false
347324
const expected = [
@@ -357,9 +334,7 @@ test('unist-util-visit', (t) => {
357334

358335
visit(tree, visitor)
359336

360-
t.equal(n, expected.length, 'should skip nodes')
361-
362-
t.end()
337+
assert.equal(n, expected.length, 'should skip nodes')
363338

364339
/**
365340
* @param {Node} node
@@ -381,51 +356,52 @@ test('unist-util-visit', (t) => {
381356
}
382357
)
383358

384-
t.test('should support any other given `index` to iterate over next', (t) => {
385-
let n = 0
386-
let again = false
387-
const expected = [
388-
'root',
389-
'paragraph',
390-
'text',
391-
'emphasis',
392-
'text',
393-
'text',
394-
'strong',
395-
'text',
396-
'inlineCode', // Skip to here.
397-
'text'
398-
]
399-
400-
visit(tree, visitor)
359+
await t.test(
360+
'should support any other given `index` to iterate over next',
361+
() => {
362+
let n = 0
363+
let again = false
364+
const expected = [
365+
'root',
366+
'paragraph',
367+
'text',
368+
'emphasis',
369+
'text',
370+
'text',
371+
'strong',
372+
'text',
373+
'inlineCode', // Skip to here.
374+
'text'
375+
]
401376

402-
t.equal(n, expected.length, 'should skip nodes')
377+
visit(tree, visitor)
403378

404-
t.end()
379+
assert.equal(n, expected.length, 'should skip nodes')
405380

406-
/**
407-
* @param {Node} node
408-
* @param {number|null} index
409-
*/
410-
function visitor(node, index) {
411-
assert.strictEqual(
412-
node.type,
413-
expected[n++],
414-
'should be the expected type'
415-
)
381+
/**
382+
* @param {Node} node
383+
* @param {number|null} index
384+
*/
385+
function visitor(node, index) {
386+
assert.strictEqual(
387+
node.type,
388+
expected[n++],
389+
'should be the expected type'
390+
)
416391

417-
if (
418-
typeof index === 'number' &&
419-
again === false &&
420-
node.type === 'strong'
421-
) {
422-
again = true
423-
return index + 2 // Skip to `inlineCode`.
392+
if (
393+
typeof index === 'number' &&
394+
again === false &&
395+
node.type === 'strong'
396+
) {
397+
again = true
398+
return index + 2 // Skip to `inlineCode`.
399+
}
424400
}
425401
}
426-
})
402+
)
427403

428-
t.test('should visit added nodes', (t) => {
404+
await t.test('should visit added nodes', () => {
429405
const tree = fromMarkdown('Some _emphasis_, **importance**, and `code`.')
430406
const other = /** @type {Parent} */ (
431407
fromMarkdown('Another ~~sentence~~.', {
@@ -439,9 +415,7 @@ test('unist-util-visit', (t) => {
439415

440416
visit(tree, visitor)
441417

442-
t.equal(n, l, 'should walk over all nodes')
443-
444-
t.end()
418+
assert.equal(n, l, 'should walk over all nodes')
445419

446420
/**
447421
* @param {Node} _1
@@ -456,6 +430,4 @@ test('unist-util-visit', (t) => {
456430
}
457431
}
458432
})
459-
460-
t.end()
461433
})

0 commit comments

Comments
 (0)