Skip to content

Commit 6e72107

Browse files
committed
Refactor tests
1 parent cf1d4a1 commit 6e72107

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,19 @@
7979
"prettier": true,
8080
"rules": {
8181
"unicorn/prefer-code-point": "off"
82-
}
82+
},
83+
"overrides": [
84+
{
85+
"files": "test/**/*.js",
86+
"rules": {
87+
"no-await-in-loop": "off"
88+
}
89+
}
90+
]
8391
},
8492
"remarkConfig": {
8593
"plugins": [
86-
"preset-wooorm"
94+
"remark-preset-wooorm"
8795
]
8896
},
8997
"typeCoverage": {

test/index.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import assert from 'node:assert/strict'
2-
import fs from 'node:fs'
3-
import path from 'node:path'
2+
import fs from 'node:fs/promises'
43
import test from 'tape'
54
import {toHtml} from 'hast-util-to-html'
65
import {toHast} from 'mdast-util-to-hast'
@@ -171,7 +170,7 @@ test('markdown -> mdast', (t) => {
171170
t.end()
172171
})
173172

174-
test('mdast -> markdown', (t) => {
173+
test('mdast -> markdown', async (t) => {
175174
t.deepEqual(
176175
toMarkdown(
177176
{
@@ -386,14 +385,25 @@ test('mdast -> markdown', (t) => {
386385
'should not escape colons in image (resource) labels'
387386
)
388387

389-
const files = fs.readdirSync('test').filter((d) => path.extname(d) === '.md')
388+
const root = new URL('./', import.meta.url)
389+
390+
const files = await fs.readdir(root)
390391
let index = -1
391392

392393
while (++index < files.length) {
393-
const d = files[index]
394-
const stem = path.basename(d, '.md')
394+
const file = files[index]
395+
396+
if (!/\.md$/.test(file)) continue
397+
398+
const stem = file.split('.').slice(0, -1).join('.')
399+
const inputUrl = new URL(file, root)
400+
const expectedUrl = new URL(stem + '.html', root)
401+
402+
const input = await fs.readFile(inputUrl)
403+
const expected = String(await fs.readFile(expectedUrl))
404+
395405
const hast = toHast(
396-
fromMarkdown(fs.readFileSync(path.join('test', d)), {
406+
fromMarkdown(input, {
397407
extensions: [gfmAutolinkLiteral],
398408
mdastExtensions: [gfmAutolinkLiteralFromMarkdown]
399409
}),
@@ -404,7 +414,6 @@ test('mdast -> markdown', (t) => {
404414
allowDangerousHtml: true,
405415
entities: {useNamedReferences: true}
406416
})
407-
const expected = String(fs.readFileSync(path.join('test', stem + '.html')))
408417

409418
if (actual.charCodeAt(actual.length - 1) !== 10) {
410419
actual += '\n'

0 commit comments

Comments
 (0)