2
2
* @typedef {import('unist').Node } Node
3
3
*/
4
4
5
- import assert from 'node:assert'
6
- import test from 'tape '
5
+ import assert from 'node:assert/strict '
6
+ import test from 'node:test '
7
7
import { fromMarkdown } from 'mdast-util-from-markdown'
8
8
import { findBefore } from './index.js'
9
9
10
- test ( '`findBefore`' , ( t ) => {
10
+ test ( '`findBefore`' , ( ) => {
11
11
const tree = fromMarkdown ( 'Some *emphasis*, **importance**, and `code`.' )
12
12
13
13
assert ( tree . type === 'root' )
@@ -18,7 +18,7 @@ test('`findBefore`', (t) => {
18
18
const next = paragraph . children [ 1 ]
19
19
assert ( next . type === 'emphasis' )
20
20
21
- t . throws (
21
+ assert . throws (
22
22
( ) => {
23
23
// @ts -expect-error runtime
24
24
findBefore ( )
@@ -27,7 +27,7 @@ test('`findBefore`', (t) => {
27
27
'should fail without parent'
28
28
)
29
29
30
- t . throws (
30
+ assert . throws (
31
31
( ) => {
32
32
// @ts -expect-error runtime
33
33
findBefore ( { type : 'foo' } )
@@ -36,7 +36,7 @@ test('`findBefore`', (t) => {
36
36
'should fail without parent node'
37
37
)
38
38
39
- t . throws (
39
+ assert . throws (
40
40
( ) => {
41
41
// @ts -expect-error runtime
42
42
findBefore ( { type : 'foo' , children : [ ] } )
@@ -45,23 +45,23 @@ test('`findBefore`', (t) => {
45
45
'should fail without index (#1)'
46
46
)
47
47
48
- t . throws (
48
+ assert . throws (
49
49
( ) => {
50
50
findBefore ( { type : 'foo' , children : [ ] } , - 1 )
51
51
} ,
52
52
/ E x p e c t e d p o s i t i v e f i n i t e n u m b e r a s i n d e x / ,
53
53
'should fail without index (#2)'
54
54
)
55
55
56
- t . throws (
56
+ assert . throws (
57
57
( ) => {
58
58
findBefore ( { type : 'foo' , children : [ ] } , { type : 'bar' } )
59
59
} ,
60
60
/ E x p e c t e d c h i l d n o d e o r i n d e x / ,
61
61
'should fail without index (#3)'
62
62
)
63
63
64
- t . throws (
64
+ assert . throws (
65
65
( ) => {
66
66
// @ts -expect-error runtime
67
67
findBefore ( { type : 'foo' , children : [ { type : 'bar' } ] } , 1 , false )
@@ -70,7 +70,7 @@ test('`findBefore`', (t) => {
70
70
'should fail for invalid `test` (#1)'
71
71
)
72
72
73
- t . throws (
73
+ assert . throws (
74
74
( ) => {
75
75
// @ts -expect-error runtime
76
76
findBefore ( { type : 'foo' , children : [ { type : 'bar' } ] } , 1 , true )
@@ -79,102 +79,100 @@ test('`findBefore`', (t) => {
79
79
'should fail for invalid `test` (#2)'
80
80
)
81
81
82
- t . strictEqual (
82
+ assert . strictEqual (
83
83
findBefore ( paragraph , paragraph . children [ 1 ] ) ,
84
84
head ,
85
85
'should return the preceding node when without `test` (#1)'
86
86
)
87
- t . strictEqual (
87
+ assert . strictEqual (
88
88
findBefore ( paragraph , 1 ) ,
89
89
head ,
90
90
'should return the preceding node when without `test` (#2)'
91
91
)
92
- t . strictEqual (
92
+ assert . strictEqual (
93
93
findBefore ( paragraph , 0 ) ,
94
94
null ,
95
95
'should return the preceding node when without `test` (#3)'
96
96
)
97
97
98
- t . strictEqual (
98
+ assert . strictEqual (
99
99
findBefore ( paragraph , 100 , head ) ,
100
100
head ,
101
101
'should return `node` when given a `node` and existing (#1)'
102
102
)
103
- t . strictEqual (
103
+ assert . strictEqual (
104
104
findBefore ( paragraph , paragraph . children [ 1 ] , head ) ,
105
105
head ,
106
106
'should return `node` when given a `node` and existing (#2)'
107
107
)
108
- t . strictEqual (
108
+ assert . strictEqual (
109
109
findBefore ( paragraph , 1 , head ) ,
110
110
head ,
111
111
'should return `node` when given a `node` and existing (#3)'
112
112
)
113
- t . strictEqual (
113
+ assert . strictEqual (
114
114
findBefore ( paragraph , head , head ) ,
115
115
null ,
116
116
'should return `node` when given a `node` and existing (#4)'
117
117
)
118
- t . strictEqual (
118
+ assert . strictEqual (
119
119
findBefore ( paragraph , 0 , head ) ,
120
120
null ,
121
121
'should return `node` when given a `node` and existing (#5)'
122
122
)
123
- t . strictEqual (
123
+ assert . strictEqual (
124
124
findBefore ( paragraph , 1 , next ) ,
125
125
null ,
126
126
'should return `node` when given a `node` and existing (#6)'
127
127
)
128
128
129
- t . strictEqual (
129
+ assert . strictEqual (
130
130
findBefore ( paragraph , 100 , 'strong' ) ,
131
131
paragraph . children [ 3 ] ,
132
132
'should return a child when given a `type` and existing (#1)'
133
133
)
134
- t . strictEqual (
134
+ assert . strictEqual (
135
135
findBefore ( paragraph , 3 , 'strong' ) ,
136
136
null ,
137
137
'should return a child when given a `type` and existing (#2)'
138
138
)
139
- t . strictEqual (
139
+ assert . strictEqual (
140
140
findBefore ( paragraph , paragraph . children [ 4 ] , 'strong' ) ,
141
141
paragraph . children [ 3 ] ,
142
142
'should return a child when given a `type` and existing (#3)'
143
143
)
144
- t . strictEqual (
144
+ assert . strictEqual (
145
145
findBefore ( paragraph , paragraph . children [ 3 ] , 'strong' ) ,
146
146
null ,
147
147
'should return a child when given a `type` and existing (#4)'
148
148
)
149
149
150
- t . strictEqual (
151
- findBefore ( paragraph , 100 , test ) ,
150
+ assert . strictEqual (
151
+ findBefore ( paragraph , 100 , check ) ,
152
152
paragraph . children [ 3 ] ,
153
153
'should return a child when given a `test` and existing (#1)'
154
154
)
155
- t . strictEqual (
156
- findBefore ( paragraph , 3 , test ) ,
155
+ assert . strictEqual (
156
+ findBefore ( paragraph , 3 , check ) ,
157
157
null ,
158
158
'should return a child when given a `test` and existing (#2)'
159
159
)
160
- t . strictEqual (
161
- findBefore ( paragraph , paragraph . children [ 4 ] , test ) ,
160
+ assert . strictEqual (
161
+ findBefore ( paragraph , paragraph . children [ 4 ] , check ) ,
162
162
paragraph . children [ 3 ] ,
163
163
'should return a child when given a `test` and existing (#3)'
164
164
)
165
- t . strictEqual (
166
- findBefore ( paragraph , paragraph . children [ 3 ] , test ) ,
165
+ assert . strictEqual (
166
+ findBefore ( paragraph , paragraph . children [ 3 ] , check ) ,
167
167
null ,
168
168
'should return a child when given a `test` and existing (#4)'
169
169
)
170
170
171
171
/**
172
172
* @param {Node } _
173
- * @param {number } n
173
+ * @param {number | null | undefined } n
174
174
*/
175
- function test ( _ , n ) {
175
+ function check ( _ , n ) {
176
176
return n === 3
177
177
}
178
-
179
- t . end ( )
180
178
} )
0 commit comments