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'
7
4
import { definitions } from './index.js'
8
5
9
- test ( 'mdast-util-definitions' , ( t ) => {
10
- /** @type {Node } */
11
- let tree
12
-
13
- t . throws (
6
+ test ( 'mdast-util-definitions' , ( ) => {
7
+ assert . throws (
14
8
( ) => {
15
9
// @ts -expect-error runtime
16
10
definitions ( )
@@ -19,12 +13,10 @@ test('mdast-util-definitions', (t) => {
19
13
'should fail without node'
20
14
)
21
15
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
+ ) ,
28
20
{
29
21
type : 'definition' ,
30
22
identifier : 'example' ,
@@ -39,14 +31,18 @@ test('mdast-util-definitions', (t) => {
39
31
'should return a definition'
40
32
)
41
33
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'
46
40
)
47
41
48
- t . deepLooseEqual (
49
- definitions ( tree ) ( '__proto__' ) ,
42
+ assert . deepEqual (
43
+ definitions ( fromMarkdown ( '[__proto__]: https://proto.com "Proto"' ) ) (
44
+ '__proto__'
45
+ ) ,
50
46
{
51
47
type : 'definition' ,
52
48
identifier : '__proto__' ,
@@ -64,32 +60,32 @@ test('mdast-util-definitions', (t) => {
64
60
/* eslint-disable no-use-extend-native/no-use-extend-native */
65
61
// @ts -expect-error: yes.
66
62
// 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' )
68
64
/* eslint-enable no-use-extend-native/no-use-extend-native */
69
65
70
- t . deepEqual (
71
- definitions ( tree ) ( 'toString' ) ,
66
+ assert . deepEqual (
67
+ definitions ( fromMarkdown ( '[__proto__]: https://proto.com "Proto"' ) ) (
68
+ 'toString'
69
+ ) ,
72
70
null ,
73
71
'should work on weird identifiers when not found'
74
72
)
75
73
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' )
81
77
82
- t . deepEqual (
78
+ assert . deepEqual (
83
79
example && example . url ,
84
80
'https://one.com' ,
85
81
'should prefer the first of duplicate definitions'
86
82
)
87
83
88
- t . deepEqual (
89
- definitions ( tree ) ( '' ) ,
84
+ assert . deepEqual (
85
+ definitions (
86
+ fromMarkdown ( '[example]: https://one.com\n[example]: https://two.com' )
87
+ ) ( '' ) ,
90
88
null ,
91
89
'should not return something for a missing identifier'
92
90
)
93
-
94
- t . end ( )
95
91
} )
0 commit comments