Skip to content

Commit 12d74f9

Browse files
committed
Use Node test runner
1 parent 72d8c67 commit 12d74f9

File tree

3 files changed

+63
-59
lines changed

3 files changed

+63
-59
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/gallium
2121
- node

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"vfile-message": "^3.0.0"
4646
},
4747
"devDependencies": {
48-
"@types/tape": "^4.0.0",
48+
"@types/node": "^18.0.0",
4949
"c8": "^7.0.0",
5050
"is-hidden": "^2.0.0",
5151
"prettier": "^2.0.0",
@@ -76,7 +76,15 @@
7676
"prettier": true,
7777
"rules": {
7878
"unicorn/prefer-code-point": "off"
79-
}
79+
},
80+
"overrides": [
81+
{
82+
"files": "test/**/*.js",
83+
"rules": {
84+
"no-await-in-loop": 0
85+
}
86+
}
87+
]
8088
},
8189
"remarkConfig": {
8290
"plugins": [

test/index.js

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
/**
2-
* @typedef {import('../lib/index.js').Node} Node
3-
*
4-
*
2+
* @typedef {import('xast').Root} Root
53
*/
64

7-
import fs from 'node:fs'
8-
import path from 'node:path'
9-
import test from 'tape'
5+
import assert from 'node:assert/strict'
6+
import fs from 'node:fs/promises'
7+
import process from 'node:process'
8+
import test from 'node:test'
109
import {isHidden} from 'is-hidden'
1110
import {fromXml} from '../index.js'
1211

13-
const join = path.join
14-
15-
test('xast-util-from-xml', (t) => {
16-
t.equal(typeof fromXml, 'function', 'should expose a function')
12+
test('fromXml', () => {
13+
assert.equal(typeof fromXml, 'function', 'should expose a function')
1714

1815
try {
1916
fromXml('<root unquoted=attribute>')
20-
t.fail('should fail (1)')
17+
assert.fail('should fail (1)')
2118
} catch (error) {
22-
t.equal(
19+
assert.equal(
2320
String(error),
2421
'1:17: Unquoted attribute value',
2522
'should throw messages'
@@ -28,9 +25,9 @@ test('xast-util-from-xml', (t) => {
2825

2926
try {
3027
fromXml('<!ENTITY>')
31-
t.fail('should fail (2)')
28+
assert.fail('should fail (2)')
3229
} catch (error) {
33-
t.deepLooseEqual(
30+
assert.equal(
3431
String(error),
3532
'1:10: Unexpected SGML declaration',
3633
'should throw for SGML directives'
@@ -39,9 +36,9 @@ test('xast-util-from-xml', (t) => {
3936

4037
try {
4138
fromXml('<root>&foo;</root>')
42-
t.fail('should fail (3)')
39+
assert.fail('should fail (3)')
4340
} catch (error) {
44-
t.deepLooseEqual(
41+
assert.equal(
4542
String(error),
4643
'1:12: Invalid character entity',
4744
'should throw for unknown entities (1)'
@@ -50,9 +47,9 @@ test('xast-util-from-xml', (t) => {
5047

5148
try {
5249
fromXml('<root>&copy;</root>')
53-
t.fail('should fail (4)')
50+
assert.fail('should fail (4)')
5451
} catch (error) {
55-
t.deepLooseEqual(
52+
assert.equal(
5653
String(error),
5754
'1:13: Invalid character entity',
5855
'should throw for unknown entities (2)'
@@ -61,182 +58,181 @@ test('xast-util-from-xml', (t) => {
6158

6259
try {
6360
fromXml('<root><a><b><c/></a></b></root>')
64-
t.fail('should fail (5)')
61+
assert.fail('should fail (5)')
6562
} catch (error) {
66-
t.deepLooseEqual(
63+
assert.equal(
6764
String(error),
6865
'1:21: Unexpected close tag',
6966
'should throw on invalid nesting'
7067
)
7168
}
7269

73-
t.throws(
70+
assert.throws(
7471
() => {
7572
fromXml('<!doctype>')
7673
},
7774
/1:11: Expected doctype name/,
7875
'should throw on missing doctype name'
7976
)
8077

81-
t.throws(
78+
assert.throws(
8279
() => {
8380
fromXml('<!doctype !>')
8481
},
8582
/1:13: Expected start of doctype name/,
8683
'should throw on invalid doctype name'
8784
)
8885

89-
t.throws(
86+
assert.throws(
9087
() => {
9188
fromXml('<!DOCTYPE name[<!ELEMENT greeting (#PCDATA)>]>')
9289
},
9390
/1:47: Unexpected internal subset/,
9491
'should throw on internal subset directly after doctype name'
9592
)
9693

97-
t.throws(
94+
assert.throws(
9895
() => {
9996
fromXml('<!DOCTYPE name [<!ELEMENT greeting (#PCDATA)>]>')
10097
},
10198
/1:48: Unexpected internal subset/,
10299
'should throw on internal subset after doctype name'
103100
)
104101

105-
t.throws(
102+
assert.throws(
106103
() => {
107104
fromXml('<!DOCTYPE name!>')
108105
},
109106
/1:17: Expected doctype name character, whitespace, or doctype end/,
110107
'should throw on invalid character directly after doctype'
111108
)
112109

113-
t.throws(
110+
assert.throws(
114111
() => {
115112
fromXml('<!DOCTYPE name !>')
116113
},
117114
/1:18: Expected external identifier \(`PUBLIC` or `SYSTEM`\), whitespace, or doctype end/,
118115
'should throw on invalid character after doctype'
119116
)
120117

121-
t.throws(
118+
assert.throws(
122119
() => {
123120
fromXml('<!DOCTYPE name PUB>')
124121
},
125122
/1:20: Expected external identifier \(`PUBLIC` or `SYSTEM`\)/,
126123
'should throw on invalid external identifier (1)'
127124
)
128125

129-
t.throws(
126+
assert.throws(
130127
() => {
131128
fromXml('<!DOCTYPE name SYSTEm>')
132129
},
133130
/1:23: Expected external identifier \(`PUBLIC` or `SYSTEM`\)/,
134131
'should throw on invalid external identifier (2)'
135132
)
136133

137-
t.throws(
134+
assert.throws(
138135
() => {
139136
fromXml('<!DOCTYPE name PUBLIC>')
140137
},
141138
/1:23: Expected whitespace after `PUBLIC`/,
142139
'should throw on missing whitespace after public identifier'
143140
)
144141

145-
t.throws(
142+
assert.throws(
146143
() => {
147144
fromXml('<!DOCTYPE name PUBLIC !>')
148145
},
149146
/1:25: Expected quote or apostrophe to start public literal/,
150147
'should throw on invalid character after public identifier'
151148
)
152149

153-
t.throws(
150+
assert.throws(
154151
() => {
155152
fromXml('<!DOCTYPE name PUBLIC "🤔">')
156153
},
157154
/1:28: Expected pubid character in public literal/,
158155
'should throw on invalid character in public identifier'
159156
)
160157

161-
t.throws(
158+
assert.throws(
162159
() => {
163160
fromXml('<!DOCTYPE name PUBLIC "literal"!>')
164161
},
165162
/1:34: Expected whitespace after public literal/,
166163
'should throw on invalid character after public literal'
167164
)
168165

169-
t.throws(
166+
assert.throws(
170167
() => {
171168
fromXml('<!DOCTYPE name SYSTEM>')
172169
},
173170
/1:23: Expected whitespace after `SYSTEM`/,
174171
'should throw on missing whitespace after system identifier'
175172
)
176173

177-
t.throws(
174+
assert.throws(
178175
() => {
179176
fromXml('<!DOCTYPE name SYSTEM !>')
180177
},
181178
/1:25: Expected quote or apostrophe to start system literal/,
182179
'should throw on invalid character after system identifier'
183180
)
184181

185-
t.throws(
182+
assert.throws(
186183
() => {
187184
fromXml('<!DOCTYPE name SYSTEM "asd>')
188185
},
189186
/1:28: Unexpected end/,
190187
'should throw on unended system literal'
191188
)
192189

193-
t.throws(
190+
assert.throws(
194191
() => {
195192
fromXml('<!DOCTYPE name SYSTEM "asd" [<!ELEMENT greeting (#PCDATA)>]>')
196193
},
197194
/1:61: Unexpected internal subset/,
198195
'should throw on internal subset after external id'
199196
)
200197

201-
t.throws(
198+
assert.throws(
202199
() => {
203200
fromXml('<!DOCTYPE name SYSTEM "asd" !>')
204201
},
205202
/1:31: Expected whitespace or end of doctype/,
206203
'should throw on unexpected character after external id'
207204
)
208-
209-
t.end()
210205
})
211206

212-
test('fixtures', (t) => {
213-
const base = join('test', 'fixtures')
214-
const files = fs.readdirSync(base)
207+
test('fixtures', async () => {
208+
const base = new URL('fixtures/', import.meta.url)
209+
const files = await fs.readdir(base)
215210
let index = -1
216211

217212
while (++index < files.length) {
218-
if (!isHidden(files[index])) {
219-
each(files[index])
220-
}
221-
}
213+
const folder = files[index]
222214

223-
t.end()
215+
if (isHidden(folder)) continue
224216

225-
function each(/** @type {string} */ fixture) {
226-
const input = fs.readFileSync(join(base, fixture, 'index.xml'))
227-
const fp = join(base, fixture, 'index.json')
217+
const inputUrl = new URL(folder + '/index.xml', base)
218+
const treeUrl = new URL(folder + '/index.json', base)
219+
const input = await fs.readFile(inputUrl)
228220
const actual = fromXml(input)
229-
/** @type {Node} */
221+
/** @type {Root} */
230222
let expected
231223

232224
try {
233-
expected = JSON.parse(String(fs.readFileSync(fp)))
225+
expected = JSON.parse(String(await fs.readFile(treeUrl)))
226+
227+
if ('UPDATE' in process.env) {
228+
throw new Error('Update')
229+
}
234230
} catch {
235-
// New fixture.
236-
fs.writeFileSync(fp, JSON.stringify(actual, null, 2) + '\n')
237-
return
231+
// New folder.
232+
await fs.writeFile(treeUrl, JSON.stringify(actual, null, 2) + '\n')
233+
continue
238234
}
239235

240-
t.deepEqual(actual, expected, fixture)
236+
assert.deepEqual(actual, expected, folder)
241237
}
242238
})

0 commit comments

Comments
 (0)