Skip to content

Commit a869bb5

Browse files
committed
Use Node test runner
1 parent 262c28f commit a869bb5

File tree

4 files changed

+54
-60
lines changed

4 files changed

+54
-60
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
@@ -40,14 +40,13 @@
4040
"devDependencies": {
4141
"@types/lodash": "^4.0.0",
4242
"@types/mdast": "^3.0.0",
43-
"@types/tape": "^4.0.0",
43+
"@types/node": "^18.0.0",
4444
"c8": "^7.0.0",
4545
"fast-check": "^3.0.0",
4646
"lodash": "^4.0.0",
4747
"prettier": "^2.0.0",
4848
"remark-cli": "^11.0.0",
4949
"remark-preset-wooorm": "^9.0.0",
50-
"tape": "^5.0.0",
5150
"tsd": "^0.25.0",
5251
"type-coverage": "^2.0.0",
5352
"typescript": "^4.0.0",

test/main.js

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* @typedef {import('unist').Parent} Parent
44
*/
55

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

9-
test('unist-util-is', (t) => {
10+
test('is', async (t) => {
1011
const node = {type: 'strong'}
1112
const parent = {type: 'paragraph', children: []}
1213

13-
t.throws(
14+
assert.throws(
1415
() => {
1516
// @ts-expect-error runtime.
1617
is(null, false)
@@ -19,23 +20,23 @@ test('unist-util-is', (t) => {
1920
'should throw when `test` is invalid'
2021
)
2122

22-
t.throws(
23+
assert.throws(
2324
() => {
2425
is(node, null, -1, parent)
2526
},
2627
/Expected positive finite index/,
2728
'should throw when `index` is invalid (#1)'
2829
)
2930

30-
t.throws(
31+
assert.throws(
3132
() => {
3233
is(node, null, Number.POSITIVE_INFINITY, parent)
3334
},
3435
/Expected positive finite index/,
3536
'should throw when `index` is invalid (#2)'
3637
)
3738

38-
t.throws(
39+
assert.throws(
3940
() => {
4041
// @ts-expect-error runtime.
4142
is(node, null, false, parent)
@@ -44,7 +45,7 @@ test('unist-util-is', (t) => {
4445
'should throw when `index` is invalid (#3)'
4546
)
4647

47-
t.throws(
48+
assert.throws(
4849
() => {
4950
// @ts-expect-error runtime.
5051
is(node, null, 0, {})
@@ -53,7 +54,7 @@ test('unist-util-is', (t) => {
5354
'should throw when `parent` is invalid (#1)'
5455
)
5556

56-
t.throws(
57+
assert.throws(
5758
() => {
5859
// @ts-expect-error runtime.
5960
is(node, null, 0, {type: 'paragraph'})
@@ -62,7 +63,7 @@ test('unist-util-is', (t) => {
6263
'should throw when `parent` is invalid (#2)'
6364
)
6465

65-
t.throws(
66+
assert.throws(
6667
() => {
6768
// @ts-expect-error: both `index` and `parent` are needed.
6869
is(node, null, 0)
@@ -71,27 +72,31 @@ test('unist-util-is', (t) => {
7172
'should throw `parent` xor `index` are given (#1)'
7273
)
7374

74-
t.throws(
75+
assert.throws(
7576
() => {
7677
// @ts-expect-error: both `index` and `parent` are needed.
7778
is(node, null, null, parent)
7879
},
7980
/Expected both parent and index/,
8081
'should throw `parent` xor `index` are given (#2)'
8182
)
82-
t.notok(is(), 'should not fail without node')
83-
t.ok(is(node), 'should check if given a node (#1)')
84-
t.notok(is({children: []}, null), 'should check if given a node (#2)')
83+
assert.ok(!is(), 'should not fail without node')
84+
assert.ok(is(node), 'should check if given a node (#1)')
85+
assert.ok(!is({children: []}, null), 'should check if given a node (#2)')
8586

86-
t.ok(is(node, 'strong'), 'should match types (#1)')
87-
t.notok(is(node, 'emphasis'), 'should match types (#2)')
87+
assert.ok(is(node, 'strong'), 'should match types (#1)')
88+
assert.ok(!is(node, 'emphasis'), 'should match types (#2)')
8889

89-
t.ok(is(node, node), 'should match partially (#1)')
90-
t.ok(is(node, {type: 'strong'}), 'should match partially (#2)')
91-
t.ok(is(parent, {type: 'paragraph'}), 'should match partially (#3)')
92-
t.notok(is(node, {type: 'paragraph'}), 'should match partially (#4)')
90+
assert.ok(is(node, node), 'should match partially (#1)')
91+
assert.ok(is(node, {type: 'strong'}), 'should match partially (#2)')
92+
assert.ok(is(parent, {type: 'paragraph'}), 'should match partially (#3)')
93+
assert.ok(!is(node, {type: 'paragraph'}), 'should match partially (#4)')
94+
95+
await t.test('should accept a test', () => {
96+
assert.ok(!is(node, test))
97+
assert.ok(!is(node, test, 0, parent))
98+
assert.ok(is(node, test, 5, parent))
9399

94-
t.test('should accept a test', (t) => {
95100
/**
96101
* @param {unknown} _
97102
* @param {number | null | undefined} n
@@ -100,18 +105,14 @@ test('unist-util-is', (t) => {
100105
function test(_, n) {
101106
return n === 5
102107
}
103-
104-
t.notok(is(node, test))
105-
t.notok(is(node, test, 0, parent))
106-
t.ok(is(node, test, 5, parent))
107-
108-
t.end()
109108
})
110109

111-
t.test('should call test', (t) => {
110+
await t.test('should call test', () => {
112111
const context = {foo: 'bar'}
112+
let calls = 0
113113

114-
t.plan(4)
114+
is(node, test, 5, parent, context)
115+
assert.equal(calls, 1)
115116

116117
/**
117118
* @this {context}
@@ -120,24 +121,23 @@ test('unist-util-is', (t) => {
120121
* @param {Parent | null | undefined} c
121122
*/
122123
function test(a, b, c) {
123-
t.equal(this, context)
124-
t.equal(a, node)
125-
t.equal(b, 5)
126-
t.equal(c, parent)
124+
assert.equal(this, context)
125+
assert.equal(a, node)
126+
assert.equal(b, 5)
127+
assert.equal(c, parent)
128+
calls++
127129
}
128-
129-
is(node, test, 5, parent, context)
130130
})
131131

132-
t.ok(is(node, ['strong', 'emphasis']), 'should match arrays (#1)')
133-
t.notok(is(node, ['b', 'i']), 'should match arrays (#2)')
132+
assert.ok(is(node, ['strong', 'emphasis']), 'should match arrays (#1)')
133+
assert.ok(!is(node, ['b', 'i']), 'should match arrays (#2)')
134134

135-
t.test('should match arrays (#3)', (t) => {
135+
await t.test('should match arrays (#3)', () => {
136136
const context = {foo: 'bar'}
137+
let calls = 0
137138

138-
t.plan(5)
139-
140-
t.ok(is(node, [test, 'strong'], 5, parent, context))
139+
assert.ok(is(node, [test, 'strong'], 5, parent, context))
140+
assert.equal(calls, 1)
141141

142142
/**
143143
* @this {context}
@@ -147,13 +147,12 @@ test('unist-util-is', (t) => {
147147
* @returns {boolean}
148148
*/
149149
function test(a, b, c) {
150-
t.equal(this, context)
151-
t.equal(a, node)
152-
t.equal(b, 5)
153-
t.equal(c, parent)
150+
assert.equal(this, context)
151+
assert.equal(a, node)
152+
assert.equal(b, 5)
153+
assert.equal(c, parent)
154+
calls++
154155
return false
155156
}
156157
})
157-
158-
t.end()
159158
})

test/property.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
/**
2-
* @typedef {import('unist').Node} Node
3-
*/
4-
5-
import test from 'tape'
1+
import assert from 'node:assert/strict'
2+
import test from 'node:test'
63
import fc from 'fast-check'
74
import lodash from 'lodash'
85
import {is} from '../index.js'
96

107
const {isObject, isPlainObject, pick, cloneDeep} = lodash
118

12-
test('unist-util-is properties', (t) => {
13-
t.plan(4)
14-
t.doesNotThrow(
9+
test('properties', () => {
10+
assert.doesNotThrow(
1511
() =>
1612
fc.assert(
1713
// @ts-expect-error: fine.
@@ -22,7 +18,7 @@ test('unist-util-is properties', (t) => {
2218
'should see any object w/ a non-empty `type` as a node'
2319
)
2420

25-
t.doesNotThrow(
21+
assert.doesNotThrow(
2622
() =>
2723
fc.assert(
2824
fc.property(
@@ -37,7 +33,7 @@ test('unist-util-is properties', (t) => {
3733
'should see any object w/o a `type` as a non-node'
3834
)
3935

40-
t.doesNotThrow(
36+
assert.doesNotThrow(
4137
() =>
4238
fc.assert(
4339
// @ts-expect-error: fine.
@@ -48,7 +44,7 @@ test('unist-util-is properties', (t) => {
4844
'should match types'
4945
)
5046

51-
t.doesNotThrow(
47+
assert.doesNotThrow(
5248
() =>
5349
fc.assert(
5450
fc.property(

0 commit comments

Comments
 (0)