Skip to content

Commit cb420bd

Browse files
committed
Replace paths with urls
1 parent 8b97813 commit cb420bd

File tree

2 files changed

+37
-31
lines changed

2 files changed

+37
-31
lines changed

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@
3838
"web-namespaces": "^2.0.0"
3939
},
4040
"devDependencies": {
41-
"@types/glob": "^8.0.0",
4241
"@types/jsdom": "^20.0.0",
4342
"@types/tape": "^4.0.0",
4443
"@types/w3c-xmlserializer": "^2.0.0",
4544
"c8": "^7.0.0",
46-
"glob": "^8.0.0",
4745
"hastscript": "^7.0.0",
4846
"jsdom": "^20.0.0",
4947
"prettier": "^2.0.0",
@@ -72,7 +70,17 @@
7270
"trailingComma": "none"
7371
},
7472
"xo": {
75-
"prettier": true
73+
"prettier": true,
74+
"overrides": [
75+
{
76+
"files": [
77+
"test/**/*.js"
78+
],
79+
"rules": {
80+
"no-await-in-loop": 0
81+
}
82+
}
83+
]
7684
},
7785
"remarkConfig": {
7886
"plugins": [

test/index.js

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
* @typedef {import('../lib/index.js').HastNode} HastNode
33
*/
44

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'
77
import test from 'tape'
8-
import glob from 'glob'
98
import {JSDOM} from 'jsdom'
109
import {webNamespaces} from 'web-namespaces'
1110
import {h, s} from 'hastscript'
1211
import serialize from 'w3c-xmlserializer'
1312
import {toDom} from '../index.js'
1413

15-
const window = new JSDOM().window
16-
const document = window.document
14+
const document = new JSDOM().window.document
1715

1816
globalThis.document = document
1917

@@ -381,39 +379,39 @@ test('hast-util-to-dom', (t) => {
381379
t.end()
382380
})
383381

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)
388385

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+
}
394390

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)
402393
/** @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)
405397
/** @type {string} */
406-
let parsedExpected
398+
let expected
407399

408400
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()
410406
} catch {
411-
fs.writeFileSync(fixtureOutput, parsedActual)
412-
return
407+
await fs.writeFile(fixtureUrl, actual + '\n')
408+
continue
413409
}
414410

415-
t.equal(parsedActual, parsedExpected, fixture)
411+
t.equal(actual, expected, folder)
416412
}
413+
414+
t.end()
417415
})
418416

419417
/**

0 commit comments

Comments
 (0)