33 * @typedef {import('unist').Parent } Parent
44 */
55
6- import test from 'tape'
6+ import assert from 'node:assert/strict'
7+ import test from 'node:test'
78import { is } from '../index.js'
89
9- test ( 'unist-util- is' , ( t ) => {
10+ test ( 'is' , async ( t ) => {
1011 const node = { type : 'strong' }
1112 const parent = { type : 'paragraph' , children : [ ] }
1213
13- t . throws (
14+ assert . throws (
1415 ( ) => {
1516 // @ts -expect-error runtime.
1617 is ( null , false )
@@ -19,23 +20,23 @@ test('unist-util-is', (t) => {
1920 'should throw when `test` is invalid'
2021 )
2122
22- t . throws (
23+ assert . throws (
2324 ( ) => {
2425 is ( node , null , - 1 , parent )
2526 } ,
2627 / 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 / ,
2728 'should throw when `index` is invalid (#1)'
2829 )
2930
30- t . throws (
31+ assert . throws (
3132 ( ) => {
3233 is ( node , null , Number . POSITIVE_INFINITY , parent )
3334 } ,
3435 / 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 / ,
3536 'should throw when `index` is invalid (#2)'
3637 )
3738
38- t . throws (
39+ assert . throws (
3940 ( ) => {
4041 // @ts -expect-error runtime.
4142 is ( node , null , false , parent )
@@ -44,7 +45,7 @@ test('unist-util-is', (t) => {
4445 'should throw when `index` is invalid (#3)'
4546 )
4647
47- t . throws (
48+ assert . throws (
4849 ( ) => {
4950 // @ts -expect-error runtime.
5051 is ( node , null , 0 , { } )
@@ -53,7 +54,7 @@ test('unist-util-is', (t) => {
5354 'should throw when `parent` is invalid (#1)'
5455 )
5556
56- t . throws (
57+ assert . throws (
5758 ( ) => {
5859 // @ts -expect-error runtime.
5960 is ( node , null , 0 , { type : 'paragraph' } )
@@ -62,7 +63,7 @@ test('unist-util-is', (t) => {
6263 'should throw when `parent` is invalid (#2)'
6364 )
6465
65- t . throws (
66+ assert . throws (
6667 ( ) => {
6768 // @ts -expect-error: both `index` and `parent` are needed.
6869 is ( node , null , 0 )
@@ -71,27 +72,31 @@ test('unist-util-is', (t) => {
7172 'should throw `parent` xor `index` are given (#1)'
7273 )
7374
74- t . throws (
75+ assert . throws (
7576 ( ) => {
7677 // @ts -expect-error: both `index` and `parent` are needed.
7778 is ( node , null , null , parent )
7879 } ,
7980 / 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 / ,
8081 'should throw `parent` xor `index` are given (#2)'
8182 )
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)' )
8586
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)' )
8889
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 ) )
9399
94- t . test ( 'should accept a test' , ( t ) => {
95100 /**
96101 * @param {unknown } _
97102 * @param {number | null | undefined } n
@@ -100,18 +105,14 @@ test('unist-util-is', (t) => {
100105 function test ( _ , n ) {
101106 return n === 5
102107 }
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 ( )
109108 } )
110109
111- t . test ( 'should call test' , ( t ) => {
110+ await t . test ( 'should call test' , ( ) => {
112111 const context = { foo : 'bar' }
112+ let calls = 0
113113
114- t . plan ( 4 )
114+ is ( node , test , 5 , parent , context )
115+ assert . equal ( calls , 1 )
115116
116117 /**
117118 * @this {context}
@@ -120,24 +121,23 @@ test('unist-util-is', (t) => {
120121 * @param {Parent | null | undefined } c
121122 */
122123 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 ++
127129 }
128-
129- is ( node , test , 5 , parent , context )
130130 } )
131131
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)' )
134134
135- t . test ( 'should match arrays (#3)' , ( t ) => {
135+ await t . test ( 'should match arrays (#3)' , ( ) => {
136136 const context = { foo : 'bar' }
137+ let calls = 0
137138
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 )
141141
142142 /**
143143 * @this {context}
@@ -147,13 +147,12 @@ test('unist-util-is', (t) => {
147147 * @returns {boolean }
148148 */
149149 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 ++
154155 return false
155156 }
156157 } )
157-
158- t . end ( )
159158} )
0 commit comments