Skip to content

Commit 6e18e20

Browse files
committed
Use Node test runner
1 parent a98ca64 commit 6e18e20

File tree

4 files changed

+36
-40
lines changed

4 files changed

+36
-40
lines changed

.github/workflows/main.yml

+1-1
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

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export function definitions(tree) {
5050
/** @type {GetDefinition} */
5151
function definition(identifier) {
5252
const id = clean(identifier)
53+
// To do: next major: return `undefined` when not found.
5354
return id && own.call(cache, id) ? cache[id] : null
5455
}
5556
}

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@
4141
"unist-util-visit": "^4.0.0"
4242
},
4343
"devDependencies": {
44-
"@types/tape": "^4.0.0",
44+
"@types/node": "^18.0.0",
4545
"c8": "^7.0.0",
46+
"mdast-util-from-markdown": "^1.0.0",
4647
"prettier": "^2.0.0",
47-
"remark": "^14.0.0",
4848
"remark-cli": "^11.0.0",
4949
"remark-preset-wooorm": "^9.0.0",
50-
"tape": "^5.0.0",
5150
"type-coverage": "^2.0.0",
5251
"typescript": "^4.0.0",
5352
"xo": "^0.53.0"

test.js

+32-36
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
/**
2-
* @typedef {import('mdast').Root|import('mdast').Content} Node
3-
*/
4-
5-
import test from 'tape'
6-
import {remark} from 'remark'
1+
import assert from 'node:assert/strict'
2+
import test from 'node:test'
3+
import {fromMarkdown} from 'mdast-util-from-markdown'
74
import {definitions} from './index.js'
85

9-
test('mdast-util-definitions', (t) => {
10-
/** @type {Node} */
11-
let tree
12-
13-
t.throws(
6+
test('mdast-util-definitions', () => {
7+
assert.throws(
148
() => {
159
// @ts-expect-error runtime
1610
definitions()
@@ -19,12 +13,10 @@ test('mdast-util-definitions', (t) => {
1913
'should fail without node'
2014
)
2115

22-
tree = /** @type {Node} */ (
23-
remark().parse('[example]: https://example.com "Example"')
24-
)
25-
26-
t.deepLooseEqual(
27-
definitions(tree)('example'),
16+
assert.deepEqual(
17+
definitions(fromMarkdown('[example]: https://example.com "Example"'))(
18+
'example'
19+
),
2820
{
2921
type: 'definition',
3022
identifier: 'example',
@@ -39,14 +31,18 @@ test('mdast-util-definitions', (t) => {
3931
'should return a definition'
4032
)
4133

42-
t.equal(definitions(tree)('foo'), null, 'should return null when not found')
43-
44-
tree = /** @type {Node} */ (
45-
remark().parse('[__proto__]: https://proto.com "Proto"')
34+
assert.equal(
35+
definitions(fromMarkdown('[example]: https://example.com "Example"'))(
36+
'foo'
37+
),
38+
null,
39+
'should return null when not found'
4640
)
4741

48-
t.deepLooseEqual(
49-
definitions(tree)('__proto__'),
42+
assert.deepEqual(
43+
definitions(fromMarkdown('[__proto__]: https://proto.com "Proto"'))(
44+
'__proto__'
45+
),
5046
{
5147
type: 'definition',
5248
identifier: '__proto__',
@@ -64,32 +60,32 @@ test('mdast-util-definitions', (t) => {
6460
/* eslint-disable no-use-extend-native/no-use-extend-native */
6561
// @ts-expect-error: yes.
6662
// type-coverage:ignore-next-line
67-
t.equal({}.type, undefined, 'should not polute the prototype')
63+
assert.equal({}.type, undefined, 'should not polute the prototype')
6864
/* eslint-enable no-use-extend-native/no-use-extend-native */
6965

70-
t.deepEqual(
71-
definitions(tree)('toString'),
66+
assert.deepEqual(
67+
definitions(fromMarkdown('[__proto__]: https://proto.com "Proto"'))(
68+
'toString'
69+
),
7270
null,
7371
'should work on weird identifiers when not found'
7472
)
7573

76-
tree = /** @type {Node} */ (
77-
remark().parse('[example]: https://one.com\n[example]: https://two.com')
78-
)
79-
80-
const example = definitions(tree)('example')
74+
const example = definitions(
75+
fromMarkdown('[example]: https://one.com\n[example]: https://two.com')
76+
)('example')
8177

82-
t.deepEqual(
78+
assert.deepEqual(
8379
example && example.url,
8480
'https://one.com',
8581
'should prefer the first of duplicate definitions'
8682
)
8783

88-
t.deepEqual(
89-
definitions(tree)(''),
84+
assert.deepEqual(
85+
definitions(
86+
fromMarkdown('[example]: https://one.com\n[example]: https://two.com')
87+
)(''),
9088
null,
9189
'should not return something for a missing identifier'
9290
)
93-
94-
t.end()
9591
})

0 commit comments

Comments
 (0)