22 * @typedef {import('vfile-message').VFileMessage } VFileMessage
33 */
44
5+ import assert from 'node:assert/strict'
56import fs from 'node:fs/promises'
6- import test from 'tape '
7+ import test from 'node:test '
78import { VFile } from 'vfile'
89import { toVFile , read } from 'to-vfile'
910import { fromHtml } from '../index.js'
1011import { errors as rerrors } from '../lib/errors.js'
1112
12- test ( 'hast-util-from-html' , ( t ) => {
13- t . deepEqual (
13+ test ( 'hast-util-from-html' , ( ) => {
14+ assert . deepEqual (
1415 fromHtml ( 'a' ) ,
1516 {
1617 type : 'root' ,
@@ -48,7 +49,7 @@ test('hast-util-from-html', (t) => {
4849 'should work'
4950 )
5051
51- t . deepEqual (
52+ assert . deepEqual (
5253 fromHtml ( 'a' , { fragment : true } ) ,
5354 {
5455 type : 'root' ,
@@ -80,7 +81,7 @@ test('hast-util-from-html', (t) => {
8081 }
8182 } )
8283
83- t . deepEqual (
84+ assert . deepEqual (
8485 JSON . parse ( JSON . stringify ( args ) ) ,
8586 [
8687 {
@@ -111,7 +112,7 @@ test('hast-util-from-html', (t) => {
111112 missingDoctype : 0
112113 } )
113114
114- t . deepEqual (
115+ assert . deepEqual (
115116 JSON . stringify ( args ) ,
116117 undefined ,
117118 'should support `options.*` to level warnings (w/ numbers)'
@@ -125,7 +126,7 @@ test('hast-util-from-html', (t) => {
125126 missingDoctype : false
126127 } )
127128
128- t . deepEqual (
129+ assert . deepEqual (
129130 JSON . stringify ( args ) ,
130131 undefined ,
131132 'should support `options.*` to level warnings (w/ booleans)'
@@ -139,7 +140,7 @@ test('hast-util-from-html', (t) => {
139140 missingDoctype : false
140141 } )
141142
142- t . deepEqual (
143+ assert . deepEqual (
143144 JSON . parse ( JSON . stringify ( args ) ) ,
144145 [
145146 {
@@ -170,7 +171,7 @@ test('hast-util-from-html', (t) => {
170171 missingDoctype : false
171172 } )
172173
173- t . deepEqual (
174+ assert . deepEqual (
174175 JSON . parse ( JSON . stringify ( args ) ) ,
175176 [
176177 {
@@ -201,7 +202,7 @@ test('hast-util-from-html', (t) => {
201202 missingDoctype : false
202203 } )
203204
204- t . deepEqual (
205+ assert . deepEqual (
205206 JSON . parse ( JSON . stringify ( args ) ) ,
206207 [
207208 {
@@ -232,7 +233,7 @@ test('hast-util-from-html', (t) => {
232233 missingDoctype : false
233234 } )
234235
235- t . deepEqual (
236+ assert . deepEqual (
236237 JSON . parse ( JSON . stringify ( args ) ) ,
237238 [
238239 {
@@ -262,7 +263,7 @@ test('hast-util-from-html', (t) => {
262263 }
263264 } )
264265
265- t . deepEqual (
266+ assert . deepEqual (
266267 JSON . parse ( JSON . stringify ( args ) ) ,
267268 [
268269 {
@@ -285,13 +286,11 @@ test('hast-util-from-html', (t) => {
285286 ] ,
286287 'should support vfiles'
287288 )
288-
289- t . end ( )
290289} )
291290
292291// Related to https://github.com/inikulin/parse5/issues/255
293292// and https://github.com/inikulin/parse5/pull/257.
294- test ( 'parse errors: coverage' , async ( t ) => {
293+ test ( 'parse errors: coverage' , async ( ) => {
295294 await fs . writeFile (
296295 new URL ( 'error-codes-from-p5.js' , import . meta. url ) ,
297296 '// @ts-nocheck\n/** @type {Record<string, string>} */\n' +
@@ -309,21 +308,17 @@ test('parse errors: coverage', async (t) => {
309308 // @ts -ignore: this errors when tests did not run before build.
310309 const { ERR : p5errors } = await import ( './error-codes-from-p5.js' )
311310
312- t . deepEqual (
311+ assert . deepEqual (
313312 Object . keys ( p5errors ) . sort ( ) ,
314313 Object . keys ( rerrors ) . sort ( ) ,
315314 'all codes from `parse5` should be covered by `hast-util-from-html`'
316315 )
317-
318- t . end ( )
319316} )
320317
321318test ( 'parse-errors: working' , async ( t ) => {
322- let index = - 1
323319 const root = new URL ( 'parse-error/' , import . meta. url )
324- const fixtures = await fs . readdir ( root )
325320
326- t . test ( 'surrogate-in-input-stream' , ( t ) => {
321+ await t . test ( 'surrogate-in-input-stream' , ( ) => {
327322 const file = toVFile ( {
328323 path : 'index.html' ,
329324 value : '<!doctype html>\n' + String . fromCharCode ( 0xd8_00 )
@@ -338,7 +333,7 @@ test('parse-errors: working', async (t) => {
338333 }
339334 } )
340335
341- t . deepEqual (
336+ assert . deepEqual (
342337 JSON . parse ( JSON . stringify ( actual ) ) ,
343338 [
344339 {
@@ -361,26 +356,20 @@ test('parse-errors: working', async (t) => {
361356 ] ,
362357 'should emit messages'
363358 )
364-
365- t . end ( )
366359 } )
367360
368361 /* Check the next fixture. */
369- function next ( ) {
370- const fixture = fixtures [ ++ index ]
362+ let index = - 1
363+ const fixtures = await fs . readdir ( root )
371364
372- if ( ! fixture ) {
373- return
374- }
365+ while ( ++ index < fixtures . length ) {
366+ const fixture = fixtures [ index ]
375367
376368 if ( fixture . charAt ( 0 ) === '.' ) {
377- setImmediate ( next )
378- return
369+ continue
379370 }
380371
381- setImmediate ( next ) // Queue next.
382-
383- t . test ( fixture , async ( t ) => {
372+ await t . test ( fixture , async ( ) => {
384373 const file = await read ( new URL ( fixture + '/index.html' , root ) , 'utf8' )
385374 /** @type {Array<Error> } */
386375 const messages = JSON . parse (
@@ -397,15 +386,11 @@ test('parse-errors: working', async (t) => {
397386 }
398387 } )
399388
400- t . deepEqual (
389+ assert . deepEqual (
401390 JSON . parse ( JSON . stringify ( actual ) ) ,
402391 messages ,
403392 'should emit messages for `' + fixture + '`'
404393 )
405-
406- t . end ( )
407394 } )
408395 }
409-
410- next ( )
411396} )
0 commit comments