Skip to content

Commit ef3f6ad

Browse files
committed
Use Node test runner
1 parent 13ed635 commit ef3f6ad

File tree

12 files changed

+97
-110
lines changed

12 files changed

+97
-110
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
@@ -36,12 +36,11 @@
3636
"stringify-entities": "^4.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
"type-coverage": "^2.0.0",
4645
"typescript": "^4.0.0",
4746
"unist-builder": "^3.0.0",

test/attribute.js

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,210 +1,203 @@
1-
import test from 'tape'
1+
import assert from 'node:assert/strict'
2+
import test from 'node:test'
23
import {x} from 'xastscript'
34
import {u} from 'unist-builder'
45
import {toXml} from '../index.js'
56

6-
test('`element` attributes', (t) => {
7-
t.deepEqual(
7+
test('`element` attributes', async (t) => {
8+
assert.deepEqual(
89
toXml(u('element', {name: 'y'}, [])),
910
'<y></y>',
1011
'should ignore missing attributes'
1112
)
1213

13-
t.deepEqual(
14+
assert.deepEqual(
1415
toXml(u('element', {name: 'y', attributes: {a: null}}, [])),
1516
'<y></y>',
1617
'should ignore attributes set to `null`'
1718
)
1819

19-
t.deepEqual(
20+
assert.deepEqual(
2021
toXml(u('element', {name: 'y', attributes: {a: undefined}}, [])),
2122
'<y></y>',
2223
'should ignore attributes set to `undefined`'
2324
)
2425

25-
t.deepEqual(
26+
assert.deepEqual(
2627
// @ts-expect-error runtime.
2728
toXml(u('element', {name: 'y', attributes: {a: Number.NaN}}, [])),
2829
'<y a="NaN"></y>',
2930
'should include attributes set to `NaN`'
3031
)
3132

32-
t.deepEqual(
33+
assert.deepEqual(
3334
// @ts-expect-error runtime.
3435
toXml(u('element', {name: 'y', attributes: {a: true}}, [])),
3536
'<y a="true"></y>',
3637
'should include attributes set to `true`'
3738
)
3839

39-
t.deepEqual(
40+
assert.deepEqual(
4041
toXml(u('element', {name: 'y', attributes: {a: 'b'}}, [])),
4142
'<y a="b"></y>',
4243
'should include attributes set to a string'
4344
)
4445

45-
t.deepEqual(
46+
assert.deepEqual(
4647
// @ts-expect-error runtime.
4748
toXml(u('element', {name: 'y', attributes: {a: ['b', 'c']}}, [])),
4849
'<y a="b,c"></y>',
4950
'should include attributes set to an array'
5051
)
5152

52-
t.deepEqual(
53+
assert.deepEqual(
5354
// @ts-expect-error runtime.
5455
toXml(u('element', {name: 'y', attributes: {a: 1}}, [])),
5556
'<y a="1"></y>',
5657
'should include attributes set to a number'
5758
)
5859

59-
t.deepEqual(
60+
assert.deepEqual(
6061
// @ts-expect-error runtime.
6162
toXml(u('element', {name: 'y', attributes: {a: 0}}, [])),
6263
'<y a="0"></y>',
6364
'should include attributes set to `0`'
6465
)
6566

66-
t.deepEqual(
67+
assert.deepEqual(
6768
// @ts-expect-error runtime.
6869
toXml(u('element', {name: 'y', attributes: {a: {toString}}}, [])),
6970
'<y a="yup"></y>',
7071
'should stringify unknowns set to objects'
7172
)
7273

73-
t.end()
74-
75-
t.test('quote', (st) => {
76-
st.deepEqual(
74+
await t.test('quote', () => {
75+
assert.deepEqual(
7776
toXml(x('y', {a: 'b'})),
7877
'<y a="b"></y>',
7978
'should quote attribute values with double quotes by default'
8079
)
8180

82-
st.deepEqual(
81+
assert.deepEqual(
8382
toXml(x('y', {a: 'b'}), {quote: "'"}),
8483
"<y a='b'></y>",
8584
'should quote attribute values with single quotes if `quote: "\'"`'
8685
)
8786

88-
st.deepEqual(
87+
assert.deepEqual(
8988
toXml(x('y', {a: 'b'}), {quote: '"'}),
9089
'<y a="b"></y>',
9190
"should quote attribute values with double quotes if `quote: '\"'`"
9291
)
9392

94-
st.deepEqual(
93+
assert.deepEqual(
9594
toXml(x('y', {a: "'b'"}), {quote: "'"}),
9695
"<y a='&#x27;b&#x27;'></y>",
9796
'should quote attribute values with single quotes if `quote: "\'"` even if they occur in value'
9897
)
9998

100-
st.deepEqual(
99+
assert.deepEqual(
101100
toXml(x('y', {a: '"b"'}), {quote: '"'}),
102101
'<y a="&#x22;b&#x22;"></y>',
103102
"should quote attribute values with double quotes if `quote: '\"'` even if they occur in value"
104103
)
105104

106-
st.throws(
105+
assert.throws(
107106
() => {
108107
// @ts-expect-error runtime.
109108
toXml(x('y'), {quote: '`'})
110109
},
111110
/Invalid quote ```, expected `'` or `"`/,
112111
'should throw on invalid quotes'
113112
)
114-
115-
st.end()
116113
})
117114

118-
t.test('quoteSmart', (st) => {
119-
st.deepEqual(
115+
await t.test('quoteSmart', () => {
116+
assert.deepEqual(
120117
toXml(x('y', {a: 'b'}), {quoteSmart: true}),
121118
'<y a="b"></y>',
122119
'should quote attribute values with primary quotes by default (`"`)'
123120
)
124121

125-
st.deepEqual(
122+
assert.deepEqual(
126123
toXml(x('y', {a: 'b'}), {quote: "'", quoteSmart: true}),
127124
"<y a='b'></y>",
128125
"should quote attribute values with primary quotes by default (`'`)"
129126
)
130127

131-
st.deepEqual(
128+
assert.deepEqual(
132129
toXml(x('y', {a: "'b'"}), {quoteSmart: true}),
133130
'<y a="\'b\'"></y>',
134131
'should quote attribute values with primary quotes if the alternative occurs'
135132
)
136133

137-
st.deepEqual(
134+
assert.deepEqual(
138135
toXml(x('y', {a: "'\"b'"}), {quoteSmart: true}),
139136
'<y a="\'&#x22;b\'"></y>',
140137
'should quote attribute values with primary quotes if they occur less than the alternative'
141138
)
142139

143-
st.deepEqual(
140+
assert.deepEqual(
144141
toXml(x('y', {a: '"b\''}), {quoteSmart: true}),
145142
'<y a="&#x22;b\'"></y>',
146143
'should quote attribute values with primary quotes if they occur as much as alternatives (#1)'
147144
)
148145

149-
st.deepEqual(
146+
assert.deepEqual(
150147
toXml(x('y', {a: '"\'b\'"'}), {quoteSmart: true}),
151148
'<y a="&#x22;\'b\'&#x22;"></y>',
152149
'should quote attribute values with primary quotes if they occur as much as alternatives (#2)'
153150
)
154151

155-
st.deepEqual(
152+
assert.deepEqual(
156153
toXml(x('y', {a: '"b"'}), {quoteSmart: true}),
157154
'<y a=\'"b"\'></y>',
158155
'should quote attribute values with alternative quotes if the primary occurs'
159156
)
160157

161-
st.deepEqual(
158+
assert.deepEqual(
162159
toXml(x('y', {a: '"\'b"'}), {quoteSmart: true}),
163160
'<y a=\'"&#x27;b"\'></y>',
164161
'should quote attribute values with alternative quotes if they occur less than the primary'
165162
)
166-
167-
st.end()
168163
})
169164

170-
t.test('entities in attributes', (st) => {
171-
st.deepEqual(
165+
await t.test('entities in attributes', () => {
166+
assert.deepEqual(
172167
toXml(x('y', {'3<5': 'a'})),
173168
'<y 3&#x3C;5="a"></y>',
174169
'should encode entities in attribute names'
175170
)
176171

177-
st.deepEqual(
172+
assert.deepEqual(
178173
toXml(x('y', {'a\0b': 'c'})),
179174
'<y ab="c"></y>',
180175
'should strip illegal characters in attribute names'
181176
)
182177

183-
st.deepEqual(
178+
assert.deepEqual(
184179
toXml(x('y', {a: '3<5'})),
185180
'<y a="3&#x3C;5"></y>',
186181
'should encode entities in attribute values'
187182
)
188183

189-
st.deepEqual(
184+
assert.deepEqual(
190185
toXml(x('y', {a: 'b\0c'})),
191186
'<y a="bc"></y>',
192187
'should strip illegal characters in attribute values'
193188
)
194189

195-
st.deepEqual(
190+
assert.deepEqual(
196191
toXml(x('y', {'3=5': 'a'})),
197192
'<y 3&#x3D;5="a"></y>',
198193
'should encode `=` in attribute names'
199194
)
200195

201-
st.deepEqual(
196+
assert.deepEqual(
202197
toXml(x('y', {a: '3=5'})),
203198
'<y a="3=5"></y>',
204199
'should not encode `=` in attribute values'
205200
)
206-
207-
st.end()
208201
})
209202
})
210203

test/cdata.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import test from 'tape'
1+
import assert from 'node:assert/strict'
2+
import test from 'node:test'
23
import {u} from 'unist-builder'
34
import {toXml} from '../index.js'
45

5-
test('`cdata`', (t) => {
6-
t.deepEqual(
6+
test('`cdata`', () => {
7+
assert.deepEqual(
78
toXml(u('cdata', '3 < 5 & 8 > 13')),
89
'<![CDATA[3 < 5 & 8 > 13]]>',
910
'should not encode `cdata`s'
1011
)
1112

12-
t.deepEqual(
13+
assert.deepEqual(
1314
toXml(u('cdata', '3 ]]> 5')),
1415
'<![CDATA[3 ]]&#x3E; 5]]>',
1516
'should encode cdata otherwise closing `cdata`s'
1617
)
17-
18-
t.end()
1918
})

test/comment.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
import test from 'tape'
1+
import assert from 'node:assert/strict'
2+
import test from 'node:test'
23
import {u} from 'unist-builder'
34
import {toXml} from '../index.js'
45

5-
test('`comment`', (t) => {
6-
t.deepEqual(
6+
test('`comment`', () => {
7+
assert.deepEqual(
78
toXml(u('comment', 'alpha')),
89
'<!--alpha-->',
910
'should serialize `comment`s'
1011
)
1112

12-
t.deepEqual(
13+
assert.deepEqual(
1314
toXml(u('comment', 'AT&T')),
1415
'<!--AT&T-->',
1516
'should not encode `comment`s (#1)'
1617
)
1718

1819
// No way to get around this.
19-
t.deepEqual(
20+
assert.deepEqual(
2021
toXml(u('comment', '-->')),
2122
'<!--&#x2D;&#x2D;>-->',
2223
'should not encode `comment`s (#2)'
2324
)
24-
25-
t.end()
2625
})

test/core.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import test from 'tape'
1+
import assert from 'node:assert/strict'
2+
import test from 'node:test'
23
import {u} from 'unist-builder'
34
import {toXml} from '../index.js'
45

5-
test('toXml()', (t) => {
6-
t.throws(
6+
test('toXml()', () => {
7+
assert.throws(
78
() => {
89
// @ts-expect-error runtime.
910
toXml(true)
@@ -12,14 +13,12 @@ test('toXml()', (t) => {
1213
'should throw on non-nodes'
1314
)
1415

15-
t.throws(
16+
assert.throws(
1617
() => {
1718
// @ts-expect-error runtime.
1819
toXml(u('foo', []))
1920
},
2021
/Cannot compile unknown node `foo`/,
2122
'should throw on unknown nodes'
2223
)
23-
24-
t.end()
2524
})

0 commit comments

Comments
 (0)