2
2
* @typedef {import('vfile-message').VFileMessage } VFileMessage
3
3
*/
4
4
5
+ import assert from 'node:assert/strict'
5
6
import fs from 'node:fs/promises'
6
- import test from 'tape '
7
+ import test from 'node:test '
7
8
import { VFile } from 'vfile'
8
9
import { toVFile , read } from 'to-vfile'
9
10
import { fromHtml } from '../index.js'
10
11
import { errors as rerrors } from '../lib/errors.js'
11
12
12
- test ( 'hast-util-from-html' , ( t ) => {
13
- t . deepEqual (
13
+ test ( 'hast-util-from-html' , ( ) => {
14
+ assert . deepEqual (
14
15
fromHtml ( 'a' ) ,
15
16
{
16
17
type : 'root' ,
@@ -48,7 +49,7 @@ test('hast-util-from-html', (t) => {
48
49
'should work'
49
50
)
50
51
51
- t . deepEqual (
52
+ assert . deepEqual (
52
53
fromHtml ( 'a' , { fragment : true } ) ,
53
54
{
54
55
type : 'root' ,
@@ -80,7 +81,7 @@ test('hast-util-from-html', (t) => {
80
81
}
81
82
} )
82
83
83
- t . deepEqual (
84
+ assert . deepEqual (
84
85
JSON . parse ( JSON . stringify ( args ) ) ,
85
86
[
86
87
{
@@ -111,7 +112,7 @@ test('hast-util-from-html', (t) => {
111
112
missingDoctype : 0
112
113
} )
113
114
114
- t . deepEqual (
115
+ assert . deepEqual (
115
116
JSON . stringify ( args ) ,
116
117
undefined ,
117
118
'should support `options.*` to level warnings (w/ numbers)'
@@ -125,7 +126,7 @@ test('hast-util-from-html', (t) => {
125
126
missingDoctype : false
126
127
} )
127
128
128
- t . deepEqual (
129
+ assert . deepEqual (
129
130
JSON . stringify ( args ) ,
130
131
undefined ,
131
132
'should support `options.*` to level warnings (w/ booleans)'
@@ -139,7 +140,7 @@ test('hast-util-from-html', (t) => {
139
140
missingDoctype : false
140
141
} )
141
142
142
- t . deepEqual (
143
+ assert . deepEqual (
143
144
JSON . parse ( JSON . stringify ( args ) ) ,
144
145
[
145
146
{
@@ -170,7 +171,7 @@ test('hast-util-from-html', (t) => {
170
171
missingDoctype : false
171
172
} )
172
173
173
- t . deepEqual (
174
+ assert . deepEqual (
174
175
JSON . parse ( JSON . stringify ( args ) ) ,
175
176
[
176
177
{
@@ -201,7 +202,7 @@ test('hast-util-from-html', (t) => {
201
202
missingDoctype : false
202
203
} )
203
204
204
- t . deepEqual (
205
+ assert . deepEqual (
205
206
JSON . parse ( JSON . stringify ( args ) ) ,
206
207
[
207
208
{
@@ -232,7 +233,7 @@ test('hast-util-from-html', (t) => {
232
233
missingDoctype : false
233
234
} )
234
235
235
- t . deepEqual (
236
+ assert . deepEqual (
236
237
JSON . parse ( JSON . stringify ( args ) ) ,
237
238
[
238
239
{
@@ -262,7 +263,7 @@ test('hast-util-from-html', (t) => {
262
263
}
263
264
} )
264
265
265
- t . deepEqual (
266
+ assert . deepEqual (
266
267
JSON . parse ( JSON . stringify ( args ) ) ,
267
268
[
268
269
{
@@ -285,13 +286,11 @@ test('hast-util-from-html', (t) => {
285
286
] ,
286
287
'should support vfiles'
287
288
)
288
-
289
- t . end ( )
290
289
} )
291
290
292
291
// Related to https://github.com/inikulin/parse5/issues/255
293
292
// and https://github.com/inikulin/parse5/pull/257.
294
- test ( 'parse errors: coverage' , async ( t ) => {
293
+ test ( 'parse errors: coverage' , async ( ) => {
295
294
await fs . writeFile (
296
295
new URL ( 'error-codes-from-p5.js' , import . meta. url ) ,
297
296
'// @ts-nocheck\n/** @type {Record<string, string>} */\n' +
@@ -309,21 +308,17 @@ test('parse errors: coverage', async (t) => {
309
308
// @ts -ignore: this errors when tests did not run before build.
310
309
const { ERR : p5errors } = await import ( './error-codes-from-p5.js' )
311
310
312
- t . deepEqual (
311
+ assert . deepEqual (
313
312
Object . keys ( p5errors ) . sort ( ) ,
314
313
Object . keys ( rerrors ) . sort ( ) ,
315
314
'all codes from `parse5` should be covered by `hast-util-from-html`'
316
315
)
317
-
318
- t . end ( )
319
316
} )
320
317
321
318
test ( 'parse-errors: working' , async ( t ) => {
322
- let index = - 1
323
319
const root = new URL ( 'parse-error/' , import . meta. url )
324
- const fixtures = await fs . readdir ( root )
325
320
326
- t . test ( 'surrogate-in-input-stream' , ( t ) => {
321
+ await t . test ( 'surrogate-in-input-stream' , ( ) => {
327
322
const file = toVFile ( {
328
323
path : 'index.html' ,
329
324
value : '<!doctype html>\n' + String . fromCharCode ( 0xd8_00 )
@@ -338,7 +333,7 @@ test('parse-errors: working', async (t) => {
338
333
}
339
334
} )
340
335
341
- t . deepEqual (
336
+ assert . deepEqual (
342
337
JSON . parse ( JSON . stringify ( actual ) ) ,
343
338
[
344
339
{
@@ -361,26 +356,20 @@ test('parse-errors: working', async (t) => {
361
356
] ,
362
357
'should emit messages'
363
358
)
364
-
365
- t . end ( )
366
359
} )
367
360
368
361
/* Check the next fixture. */
369
- function next ( ) {
370
- const fixture = fixtures [ ++ index ]
362
+ let index = - 1
363
+ const fixtures = await fs . readdir ( root )
371
364
372
- if ( ! fixture ) {
373
- return
374
- }
365
+ while ( ++ index < fixtures . length ) {
366
+ const fixture = fixtures [ index ]
375
367
376
368
if ( fixture . charAt ( 0 ) === '.' ) {
377
- setImmediate ( next )
378
- return
369
+ continue
379
370
}
380
371
381
- setImmediate ( next ) // Queue next.
382
-
383
- t . test ( fixture , async ( t ) => {
372
+ await t . test ( fixture , async ( ) => {
384
373
const file = await read ( new URL ( fixture + '/index.html' , root ) , 'utf8' )
385
374
/** @type {Array<Error> } */
386
375
const messages = JSON . parse (
@@ -397,15 +386,11 @@ test('parse-errors: working', async (t) => {
397
386
}
398
387
} )
399
388
400
- t . deepEqual (
389
+ assert . deepEqual (
401
390
JSON . parse ( JSON . stringify ( actual ) ) ,
402
391
messages ,
403
392
'should emit messages for `' + fixture + '`'
404
393
)
405
-
406
- t . end ( )
407
394
} )
408
395
}
409
-
410
- next ( )
411
396
} )
0 commit comments