Skip to content

Commit 3c358e3

Browse files
committed
Use Node test runner
1 parent 31d6a76 commit 3c358e3

File tree

3 files changed

+39
-49
lines changed

3 files changed

+39
-49
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ jobs:
1717
strategy:
1818
matrix:
1919
node:
20-
- lts/fermium
20+
- lts/hydrogen
2121
- node

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@
3636
"@types/unist": "^2.0.0"
3737
},
3838
"devDependencies": {
39-
"@types/tape": "^4.0.0",
39+
"@types/node": "^18.0.0",
4040
"c8": "^7.0.0",
4141
"prettier": "^2.0.0",
4242
"remark-cli": "^11.0.0",
4343
"remark-preset-wooorm": "^9.0.0",
44-
"tape": "^5.0.0",
4544
"tsd": "^0.25.0",
4645
"type-coverage": "^2.0.0",
4746
"typescript": "^4.0.0",

test.js

+37-46
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* @typedef {import('hast').Element} Element
44
*/
55

6-
import test from 'tape'
6+
import assert from 'node:assert/strict'
7+
import test from 'node:test'
78
import {isElement} from './index.js'
89

9-
test('isElement', (t) => {
10-
t.equal(isElement(), false, 'should return `false` without node')
11-
t.equal(isElement(null), false, 'should return `false` with `null`')
10+
test('isElement', async (t) => {
11+
assert.equal(isElement(), false, 'should return `false` without node')
12+
assert.equal(isElement(null), false, 'should return `false` with `null`')
1213

13-
t.throws(
14+
assert.throws(
1415
() => {
1516
// @ts-expect-error runtime.
1617
isElement(null, true)
@@ -19,100 +20,94 @@ test('isElement', (t) => {
1920
'should throw when the second parameter is invalid'
2021
)
2122

22-
t.test('isElement(node)', (st) => {
23-
st.equal(
23+
await t.test('isElement(node)', () => {
24+
assert.equal(
2425
isElement({type: 'text'}),
2526
false,
2627
'should return `false` when without `element`'
2728
)
2829

29-
st.equal(
30+
assert.equal(
3031
isElement({type: 'element'}),
3132
false,
3233
'should return `false` when with invalid `element`'
3334
)
3435

35-
st.equal(
36+
assert.equal(
3637
isElement({type: 'element', tagName: 'div'}),
3738
true,
3839
'should return `true` when with valid `element`'
3940
)
40-
41-
st.end()
4241
})
4342

44-
t.test('isElement(node, tagName)', (st) => {
45-
st.equal(
43+
await t.test('isElement(node, tagName)', () => {
44+
assert.equal(
4645
isElement({type: 'text'}, 'div'),
4746
false,
4847
'should return `false` when without `element`'
4948
)
5049

51-
st.equal(
50+
assert.equal(
5251
isElement({type: 'element'}, 'div'),
5352
false,
5453
'should return `false` when with invalid `element`'
5554
)
5655

57-
st.equal(
56+
assert.equal(
5857
isElement({type: 'element', tagName: 'strong'}, 'div'),
5958
false,
6059
'should return `false` when without matching `element`'
6160
)
6261

63-
st.equal(
62+
assert.equal(
6463
isElement({type: 'element', tagName: 'div'}, 'div'),
6564
true,
6665
'should return `true` when with matching `element`'
6766
)
68-
69-
st.end()
7067
})
7168

72-
t.test('isElement(node, tagNames)', (st) => {
73-
st.equal(
69+
await t.test('isElement(node, tagNames)', () => {
70+
assert.equal(
7471
isElement({type: 'text'}, ['div']),
7572
false,
7673
'should return `false` when without `element`'
7774
)
7875

79-
st.equal(
76+
assert.equal(
8077
isElement({type: 'element'}, ['div']),
8178
false,
8279
'should return `false` when with invalid `element`'
8380
)
8481

85-
st.equal(
82+
assert.equal(
8683
isElement({type: 'element', tagName: 'strong'}, ['div']),
8784
false,
8885
'should return `false` when without matching `element`'
8986
)
9087

91-
st.equal(
88+
assert.equal(
9289
isElement({type: 'element', tagName: 'div'}, ['div', 'strong', 'em']),
9390
true,
9491
'should return `true` when with matching `element` (#1)'
9592
)
9693

97-
st.equal(
94+
assert.equal(
9895
isElement({type: 'element', tagName: 'em'}, ['div', 'strong', 'em']),
9996
true,
10097
'should return `true` when with matching `element` (#2)'
10198
)
102-
103-
st.end()
10499
})
105100

106-
t.test('isElement(node, test)', (st) => {
107-
st.equal(
101+
await t.test('isElement(node, test)', () => {
102+
assert.equal(
108103
isElement({type: 'text'}, () => {
109104
throw new Error('!')
110105
}),
111106
false,
112107
'should not call `test` if the given node is not an element'
113108
)
114109

115-
st.equal(
110+
assert.equal(
116111
isElement(
117112
{type: 'element', tagName: 'a', children: []},
118113
(node) => node.children.length === 0
@@ -121,7 +116,7 @@ test('isElement', (t) => {
121116
'should call `test` if the given node is a valid element (1)'
122117
)
123118

124-
st.equal(
119+
assert.equal(
125120
isElement(
126121
{type: 'element', tagName: 'a', children: [{type: 'text'}]},
127122
(node) => node.children.length === 0
@@ -136,7 +131,7 @@ test('isElement', (t) => {
136131
children: [{type: 'element', tagName: 'a', children: []}]
137132
}
138133

139-
st.equal(
134+
assert.equal(
140135
isElement(
141136
root.children[0],
142137
/**
@@ -146,10 +141,10 @@ test('isElement', (t) => {
146141
* @param {Parent|undefined|null} parent
147142
*/
148143
function (node, index, parent) {
149-
st.equal(node, root.children[0], 'should pass `node` to test')
150-
st.equal(index, 0, 'should pass `index` to test')
151-
st.equal(parent, root, 'should pass `parent` to test')
152-
st.equal(this, ctx, 'should pass `context` to test')
144+
assert.equal(node, root.children[0], 'should pass `node` to test')
145+
assert.equal(index, 0, 'should pass `index` to test')
146+
assert.equal(parent, root, 'should pass `parent` to test')
147+
assert.equal(this, ctx, 'should pass `context` to test')
153148
},
154149
0,
155150
root,
@@ -159,23 +154,23 @@ test('isElement', (t) => {
159154
'should call `test` if the given node is a valid element (2)'
160155
)
161156

162-
st.throws(
157+
assert.throws(
163158
() => {
164159
isElement(root.children[0], () => {}, 0)
165160
},
166161
/Expected both parent and index/,
167162
'should throw if `index` is passed but not `parent`'
168163
)
169164

170-
st.throws(
165+
assert.throws(
171166
() => {
172167
isElement(root.children[0], () => {}, undefined, root)
173168
},
174169
/Expected both parent and index/,
175170
'should throw if `parent` is passed but not `index`'
176171
)
177172

178-
st.throws(
173+
assert.throws(
179174
() => {
180175
// @ts-expect-error runtime.
181176
isElement(root.children[0], () => {}, false)
@@ -184,23 +179,23 @@ test('isElement', (t) => {
184179
'should throw if `index` is not a number'
185180
)
186181

187-
st.throws(
182+
assert.throws(
188183
() => {
189184
isElement(root.children[0], () => {}, -1)
190185
},
191186
/Expected positive finite index for child node/,
192187
'should throw if `index` is negative'
193188
)
194189

195-
st.throws(
190+
assert.throws(
196191
() => {
197192
isElement(root.children[0], () => {}, Number.POSITIVE_INFINITY)
198193
},
199194
/Expected positive finite index for child node/,
200195
'should throw if `index` is infinity'
201196
)
202197

203-
st.throws(
198+
assert.throws(
204199
() => {
205200
// @ts-expect-error runtime.
206201
isElement(root.children[0], () => {}, 0, true)
@@ -209,17 +204,13 @@ test('isElement', (t) => {
209204
'should throw if `parent` is not a node'
210205
)
211206

212-
st.throws(
207+
assert.throws(
213208
() => {
214209
// @ts-expect-error runtime.
215210
isElement(root.children[0], () => {}, 0, {type: 'root'})
216211
},
217212
/Expected parent node/,
218213
'should throw if `parent` is not a parent'
219214
)
220-
221-
st.end()
222215
})
223-
224-
t.end()
225216
})

0 commit comments

Comments
 (0)