3
3
* @typedef {import('unist').Parent } Parent
4
4
*/
5
5
6
- import test from 'tape'
6
+ import assert from 'node:assert/strict'
7
+ import test from 'node:test'
7
8
import { is } from '../index.js'
8
9
9
- test ( 'unist-util- is' , ( t ) => {
10
+ test ( 'is' , async ( t ) => {
10
11
const node = { type : 'strong' }
11
12
const parent = { type : 'paragraph' , children : [ ] }
12
13
13
- t . throws (
14
+ assert . throws (
14
15
( ) => {
15
16
// @ts -expect-error runtime.
16
17
is ( null , false )
@@ -19,23 +20,23 @@ test('unist-util-is', (t) => {
19
20
'should throw when `test` is invalid'
20
21
)
21
22
22
- t . throws (
23
+ assert . throws (
23
24
( ) => {
24
25
is ( node , null , - 1 , parent )
25
26
} ,
26
27
/ E x p e c t e d p o s i t i v e f i n i t e i n d e x / ,
27
28
'should throw when `index` is invalid (#1)'
28
29
)
29
30
30
- t . throws (
31
+ assert . throws (
31
32
( ) => {
32
33
is ( node , null , Number . POSITIVE_INFINITY , parent )
33
34
} ,
34
35
/ E x p e c t e d p o s i t i v e f i n i t e i n d e x / ,
35
36
'should throw when `index` is invalid (#2)'
36
37
)
37
38
38
- t . throws (
39
+ assert . throws (
39
40
( ) => {
40
41
// @ts -expect-error runtime.
41
42
is ( node , null , false , parent )
@@ -44,7 +45,7 @@ test('unist-util-is', (t) => {
44
45
'should throw when `index` is invalid (#3)'
45
46
)
46
47
47
- t . throws (
48
+ assert . throws (
48
49
( ) => {
49
50
// @ts -expect-error runtime.
50
51
is ( node , null , 0 , { } )
@@ -53,7 +54,7 @@ test('unist-util-is', (t) => {
53
54
'should throw when `parent` is invalid (#1)'
54
55
)
55
56
56
- t . throws (
57
+ assert . throws (
57
58
( ) => {
58
59
// @ts -expect-error runtime.
59
60
is ( node , null , 0 , { type : 'paragraph' } )
@@ -62,7 +63,7 @@ test('unist-util-is', (t) => {
62
63
'should throw when `parent` is invalid (#2)'
63
64
)
64
65
65
- t . throws (
66
+ assert . throws (
66
67
( ) => {
67
68
// @ts -expect-error: both `index` and `parent` are needed.
68
69
is ( node , null , 0 )
@@ -71,27 +72,31 @@ test('unist-util-is', (t) => {
71
72
'should throw `parent` xor `index` are given (#1)'
72
73
)
73
74
74
- t . throws (
75
+ assert . throws (
75
76
( ) => {
76
77
// @ts -expect-error: both `index` and `parent` are needed.
77
78
is ( node , null , null , parent )
78
79
} ,
79
80
/ E x p e c t e d b o t h p a r e n t a n d i n d e x / ,
80
81
'should throw `parent` xor `index` are given (#2)'
81
82
)
82
- t . notok ( is ( ) , 'should not fail without node' )
83
- t . ok ( is ( node ) , 'should check if given a node (#1)' )
84
- t . notok ( is ( { children : [ ] } , null ) , 'should check if given a node (#2)' )
83
+ assert . ok ( ! is ( ) , 'should not fail without node' )
84
+ assert . ok ( is ( node ) , 'should check if given a node (#1)' )
85
+ assert . ok ( ! is ( { children : [ ] } , null ) , 'should check if given a node (#2)' )
85
86
86
- t . ok ( is ( node , 'strong' ) , 'should match types (#1)' )
87
- t . notok ( is ( node , 'emphasis' ) , 'should match types (#2)' )
87
+ assert . ok ( is ( node , 'strong' ) , 'should match types (#1)' )
88
+ assert . ok ( ! is ( node , 'emphasis' ) , 'should match types (#2)' )
88
89
89
- t . ok ( is ( node , node ) , 'should match partially (#1)' )
90
- t . ok ( is ( node , { type : 'strong' } ) , 'should match partially (#2)' )
91
- t . ok ( is ( parent , { type : 'paragraph' } ) , 'should match partially (#3)' )
92
- t . notok ( is ( node , { type : 'paragraph' } ) , 'should match partially (#4)' )
90
+ assert . ok ( is ( node , node ) , 'should match partially (#1)' )
91
+ assert . ok ( is ( node , { type : 'strong' } ) , 'should match partially (#2)' )
92
+ assert . ok ( is ( parent , { type : 'paragraph' } ) , 'should match partially (#3)' )
93
+ assert . ok ( ! is ( node , { type : 'paragraph' } ) , 'should match partially (#4)' )
94
+
95
+ await t . test ( 'should accept a test' , ( ) => {
96
+ assert . ok ( ! is ( node , test ) )
97
+ assert . ok ( ! is ( node , test , 0 , parent ) )
98
+ assert . ok ( is ( node , test , 5 , parent ) )
93
99
94
- t . test ( 'should accept a test' , ( t ) => {
95
100
/**
96
101
* @param {unknown } _
97
102
* @param {number | null | undefined } n
@@ -100,18 +105,14 @@ test('unist-util-is', (t) => {
100
105
function test ( _ , n ) {
101
106
return n === 5
102
107
}
103
-
104
- t . notok ( is ( node , test ) )
105
- t . notok ( is ( node , test , 0 , parent ) )
106
- t . ok ( is ( node , test , 5 , parent ) )
107
-
108
- t . end ( )
109
108
} )
110
109
111
- t . test ( 'should call test' , ( t ) => {
110
+ await t . test ( 'should call test' , ( ) => {
112
111
const context = { foo : 'bar' }
112
+ let calls = 0
113
113
114
- t . plan ( 4 )
114
+ is ( node , test , 5 , parent , context )
115
+ assert . equal ( calls , 1 )
115
116
116
117
/**
117
118
* @this {context}
@@ -120,24 +121,23 @@ test('unist-util-is', (t) => {
120
121
* @param {Parent | null | undefined } c
121
122
*/
122
123
function test ( a , b , c ) {
123
- t . equal ( this , context )
124
- t . equal ( a , node )
125
- t . equal ( b , 5 )
126
- t . equal ( c , parent )
124
+ assert . equal ( this , context )
125
+ assert . equal ( a , node )
126
+ assert . equal ( b , 5 )
127
+ assert . equal ( c , parent )
128
+ calls ++
127
129
}
128
-
129
- is ( node , test , 5 , parent , context )
130
130
} )
131
131
132
- t . ok ( is ( node , [ 'strong' , 'emphasis' ] ) , 'should match arrays (#1)' )
133
- t . notok ( is ( node , [ 'b' , 'i' ] ) , 'should match arrays (#2)' )
132
+ assert . ok ( is ( node , [ 'strong' , 'emphasis' ] ) , 'should match arrays (#1)' )
133
+ assert . ok ( ! is ( node , [ 'b' , 'i' ] ) , 'should match arrays (#2)' )
134
134
135
- t . test ( 'should match arrays (#3)' , ( t ) => {
135
+ await t . test ( 'should match arrays (#3)' , ( ) => {
136
136
const context = { foo : 'bar' }
137
+ let calls = 0
137
138
138
- t . plan ( 5 )
139
-
140
- t . ok ( is ( node , [ test , 'strong' ] , 5 , parent , context ) )
139
+ assert . ok ( is ( node , [ test , 'strong' ] , 5 , parent , context ) )
140
+ assert . equal ( calls , 1 )
141
141
142
142
/**
143
143
* @this {context}
@@ -147,13 +147,12 @@ test('unist-util-is', (t) => {
147
147
* @returns {boolean }
148
148
*/
149
149
function test ( a , b , c ) {
150
- t . equal ( this , context )
151
- t . equal ( a , node )
152
- t . equal ( b , 5 )
153
- t . equal ( c , parent )
150
+ assert . equal ( this , context )
151
+ assert . equal ( a , node )
152
+ assert . equal ( b , 5 )
153
+ assert . equal ( c , parent )
154
+ calls ++
154
155
return false
155
156
}
156
157
} )
157
-
158
- t . end ( )
159
158
} )
0 commit comments