1
- import test from 'tape'
1
+ import assert from 'node:assert/strict'
2
+ import test from 'node:test'
2
3
import { webNamespaces as ns } from 'web-namespaces'
3
4
import { u } from 'unist-builder'
4
5
import { h , s } from 'hastscript'
5
6
import { x } from 'xastscript'
6
7
import { toXast } from './index.js'
7
8
8
- test ( 'toXast' , ( t ) => {
9
- t . test ( 'main' , ( t ) => {
10
- t . equal ( typeof toXast , 'function' , 'should expose a function' )
9
+ test ( 'toXast' , async ( t ) => {
10
+ await t . test ( 'main' , ( ) => {
11
+ assert . equal ( typeof toXast , 'function' , 'should expose a function' )
11
12
12
- t . throws (
13
+ assert . throws (
13
14
( ) => {
14
15
// @ts -expect-error runtime.
15
16
toXast ( )
@@ -18,7 +19,7 @@ test('toXast', (t) => {
18
19
'should throw without node'
19
20
)
20
21
21
- t . throws (
22
+ assert . throws (
22
23
( ) => {
23
24
// @ts -expect-error well-known.
24
25
toXast ( { type : 'raw' , value : '<script>alert(1)</script>' } )
@@ -27,25 +28,25 @@ test('toXast', (t) => {
27
28
'should throw if a node cannot be handled'
28
29
)
29
30
30
- t . deepEqual (
31
+ assert . deepEqual (
31
32
toXast ( h ( 'div' ) ) ,
32
33
x ( 'div' , { xmlns : ns . html } ) ,
33
34
'should support html'
34
35
)
35
36
36
- t . deepEqual (
37
+ assert . deepEqual (
37
38
toXast ( s ( 'rect' ) , { space : 'svg' } ) ,
38
39
x ( 'rect' , { xmlns : ns . svg } ) ,
39
40
'should support `options.space` (svg)'
40
41
)
41
42
42
- t . deepEqual (
43
+ assert . deepEqual (
43
44
toXast ( s ( 'circle' ) , 'svg' ) ,
44
45
x ( 'circle' , { xmlns : ns . svg } ) ,
45
46
'should support `space` (svg)'
46
47
)
47
48
48
- t . deepEqual (
49
+ assert . deepEqual (
49
50
toXast ( {
50
51
type : 'text' ,
51
52
value : 'foo' ,
@@ -64,73 +65,63 @@ test('toXast', (t) => {
64
65
} ,
65
66
'should support positional information'
66
67
)
67
-
68
- t . end ( )
69
68
} )
70
69
71
- t . test ( 'root' , ( t ) => {
72
- t . deepEqual (
70
+ await t . test ( 'root' , ( ) => {
71
+ assert . deepEqual (
73
72
toXast ( u ( 'root' , [ h ( 'div' , 'Alpha' ) ] ) ) ,
74
73
u ( 'root' , [ x ( 'div' , { xmlns : ns . html } , 'Alpha' ) ] ) ,
75
74
'should support a root node'
76
75
)
77
-
78
- t . end ( )
79
76
} )
80
77
81
- t . test ( 'text' , ( t ) => {
82
- t . deepEqual (
78
+ await t . test ( 'text' , ( ) => {
79
+ assert . deepEqual (
83
80
toXast ( u ( 'text' , 'Alpha' ) ) ,
84
81
u ( 'text' , 'Alpha' ) ,
85
82
'should support a text node'
86
83
)
87
84
88
- t . deepEqual (
85
+ assert . deepEqual (
89
86
// @ts -expect-error runtime.
90
87
toXast ( u ( 'text' ) ) ,
91
88
u ( 'text' , '' ) ,
92
89
'should support a void text node'
93
90
)
94
-
95
- t . end ( )
96
91
} )
97
92
98
- t . test ( 'comment' , ( t ) => {
99
- t . deepEqual (
93
+ await t . test ( 'comment' , ( ) => {
94
+ assert . deepEqual (
100
95
toXast ( u ( 'comment' , 'Alpha' ) ) ,
101
96
u ( 'comment' , 'Alpha' ) ,
102
97
'should support a comment node'
103
98
)
104
99
105
- t . deepEqual (
100
+ assert . deepEqual (
106
101
// @ts -expect-error runtime.
107
102
toXast ( u ( 'comment' ) ) ,
108
103
u ( 'comment' , '' ) ,
109
104
'should support a void comment node'
110
105
)
111
-
112
- t . end ( )
113
106
} )
114
107
115
- t . test ( 'doctype' , ( t ) => {
116
- t . deepEqual (
108
+ await t . test ( 'doctype' , ( ) => {
109
+ assert . deepEqual (
117
110
// @ts -expect-error hast@next.
118
111
toXast ( u ( 'doctype' ) ) ,
119
112
u ( 'doctype' , { name : 'html' , public : undefined , system : undefined } ) ,
120
113
'should support a doctype node'
121
114
)
122
-
123
- t . end ( )
124
115
} )
125
116
126
- t . test ( 'element' , ( t ) => {
127
- t . deepEqual (
117
+ await t . test ( 'element' , ( ) => {
118
+ assert . deepEqual (
128
119
toXast ( h ( 'p' , [ h ( 'a' , 'A' ) , ' & ' , h ( 'b' , 'B' ) , '.' ] ) ) ,
129
120
x ( 'p' , { xmlns : ns . html } , [ x ( 'a' , 'A' ) , ' & ' , x ( 'b' , 'B' ) , '.' ] ) ,
130
121
'should support elements'
131
122
)
132
123
133
- t . deepEqual (
124
+ assert . deepEqual (
134
125
toXast ( {
135
126
type : 'element' ,
136
127
tagName : 'template' ,
@@ -147,7 +138,7 @@ test('toXast', (t) => {
147
138
'should support template elements'
148
139
)
149
140
150
- t . deepEqual (
141
+ assert . deepEqual (
151
142
toXast ( h ( 'p#a.b.c' , { ariaLabel : 'd' , dataE : 'f' } , 'Alpha' ) ) ,
152
143
x (
153
144
'p' ,
@@ -162,98 +153,96 @@ test('toXast', (t) => {
162
153
) ,
163
154
'should support attributes'
164
155
)
165
-
166
- t . end ( )
167
156
} )
168
157
169
- t . test ( 'attributes' , ( t ) => {
170
- t . deepEqual (
158
+ await t . test ( 'attributes' , ( ) => {
159
+ assert . deepEqual (
171
160
toXast ( u ( 'element' , { tagName : 'br' } , [ ] ) ) ,
172
161
x ( 'br' , { xmlns : ns . html } ) ,
173
162
'should not fail for elements without properties'
174
163
)
175
164
176
- t . deepEqual (
165
+ assert . deepEqual (
177
166
toXast ( u ( 'element' , { tagName : 'br' , properties : { prop : null } } , [ ] ) ) ,
178
167
x ( 'br' , { xmlns : ns . html } ) ,
179
168
'should support attribute values: `null`'
180
169
)
181
170
182
- t . deepEqual (
171
+ assert . deepEqual (
183
172
toXast ( u ( 'element' , { tagName : 'br' , properties : { prop : undefined } } , [ ] ) ) ,
184
173
x ( 'br' , { xmlns : ns . html } ) ,
185
174
'should support attribute values: `undefined`'
186
175
)
187
176
188
- t . deepEqual (
177
+ assert . deepEqual (
189
178
toXast ( u ( 'element' , { tagName : 'br' , properties : { prop : Number . NaN } } , [ ] ) ) ,
190
179
x ( 'br' , { xmlns : ns . html } ) ,
191
180
'should support attribute values: `NaN`'
192
181
)
193
182
194
- t . deepEqual (
183
+ assert . deepEqual (
195
184
toXast ( u ( 'element' , { tagName : 'br' , properties : { prop : false } } , [ ] ) ) ,
196
185
x ( 'br' , { xmlns : ns . html } ) ,
197
186
'should support attribute values: `false`'
198
187
)
199
188
200
- t . deepEqual (
189
+ assert . deepEqual (
201
190
toXast ( u ( 'element' , { tagName : 'br' , properties : { prop : true } } , [ ] ) ) ,
202
191
x ( 'br' , { xmlns : ns . html , prop : '' } ) ,
203
192
'should support attribute values: `true`'
204
193
)
205
194
206
- t . deepEqual (
195
+ assert . deepEqual (
207
196
toXast ( u ( 'element' , { tagName : 'script' , properties : { async : 0 } } , [ ] ) ) ,
208
197
x ( 'script' , { xmlns : ns . html } ) ,
209
198
'should support known falsey boolean attribute values'
210
199
)
211
200
212
- t . deepEqual (
201
+ assert . deepEqual (
213
202
toXast ( u ( 'element' , { tagName : 'br' , properties : { prop : 1.2 } } , [ ] ) ) ,
214
203
x ( 'br' , { xmlns : ns . html , prop : '1.2' } ) ,
215
204
'should support numeric attribute values'
216
205
)
217
206
218
- t . deepEqual (
207
+ assert . deepEqual (
219
208
toXast (
220
209
u ( 'element' , { tagName : 'br' , properties : { className : [ 'a' , 'b' ] } } , [ ] )
221
210
) ,
222
211
x ( 'br' , { xmlns : ns . html , class : 'a b' } ) ,
223
212
'should support known space-separated attribute values'
224
213
)
225
214
226
- t . deepEqual (
215
+ assert . deepEqual (
227
216
toXast (
228
217
u ( 'element' , { tagName : 'br' , properties : { accept : [ 'a' , 'b' ] } } , [ ] )
229
218
) ,
230
219
x ( 'br' , { xmlns : ns . html , accept : 'a, b' } ) ,
231
220
'should support known comma-separated attribute values'
232
221
)
233
222
234
- t . deepEqual (
223
+ assert . deepEqual (
235
224
toXast ( u ( 'element' , { tagName : 'br' , properties : { xmlLang : 'en' } } , [ ] ) ) ,
236
225
x ( 'br' , { xmlns : ns . html , 'xml:lang' : 'en' } ) ,
237
226
'should support attributes in the xml space (1)'
238
227
)
239
228
240
- t . deepEqual (
229
+ assert . deepEqual (
241
230
toXast (
242
231
u ( 'element' , { tagName : 'svg' , properties : { xmlSpace : 'preserve' } } , [ ] )
243
232
) ,
244
233
x ( 'svg' , { xmlns : ns . svg , 'xml:space' : 'preserve' } ) ,
245
234
'should support attributes in the xml space (2)'
246
235
)
247
236
248
- t . deepEqual (
237
+ assert . deepEqual (
249
238
toXast (
250
239
u ( 'element' , { tagName : 'svg' , properties : { xmlnsXLink : ns . xlink } } , [ ] )
251
240
) ,
252
241
x ( 'svg' , { xmlns : ns . svg , 'xmlns:xlink' : ns . xlink } ) ,
253
242
'should support attributes in the xmlns space'
254
243
)
255
244
256
- t . deepEqual (
245
+ assert . deepEqual (
257
246
toXast (
258
247
u (
259
248
'element' ,
@@ -275,15 +264,15 @@ test('toXast', (t) => {
275
264
'should support attributes in the xlink space'
276
265
)
277
266
278
- t . deepEqual (
267
+ assert . deepEqual (
279
268
toXast (
280
269
u ( 'element' , { tagName : 'x' , properties : { 'alpha:bravo' : 'charlie' } } , [ ] )
281
270
) ,
282
271
x ( 'x' , { xmlns : ns . html , 'alpha:bravo' : 'charlie' } ) ,
283
272
'should include random prefixes'
284
273
)
285
274
286
- t . deepEqual (
275
+ assert . deepEqual (
287
276
toXast (
288
277
u (
289
278
'element' ,
@@ -298,12 +287,10 @@ test('toXast', (t) => {
298
287
} ) ,
299
288
'should include undefined prefixed attributes'
300
289
)
301
-
302
- t . end ( )
303
290
} )
304
291
305
- t . test ( 'aria' , ( t ) => {
306
- t . deepEqual (
292
+ await t . test ( 'aria' , ( ) => {
293
+ assert . deepEqual (
307
294
toXast (
308
295
h ( 'a' , { ariaHidden : 'true' , href : '#lorem-ipsum' } , [
309
296
h ( 'span.icon.icon-link' )
@@ -314,12 +301,10 @@ test('toXast', (t) => {
314
301
] ) ,
315
302
'should support aria'
316
303
)
317
-
318
- t . end ( )
319
304
} )
320
305
321
- t . test ( 'svg' , ( t ) => {
322
- t . deepEqual (
306
+ await t . test ( 'svg' , ( ) => {
307
+ assert . deepEqual (
323
308
toXast (
324
309
s (
325
310
'svg' ,
@@ -353,7 +338,7 @@ test('toXast', (t) => {
353
338
'should support svg'
354
339
)
355
340
356
- t . deepEqual (
341
+ assert . deepEqual (
357
342
toXast (
358
343
u ( 'root' , [
359
344
u ( 'doctype' , { name : 'html' } ) ,
@@ -381,7 +366,7 @@ test('toXast', (t) => {
381
366
'should support svg in html'
382
367
)
383
368
384
- t . deepEqual (
369
+ assert . deepEqual (
385
370
toXast (
386
371
u ( 'root' , [
387
372
u ( 'doctype' , { name : 'html' } ) ,
@@ -414,12 +399,10 @@ test('toXast', (t) => {
414
399
] ) ,
415
400
'should support html in svg in html'
416
401
)
417
-
418
- t . end ( )
419
402
} )
420
403
421
- t . test ( 'mathml' , ( t ) => {
422
- t . deepEqual (
404
+ await t . test ( 'mathml' , ( ) => {
405
+ assert . deepEqual (
423
406
toXast (
424
407
u ( 'element' , { tagName : 'p' , properties : { } } , [
425
408
u ( 'element' , { tagName : 'math' , properties : { xmlns : ns . mathml } } , [
@@ -438,9 +421,5 @@ test('toXast', (t) => {
438
421
] ) ,
439
422
'should *not really* support mathml'
440
423
)
441
-
442
- t . end ( )
443
424
} )
444
-
445
- t . end ( )
446
425
} )
0 commit comments