|
2 | 2 | * @typedef {import('../lib/index.js').HastNode} HastNode
|
3 | 3 | */
|
4 | 4 |
|
5 |
| -import fs from 'node:fs' |
6 |
| -import path from 'node:path' |
| 5 | +import fs from 'node:fs/promises' |
| 6 | +import process from 'node:process' |
7 | 7 | import test from 'tape'
|
8 |
| -import glob from 'glob' |
9 | 8 | import {JSDOM} from 'jsdom'
|
10 | 9 | import {webNamespaces} from 'web-namespaces'
|
11 | 10 | import {h, s} from 'hastscript'
|
12 | 11 | import serialize from 'w3c-xmlserializer'
|
13 | 12 | import {toDom} from '../index.js'
|
14 | 13 |
|
15 |
| -const window = new JSDOM().window |
16 |
| -const document = window.document |
| 14 | +const document = new JSDOM().window.document |
17 | 15 |
|
18 | 16 | globalThis.document = document
|
19 | 17 |
|
@@ -381,39 +379,39 @@ test('hast-util-to-dom', (t) => {
|
381 | 379 | t.end()
|
382 | 380 | })
|
383 | 381 |
|
384 |
| -test('fixtures', (t) => { |
385 |
| - const root = path.join('test', 'fixtures') |
386 |
| - const fixturePaths = glob.sync(path.join(root, '**/*/')) |
387 |
| - let index = -1 |
| 382 | +test('fixtures', async (t) => { |
| 383 | + const base = new URL('fixtures/', import.meta.url) |
| 384 | + const folders = await fs.readdir(base) |
388 | 385 |
|
389 |
| - while (++index < fixturePaths.length) { |
390 |
| - each(fixturePaths[index]) |
391 |
| - } |
392 |
| - |
393 |
| - t.end() |
| 386 | + for (const folder of folders) { |
| 387 | + if (folder.charAt(0) === '.') { |
| 388 | + continue |
| 389 | + } |
394 | 390 |
|
395 |
| - /** |
396 |
| - * @param {string} fixturePath |
397 |
| - */ |
398 |
| - function each(fixturePath) { |
399 |
| - const fixture = path.relative(root, fixturePath) |
400 |
| - const fixtureInput = path.join(fixturePath, 'index.json') |
401 |
| - const fixtureOutput = path.join(fixturePath, 'index.html') |
| 391 | + const treeUrl = new URL(folder + '/index.json', base) |
| 392 | + const fixtureUrl = new URL(folder + '/index.html', base) |
402 | 393 | /** @type {HastNode} */
|
403 |
| - const fixtureData = JSON.parse(String(fs.readFileSync(fixtureInput))) |
404 |
| - const parsedActual = serializeNodeToHtmlString(toDom(fixtureData)) |
| 394 | + const tree = JSON.parse(String(await fs.readFile(treeUrl))) |
| 395 | + const dom = toDom(tree) |
| 396 | + const actual = serializeNodeToHtmlString(dom) |
405 | 397 | /** @type {string} */
|
406 |
| - let parsedExpected |
| 398 | + let expected |
407 | 399 |
|
408 | 400 | try {
|
409 |
| - parsedExpected = fs.readFileSync(fixtureOutput).toString().trim() |
| 401 | + if ('UPDATE' in process.env) { |
| 402 | + throw new Error('Updating') |
| 403 | + } |
| 404 | + |
| 405 | + expected = String(await fs.readFile(fixtureUrl)).trim() |
410 | 406 | } catch {
|
411 |
| - fs.writeFileSync(fixtureOutput, parsedActual) |
412 |
| - return |
| 407 | + await fs.writeFile(fixtureUrl, actual + '\n') |
| 408 | + continue |
413 | 409 | }
|
414 | 410 |
|
415 |
| - t.equal(parsedActual, parsedExpected, fixture) |
| 411 | + t.equal(actual, expected, folder) |
416 | 412 | }
|
| 413 | + |
| 414 | + t.end() |
417 | 415 | })
|
418 | 416 |
|
419 | 417 | /**
|
|
0 commit comments