22 * @typedef {import('../lib/index.js').HastNode } HastNode
33 */
44
5+ import assert from 'node:assert'
56import fs from 'node:fs/promises'
67import process from 'node:process'
7- import test from 'tape '
8+ import test from 'node:test '
89import { JSDOM } from 'jsdom'
910import { webNamespaces } from 'web-namespaces'
1011import { h , s } from 'hastscript'
@@ -15,15 +16,15 @@ const document = new JSDOM().window.document
1516
1617globalThis . document = document
1718
18- test ( 'hast-util-to-dom' , ( t ) => {
19- t . equal (
19+ test ( 'hast-util-to-dom' , ( ) => {
20+ assert . equal (
2021 // @ts -expect-error runtime.
2122 serializeNodeToHtmlString ( toDom ( { type : 'root' } ) ) ,
2223 '' ,
2324 'creates an empty root node'
2425 )
2526
26- t . equal (
27+ assert . equal (
2728 serializeNodeToHtmlString (
2829 toDom ( {
2930 type : 'root' ,
@@ -36,7 +37,7 @@ test('hast-util-to-dom', (t) => {
3637 'creates a root node with a document element'
3738 )
3839
39- t . equal (
40+ assert . equal (
4041 serializeNodeToHtmlString (
4142 toDom ( {
4243 type : 'root' ,
@@ -58,26 +59,26 @@ test('hast-util-to-dom', (t) => {
5859 'creates a root node with a doctype'
5960 )
6061
61- t . equal (
62+ assert . equal (
6263 serializeNodeToHtmlString ( toDom ( { type : 'text' , value : 'hello world' } ) ) ,
6364 'hello world' ,
6465 'creates a text node'
6566 )
6667
67- t . equal (
68+ assert . equal (
6869 serializeNodeToHtmlString ( toDom ( h ( 'div' ) ) ) ,
6970 '<div></div>' ,
7071 'creates an element node'
7172 )
7273
73- t . equal (
74+ assert . equal (
7475 // @ts -expect-error runtime.
7576 serializeNodeToHtmlString ( toDom ( { type : 'something-else' } ) ) ,
7677 '<div></div>' ,
7778 'creates an unknown node in HTML'
7879 )
7980
80- t . equal (
81+ assert . equal (
8182 serializeNodeToHtmlString (
8283 // @ts -expect-error runtime.
8384 toDom ( { type : 'something-else' } , { namespace : webNamespaces . svg } )
@@ -86,7 +87,7 @@ test('hast-util-to-dom', (t) => {
8687 'creates an unknown node in SVG'
8788 )
8889
89- t . equal (
90+ assert . equal (
9091 serializeNodeToHtmlString (
9192 toDom ( {
9293 // @ts -expect-error runtime.
@@ -98,43 +99,43 @@ test('hast-util-to-dom', (t) => {
9899 'creates an unknown node (with children)'
99100 )
100101
101- t . equal (
102+ assert . equal (
102103 serializeNodeToHtmlString ( toDom ( h ( 'span' , [ 'hello' , 'world' ] ) ) ) ,
103104 '<span>helloworld</span>' ,
104105 'creates text nodes inside an element node'
105106 )
106107
107- t . equal (
108+ assert . equal (
108109 serializeNodeToHtmlString ( toDom ( h ( '#foo.bar' , 'text' ) ) ) ,
109110 '<div id="foo" class="bar">text</div>' ,
110111 'creates an html element'
111112 )
112113
113- t . equal (
114+ assert . equal (
114115 serializeNodeToHtmlString (
115116 toDom ( s ( '#foo.bar' , s ( 'circle' ) ) , { namespace : webNamespaces . svg } )
116117 ) ,
117118 '<g id="foo" class="bar"><circle/></g>' ,
118119 'creates SVG elements'
119120 )
120121
121- t . equal (
122+ assert . equal (
122123 serializeNodeToHtmlString (
123124 toDom ( h ( 'input' , { disabled : true , value : 'foo' } ) )
124125 ) ,
125126 '<input disabled="" value="foo" />' ,
126127 'creates an input node with some attributes'
127128 )
128129
129- t . equal (
130+ assert . equal (
130131 serializeNodeToHtmlString (
131132 toDom ( h ( 'input' , { type : 'checkbox' , checked : true } ) )
132133 ) ,
133134 '<input type="checkbox" checked="" />' ,
134135 'creates an checkbox where `checked` must be set as a property'
135136 )
136137
137- t . equal (
138+ assert . equal (
138139 serializeNodeToHtmlString (
139140 toDom ( {
140141 type : 'element' ,
@@ -147,34 +148,34 @@ test('hast-util-to-dom', (t) => {
147148 'handles falsey booleans correctly'
148149 )
149150
150- t . equal (
151+ assert . equal (
151152 serializeNodeToHtmlString ( toDom ( h ( 'div' , { class : [ 'foo' , 'bar' ] } ) ) ) ,
152153 '<div class="foo bar"></div>' ,
153154 'handles space-separated attributes correctly'
154155 )
155156
156- t . equal (
157+ assert . equal (
157158 serializeNodeToHtmlString (
158159 toDom ( h ( 'input' , { type : 'file' , accept : [ 'image/*' , '.doc' ] } ) )
159160 ) ,
160161 `<input type="file" accept="image/*, .doc" />` ,
161162 'handles comma-separated attributes correctly'
162163 )
163164
164- t . equal (
165+ assert . equal (
165166 // @ts -expect-error hast types out of date.
166167 serializeNodeToHtmlString ( toDom ( { type : 'doctype' } ) ) ,
167168 '<!DOCTYPE html>' ,
168169 'creates a doctype node'
169170 )
170171
171- t . equal (
172+ assert . equal (
172173 serializeNodeToHtmlString ( toDom ( { type : 'comment' , value : 'after' } ) ) ,
173174 '<!--after-->' ,
174175 'creates a comment'
175176 )
176177
177- t . equal (
178+ assert . equal (
178179 serializeNodeToHtmlString (
179180 toDom (
180181 h ( '.alpha' , [
@@ -189,7 +190,7 @@ test('hast-util-to-dom', (t) => {
189190 'creates nested nodes with attributes'
190191 )
191192
192- t . equal (
193+ assert . equal (
193194 serializeNodeToHtmlString (
194195 toDom ( {
195196 type : 'root' ,
@@ -213,7 +214,7 @@ test('hast-util-to-dom', (t) => {
213214 'wraps a fragment in an HTML element'
214215 )
215216
216- t . equal (
217+ assert . equal (
217218 serializeNodeToHtmlString (
218219 toDom (
219220 {
@@ -240,7 +241,7 @@ test('hast-util-to-dom', (t) => {
240241 'does not wrap a fragment when the option is specified'
241242 )
242243
243- t . equal (
244+ assert . equal (
244245 serializeNodeToHtmlString (
245246 toDom (
246247 { type : 'root' , children : [ h ( 'html' ) ] } ,
@@ -282,7 +283,7 @@ test('hast-util-to-dom', (t) => {
282283 }
283284 }
284285
285- t . equal (
286+ assert . equal (
286287 serializeNodeToHtmlString (
287288 toDom (
288289 {
@@ -297,67 +298,67 @@ test('hast-util-to-dom', (t) => {
297298 'should support a given document'
298299 )
299300
300- t . equal (
301+ assert . equal (
301302 serializeNodeToHtmlString ( toDom ( h ( 'div' , { ariaChecked : true } ) ) ) ,
302303 '<div aria-checked="true"></div>' ,
303304 'handles booleanish attribute with `true` value correctly'
304305 )
305306
306- t . equal (
307+ assert . equal (
307308 serializeNodeToHtmlString ( toDom ( h ( 'div' , { ariaChecked : false } ) ) ) ,
308309 '<div aria-checked="false"></div>' ,
309310 'handles booleanish attribute with `false` value correctly'
310311 )
311312
312- t . equal (
313+ assert . equal (
313314 serializeNodeToHtmlString ( toDom ( h ( 'div' , { ariaChecked : 'mixed' } ) ) ) ,
314315 '<div aria-checked="mixed"></div>' ,
315316 'handles booleanish attribute with value correctly'
316317 )
317318
318- t . equal (
319+ assert . equal (
319320 serializeNodeToHtmlString ( toDom ( h ( 'div' , { dataTest : false } ) ) ) ,
320321 '<div></div>' ,
321322 'ignores data properties when value is `false`'
322323 )
323324
324- t . equal (
325+ assert . equal (
325326 serializeNodeToHtmlString ( toDom ( h ( 'div' , { dataTest : Number . NaN } ) ) ) ,
326327 '<div></div>' ,
327328 'ignores data properties when value is `NaN`'
328329 )
329330
330- t . equal (
331+ assert . equal (
331332 serializeNodeToHtmlString ( toDom ( h ( 'div' , { dataTest : 0 } ) ) ) ,
332333 '<div data-test="0"></div>' ,
333334 'encodes data properties when a number'
334335 )
335336
336- t . equal (
337+ assert . equal (
337338 serializeNodeToHtmlString ( toDom ( h ( 'div' , { dataTest : true } ) ) ) ,
338339 '<div data-test=""></div>' ,
339340 'encodes data properties w/o value `true`'
340341 )
341342
342- t . equal (
343+ assert . equal (
343344 serializeNodeToHtmlString ( toDom ( h ( 'div' , { dataTest : '' } ) ) ) ,
344345 '<div data-test=""></div>' ,
345346 'encodes data properties when an empty string'
346347 )
347348
348- t . equal (
349+ assert . equal (
349350 serializeNodeToHtmlString ( toDom ( h ( 'div' , { dataTest : 'data-test' } ) ) ) ,
350351 '<div data-test="data-test"></div>' ,
351352 'encodes data properties when string'
352353 )
353354
354- t . equal (
355+ assert . equal (
355356 serializeNodeToHtmlString ( toDom ( h ( 'div' , { data123 : 'dataTest' } ) ) ) ,
356357 '<div data-123="dataTest"></div>' ,
357358 'encodes data properties when string'
358359 )
359360
360- t . deepEqual (
361+ assert . deepEqual (
361362 ( ( ) => {
362363 /** @type {Array<[HastNode, string]> } */
363364 const calls = [ ]
@@ -375,11 +376,9 @@ test('hast-util-to-dom', (t) => {
375376 ] ,
376377 'should call `afterTransform`'
377378 )
378-
379- t . end ( )
380379} )
381380
382- test ( 'fixtures' , async ( t ) => {
381+ test ( 'fixtures' , async ( ) => {
383382 const base = new URL ( 'fixtures/' , import . meta. url )
384383 const folders = await fs . readdir ( base )
385384
@@ -408,14 +407,17 @@ test('fixtures', async (t) => {
408407 continue
409408 }
410409
411- t . equal ( actual , expected , folder )
410+ assert . equal ( actual , expected , folder )
412411 }
413-
414- t . end ( )
415412} )
416413
417414/**
415+ * Serialize a DOM node as HTML.
416+ *
418417 * @param {Node } node
418+ * DOM node.
419+ * @returns {string }
420+ * Serialized HTML.
419421 */
420422function serializeNodeToHtmlString ( node ) {
421423 const serialized = serialize ( node )
0 commit comments