Skip to content

Commit 183b34d

Browse files
committed
Use Node test runner
1 parent bd0e69d commit 183b34d

File tree

3 files changed

+91
-98
lines changed

3 files changed

+91
-98
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ jobs:
1717
strategy:
1818
matrix:
1919
node:
20-
- lts/fermium
20+
- lts/hydrogen
2121
- node

package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,16 @@
5050
"vfile-location": "^4.0.0"
5151
},
5252
"devDependencies": {
53-
"@types/tape": "^4.0.0",
53+
"@types/node": "^18.0.0",
5454
"c8": "^7.0.0",
55+
"hast-util-from-html": "^1.0.0",
5556
"is-hidden": "^2.0.0",
5657
"parse-dutch": "^6.0.0",
5758
"parse-english": "^6.0.0",
5859
"parse-latin": "^6.0.0",
5960
"prettier": "^2.0.0",
60-
"rehype": "^12.0.0",
6161
"remark-cli": "^11.0.0",
6262
"remark-preset-wooorm": "^9.0.0",
63-
"tape": "^5.0.0",
6463
"type-coverage": "^2.0.0",
6564
"typescript": "^4.0.0",
6665
"xo": "^0.53.0"
@@ -82,7 +81,15 @@
8281
"trailingComma": "none"
8382
},
8483
"xo": {
85-
"prettier": true
84+
"prettier": true,
85+
"overrides": [
86+
{
87+
"files": "test/**/*.js",
88+
"rules": {
89+
"no-await-in-loop": 0
90+
}
91+
}
92+
]
8693
},
8794
"remarkConfig": {
8895
"plugins": [

test/index.js

Lines changed: 79 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import fs from 'node:fs'
2-
import path from 'node:path'
3-
import test from 'tape'
4-
import {rehype} from 'rehype'
1+
import assert from 'node:assert/strict'
2+
import fs from 'node:fs/promises'
3+
import test from 'node:test'
4+
import {isHidden} from 'is-hidden'
55
import {VFile} from 'vfile'
66
import {ParseLatin} from 'parse-latin'
77
import {ParseDutch} from 'parse-dutch'
88
import {ParseEnglish} from 'parse-english'
9-
import {isHidden} from 'is-hidden'
9+
import {fromHtml} from 'hast-util-from-html'
1010
import {toNlcst} from '../index.js'
1111

12-
test('hast-util-to-nlcst', (t) => {
13-
t.throws(
12+
test('toNlcst', () => {
13+
assert.throws(
1414
() => {
1515
// @ts-expect-error runtime.
1616
toNlcst()
@@ -19,7 +19,7 @@ test('hast-util-to-nlcst', (t) => {
1919
'should fail when not given a tree'
2020
)
2121

22-
t.throws(
22+
assert.throws(
2323
() => {
2424
// @ts-expect-error runtime.
2525
toNlcst({})
@@ -28,7 +28,7 @@ test('hast-util-to-nlcst', (t) => {
2828
'should fail when not given a tree (#2)'
2929
)
3030

31-
t.throws(
31+
assert.throws(
3232
() => {
3333
// @ts-expect-error runtime.
3434
toNlcst({type: 'foo'})
@@ -37,7 +37,7 @@ test('hast-util-to-nlcst', (t) => {
3737
'should fail when not given a file'
3838
)
3939

40-
t.throws(
40+
assert.throws(
4141
() => {
4242
// @ts-expect-error runtime.
4343
toNlcst({type: 'foo'})
@@ -46,7 +46,7 @@ test('hast-util-to-nlcst', (t) => {
4646
'should fail when not given a file (#2)'
4747
)
4848

49-
t.throws(
49+
assert.throws(
5050
() => {
5151
// @ts-expect-error runtime.
5252
toNlcst({type: 'text', value: 'foo'}, {foo: 'bar'})
@@ -55,7 +55,7 @@ test('hast-util-to-nlcst', (t) => {
5555
'should fail when not given a file (#3)'
5656
)
5757

58-
t.throws(
58+
assert.throws(
5959
() => {
6060
// @ts-expect-error runtime.
6161
toNlcst({type: 'text', value: 'foo'}, new VFile('foo'))
@@ -64,15 +64,15 @@ test('hast-util-to-nlcst', (t) => {
6464
'should fail without parser'
6565
)
6666

67-
t.throws(
67+
assert.throws(
6868
() => {
6969
toNlcst({type: 'text', value: 'foo'}, new VFile(), ParseLatin)
7070
},
7171
/hast-util-to-nlcst expected position on nodes/,
7272
'should fail when not given positional information'
7373
)
7474

75-
t.doesNotThrow(() => {
75+
assert.doesNotThrow(() => {
7676
toNlcst(
7777
{
7878
type: 'text',
@@ -87,7 +87,7 @@ test('hast-util-to-nlcst', (t) => {
8787
)
8888
}, 'should accept a parser constructor')
8989

90-
t.doesNotThrow(() => {
90+
assert.doesNotThrow(() => {
9191
toNlcst(
9292
{
9393
type: 'text',
@@ -102,7 +102,7 @@ test('hast-util-to-nlcst', (t) => {
102102
)
103103
}, 'should accept a parser instance')
104104

105-
t.throws(
105+
assert.throws(
106106
() => {
107107
toNlcst(
108108
{
@@ -118,97 +118,83 @@ test('hast-util-to-nlcst', (t) => {
118118
/hast-util-to-nlcst expected position on nodes/,
119119
'should fail when not given positional information (#2)'
120120
)
121+
})
121122

122-
t.test('should accept nodes without offsets', (t) => {
123-
const node = toNlcst(
124-
{
125-
type: 'text',
126-
value: 'foo',
127-
position: {
128-
start: {line: 1, column: 1},
129-
end: {line: 1, column: 4}
130-
}
131-
},
132-
new VFile('foo'),
133-
ParseLatin
134-
)
135-
136-
t.equal(
137-
node.position && node.position.start.offset,
138-
0,
139-
'should set starting offset'
140-
)
141-
t.equal(
142-
node.position && node.position.end.offset,
143-
3,
144-
'should set ending offset'
145-
)
146-
147-
t.end()
148-
})
149-
150-
t.test('should accept comments', (t) => {
151-
const node = toNlcst(
152-
{
153-
type: 'comment',
154-
value: 'a',
155-
position: {start: {line: 1, column: 1}, end: {line: 1, column: 9}}
156-
},
157-
new VFile('<!--a-->'),
158-
ParseLatin
159-
)
123+
await test('should accept nodes without offsets', () => {
124+
const node = toNlcst(
125+
{
126+
type: 'text',
127+
value: 'foo',
128+
position: {
129+
start: {line: 1, column: 1},
130+
end: {line: 1, column: 4}
131+
}
132+
},
133+
new VFile('foo'),
134+
ParseLatin
135+
)
160136

161-
t.deepEqual(
162-
node,
163-
{
164-
type: 'RootNode',
165-
children: [],
166-
position: {
167-
start: {line: 1, column: 1, offset: 0},
168-
end: {line: 1, column: 9, offset: 8}
169-
}
170-
},
171-
'should support comments'
172-
)
137+
assert.equal(
138+
node.position && node.position.start.offset,
139+
0,
140+
'should set starting offset'
141+
)
142+
assert.equal(
143+
node.position && node.position.end.offset,
144+
3,
145+
'should set ending offset'
146+
)
147+
})
173148

174-
t.end()
175-
})
149+
await test('should accept comments', () => {
150+
const node = toNlcst(
151+
{
152+
type: 'comment',
153+
value: 'a',
154+
position: {start: {line: 1, column: 1}, end: {line: 1, column: 9}}
155+
},
156+
new VFile('<!--a-->'),
157+
ParseLatin
158+
)
176159

177-
t.end()
160+
assert.deepEqual(
161+
node,
162+
{
163+
type: 'RootNode',
164+
children: [],
165+
position: {
166+
start: {line: 1, column: 1, offset: 0},
167+
end: {line: 1, column: 9, offset: 8}
168+
}
169+
},
170+
'should support comments'
171+
)
178172
})
179173

180-
test('Fixtures', (t) => {
181-
const root = path.join('test', 'fixtures')
182-
const files = fs.readdirSync(root)
174+
test('fixtures', async () => {
175+
const root = new URL('fixtures/', import.meta.url)
176+
const files = await fs.readdir(root)
183177
let index = -1
184-
/** @type {string} */
185-
let input
186-
/** @type {string} */
187-
let output
188-
/** @type {import('vfile').VFile} */
189-
let file
190-
/** @type {import('unist').Node} */
191-
let actual
192-
/** @type {import('unist').Node} */
193-
let expected
194178

195179
while (++index < files.length) {
196-
if (isHidden(files[index])) continue
180+
const folder = files[index]
197181

198-
input = path.join(root, files[index], 'input.html')
199-
output = path.join(root, files[index], 'output.json')
200-
file = new VFile(fs.readFileSync(input))
201-
actual = toNlcst(rehype().parse(file), file, ParseLatin)
182+
if (isHidden(folder)) continue
183+
184+
const input = new URL(folder + '/input.html', root)
185+
const output = new URL(folder + '/output.json', root)
186+
const file = new VFile(await fs.readFile(input))
187+
const actual = toNlcst(fromHtml(file), file, ParseLatin)
188+
/** @type {import('unist').Node} */
189+
let expected
202190

203191
try {
204-
expected = JSON.parse(String(fs.readFileSync(output)))
192+
expected = JSON.parse(String(await fs.readFile(output)))
205193
} catch {
206-
fs.writeFileSync(output, JSON.stringify(actual, null, 2) + '\n')
207-
return
194+
await fs.writeFile(output, JSON.stringify(actual, null, 2) + '\n')
195+
continue
208196
}
209197

210-
t.deepEqual(actual, expected, 'should work on `' + files[index] + '`')
198+
assert.deepEqual(actual, expected, 'should work on `' + files[index] + '`')
211199
}
212-
213-
t.end()
214200
})

0 commit comments

Comments
 (0)