2
2
* @typedef {import('../lib/index.js').HastNode } HastNode
3
3
*/
4
4
5
+ import assert from 'node:assert'
5
6
import fs from 'node:fs/promises'
6
7
import process from 'node:process'
7
- import test from 'tape '
8
+ import test from 'node:test '
8
9
import { JSDOM } from 'jsdom'
9
10
import { webNamespaces } from 'web-namespaces'
10
11
import { h , s } from 'hastscript'
@@ -15,15 +16,15 @@ const document = new JSDOM().window.document
15
16
16
17
globalThis . document = document
17
18
18
- test ( 'hast-util-to-dom' , ( t ) => {
19
- t . equal (
19
+ test ( 'hast-util-to-dom' , ( ) => {
20
+ assert . equal (
20
21
// @ts -expect-error runtime.
21
22
serializeNodeToHtmlString ( toDom ( { type : 'root' } ) ) ,
22
23
'' ,
23
24
'creates an empty root node'
24
25
)
25
26
26
- t . equal (
27
+ assert . equal (
27
28
serializeNodeToHtmlString (
28
29
toDom ( {
29
30
type : 'root' ,
@@ -36,7 +37,7 @@ test('hast-util-to-dom', (t) => {
36
37
'creates a root node with a document element'
37
38
)
38
39
39
- t . equal (
40
+ assert . equal (
40
41
serializeNodeToHtmlString (
41
42
toDom ( {
42
43
type : 'root' ,
@@ -58,26 +59,26 @@ test('hast-util-to-dom', (t) => {
58
59
'creates a root node with a doctype'
59
60
)
60
61
61
- t . equal (
62
+ assert . equal (
62
63
serializeNodeToHtmlString ( toDom ( { type : 'text' , value : 'hello world' } ) ) ,
63
64
'hello world' ,
64
65
'creates a text node'
65
66
)
66
67
67
- t . equal (
68
+ assert . equal (
68
69
serializeNodeToHtmlString ( toDom ( h ( 'div' ) ) ) ,
69
70
'<div></div>' ,
70
71
'creates an element node'
71
72
)
72
73
73
- t . equal (
74
+ assert . equal (
74
75
// @ts -expect-error runtime.
75
76
serializeNodeToHtmlString ( toDom ( { type : 'something-else' } ) ) ,
76
77
'<div></div>' ,
77
78
'creates an unknown node in HTML'
78
79
)
79
80
80
- t . equal (
81
+ assert . equal (
81
82
serializeNodeToHtmlString (
82
83
// @ts -expect-error runtime.
83
84
toDom ( { type : 'something-else' } , { namespace : webNamespaces . svg } )
@@ -86,7 +87,7 @@ test('hast-util-to-dom', (t) => {
86
87
'creates an unknown node in SVG'
87
88
)
88
89
89
- t . equal (
90
+ assert . equal (
90
91
serializeNodeToHtmlString (
91
92
toDom ( {
92
93
// @ts -expect-error runtime.
@@ -98,43 +99,43 @@ test('hast-util-to-dom', (t) => {
98
99
'creates an unknown node (with children)'
99
100
)
100
101
101
- t . equal (
102
+ assert . equal (
102
103
serializeNodeToHtmlString ( toDom ( h ( 'span' , [ 'hello' , 'world' ] ) ) ) ,
103
104
'<span>helloworld</span>' ,
104
105
'creates text nodes inside an element node'
105
106
)
106
107
107
- t . equal (
108
+ assert . equal (
108
109
serializeNodeToHtmlString ( toDom ( h ( '#foo.bar' , 'text' ) ) ) ,
109
110
'<div id="foo" class="bar">text</div>' ,
110
111
'creates an html element'
111
112
)
112
113
113
- t . equal (
114
+ assert . equal (
114
115
serializeNodeToHtmlString (
115
116
toDom ( s ( '#foo.bar' , s ( 'circle' ) ) , { namespace : webNamespaces . svg } )
116
117
) ,
117
118
'<g id="foo" class="bar"><circle/></g>' ,
118
119
'creates SVG elements'
119
120
)
120
121
121
- t . equal (
122
+ assert . equal (
122
123
serializeNodeToHtmlString (
123
124
toDom ( h ( 'input' , { disabled : true , value : 'foo' } ) )
124
125
) ,
125
126
'<input disabled="" value="foo" />' ,
126
127
'creates an input node with some attributes'
127
128
)
128
129
129
- t . equal (
130
+ assert . equal (
130
131
serializeNodeToHtmlString (
131
132
toDom ( h ( 'input' , { type : 'checkbox' , checked : true } ) )
132
133
) ,
133
134
'<input type="checkbox" checked="" />' ,
134
135
'creates an checkbox where `checked` must be set as a property'
135
136
)
136
137
137
- t . equal (
138
+ assert . equal (
138
139
serializeNodeToHtmlString (
139
140
toDom ( {
140
141
type : 'element' ,
@@ -147,34 +148,34 @@ test('hast-util-to-dom', (t) => {
147
148
'handles falsey booleans correctly'
148
149
)
149
150
150
- t . equal (
151
+ assert . equal (
151
152
serializeNodeToHtmlString ( toDom ( h ( 'div' , { class : [ 'foo' , 'bar' ] } ) ) ) ,
152
153
'<div class="foo bar"></div>' ,
153
154
'handles space-separated attributes correctly'
154
155
)
155
156
156
- t . equal (
157
+ assert . equal (
157
158
serializeNodeToHtmlString (
158
159
toDom ( h ( 'input' , { type : 'file' , accept : [ 'image/*' , '.doc' ] } ) )
159
160
) ,
160
161
`<input type="file" accept="image/*, .doc" />` ,
161
162
'handles comma-separated attributes correctly'
162
163
)
163
164
164
- t . equal (
165
+ assert . equal (
165
166
// @ts -expect-error hast types out of date.
166
167
serializeNodeToHtmlString ( toDom ( { type : 'doctype' } ) ) ,
167
168
'<!DOCTYPE html>' ,
168
169
'creates a doctype node'
169
170
)
170
171
171
- t . equal (
172
+ assert . equal (
172
173
serializeNodeToHtmlString ( toDom ( { type : 'comment' , value : 'after' } ) ) ,
173
174
'<!--after-->' ,
174
175
'creates a comment'
175
176
)
176
177
177
- t . equal (
178
+ assert . equal (
178
179
serializeNodeToHtmlString (
179
180
toDom (
180
181
h ( '.alpha' , [
@@ -189,7 +190,7 @@ test('hast-util-to-dom', (t) => {
189
190
'creates nested nodes with attributes'
190
191
)
191
192
192
- t . equal (
193
+ assert . equal (
193
194
serializeNodeToHtmlString (
194
195
toDom ( {
195
196
type : 'root' ,
@@ -213,7 +214,7 @@ test('hast-util-to-dom', (t) => {
213
214
'wraps a fragment in an HTML element'
214
215
)
215
216
216
- t . equal (
217
+ assert . equal (
217
218
serializeNodeToHtmlString (
218
219
toDom (
219
220
{
@@ -240,7 +241,7 @@ test('hast-util-to-dom', (t) => {
240
241
'does not wrap a fragment when the option is specified'
241
242
)
242
243
243
- t . equal (
244
+ assert . equal (
244
245
serializeNodeToHtmlString (
245
246
toDom (
246
247
{ type : 'root' , children : [ h ( 'html' ) ] } ,
@@ -282,7 +283,7 @@ test('hast-util-to-dom', (t) => {
282
283
}
283
284
}
284
285
285
- t . equal (
286
+ assert . equal (
286
287
serializeNodeToHtmlString (
287
288
toDom (
288
289
{
@@ -297,67 +298,67 @@ test('hast-util-to-dom', (t) => {
297
298
'should support a given document'
298
299
)
299
300
300
- t . equal (
301
+ assert . equal (
301
302
serializeNodeToHtmlString ( toDom ( h ( 'div' , { ariaChecked : true } ) ) ) ,
302
303
'<div aria-checked="true"></div>' ,
303
304
'handles booleanish attribute with `true` value correctly'
304
305
)
305
306
306
- t . equal (
307
+ assert . equal (
307
308
serializeNodeToHtmlString ( toDom ( h ( 'div' , { ariaChecked : false } ) ) ) ,
308
309
'<div aria-checked="false"></div>' ,
309
310
'handles booleanish attribute with `false` value correctly'
310
311
)
311
312
312
- t . equal (
313
+ assert . equal (
313
314
serializeNodeToHtmlString ( toDom ( h ( 'div' , { ariaChecked : 'mixed' } ) ) ) ,
314
315
'<div aria-checked="mixed"></div>' ,
315
316
'handles booleanish attribute with value correctly'
316
317
)
317
318
318
- t . equal (
319
+ assert . equal (
319
320
serializeNodeToHtmlString ( toDom ( h ( 'div' , { dataTest : false } ) ) ) ,
320
321
'<div></div>' ,
321
322
'ignores data properties when value is `false`'
322
323
)
323
324
324
- t . equal (
325
+ assert . equal (
325
326
serializeNodeToHtmlString ( toDom ( h ( 'div' , { dataTest : Number . NaN } ) ) ) ,
326
327
'<div></div>' ,
327
328
'ignores data properties when value is `NaN`'
328
329
)
329
330
330
- t . equal (
331
+ assert . equal (
331
332
serializeNodeToHtmlString ( toDom ( h ( 'div' , { dataTest : 0 } ) ) ) ,
332
333
'<div data-test="0"></div>' ,
333
334
'encodes data properties when a number'
334
335
)
335
336
336
- t . equal (
337
+ assert . equal (
337
338
serializeNodeToHtmlString ( toDom ( h ( 'div' , { dataTest : true } ) ) ) ,
338
339
'<div data-test=""></div>' ,
339
340
'encodes data properties w/o value `true`'
340
341
)
341
342
342
- t . equal (
343
+ assert . equal (
343
344
serializeNodeToHtmlString ( toDom ( h ( 'div' , { dataTest : '' } ) ) ) ,
344
345
'<div data-test=""></div>' ,
345
346
'encodes data properties when an empty string'
346
347
)
347
348
348
- t . equal (
349
+ assert . equal (
349
350
serializeNodeToHtmlString ( toDom ( h ( 'div' , { dataTest : 'data-test' } ) ) ) ,
350
351
'<div data-test="data-test"></div>' ,
351
352
'encodes data properties when string'
352
353
)
353
354
354
- t . equal (
355
+ assert . equal (
355
356
serializeNodeToHtmlString ( toDom ( h ( 'div' , { data123 : 'dataTest' } ) ) ) ,
356
357
'<div data-123="dataTest"></div>' ,
357
358
'encodes data properties when string'
358
359
)
359
360
360
- t . deepEqual (
361
+ assert . deepEqual (
361
362
( ( ) => {
362
363
/** @type {Array<[HastNode, string]> } */
363
364
const calls = [ ]
@@ -375,11 +376,9 @@ test('hast-util-to-dom', (t) => {
375
376
] ,
376
377
'should call `afterTransform`'
377
378
)
378
-
379
- t . end ( )
380
379
} )
381
380
382
- test ( 'fixtures' , async ( t ) => {
381
+ test ( 'fixtures' , async ( ) => {
383
382
const base = new URL ( 'fixtures/' , import . meta. url )
384
383
const folders = await fs . readdir ( base )
385
384
@@ -408,14 +407,17 @@ test('fixtures', async (t) => {
408
407
continue
409
408
}
410
409
411
- t . equal ( actual , expected , folder )
410
+ assert . equal ( actual , expected , folder )
412
411
}
413
-
414
- t . end ( )
415
412
} )
416
413
417
414
/**
415
+ * Serialize a DOM node as HTML.
416
+ *
418
417
* @param {Node } node
418
+ * DOM node.
419
+ * @returns {string }
420
+ * Serialized HTML.
419
421
*/
420
422
function serializeNodeToHtmlString ( node ) {
421
423
const serialized = serialize ( node )
0 commit comments