Skip to content

Commit 2e83190

Browse files
committed
Use Node test runner
1 parent 50db7b2 commit 2e83190

File tree

3 files changed

+55
-41
lines changed

3 files changed

+55
-41
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ jobs:
1717
strategy:
1818
matrix:
1919
node:
20-
- lts/fermium
20+
- lts/hydrogen
2121
- node

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@
4040
"hastscript": "^7.0.0"
4141
},
4242
"devDependencies": {
43-
"@types/tape": "^4.0.0",
43+
"@types/node": "^18.0.0",
4444
"c8": "^7.0.0",
4545
"prettier": "^2.0.0",
4646
"remark-cli": "^11.0.0",
4747
"remark-preset-wooorm": "^9.0.0",
48-
"tape": "^5.0.0",
4948
"type-coverage": "^2.0.0",
5049
"typescript": "^4.0.0",
5150
"unist-builder": "^3.0.0",

test.js

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,181 @@
1-
import test from 'tape'
1+
import assert from 'node:assert/strict'
2+
import test from 'node:test'
23
import {h, s} from 'hastscript'
34
import {fromSelector} from './index.js'
45

5-
test('fromSelector()', (t) => {
6-
t.throws(
6+
test('fromSelector()', () => {
7+
assert.throws(
78
() => {
89
fromSelector('@supports (transform-origin: 5% 5%) {}')
910
},
1011
/Error: Rule expected but "@" found/,
1112
'should throw w/ invalid selector'
1213
)
1314

14-
t.throws(
15+
assert.throws(
1516
() => {
1617
fromSelector('a, b')
1718
},
1819
/Error: Cannot handle selector list/,
1920
'should throw w/ multiple selector'
2021
)
2122

22-
t.throws(
23+
assert.throws(
2324
() => {
2425
fromSelector('a + b')
2526
},
2627
/Error: Cannot handle sibling combinator `\+` at root/,
2728
'should throw w/ next-sibling combinator at root'
2829
)
2930

30-
t.throws(
31+
assert.throws(
3132
() => {
3233
fromSelector('a ~ b')
3334
},
3435
/Error: Cannot handle sibling combinator `~` at root/,
3536
'should throw w/ subsequent-sibling combinator at root'
3637
)
3738

38-
t.throws(
39+
assert.throws(
3940
() => {
4041
fromSelector('[foo%=bar]')
4142
},
4243
/Error: Expected "=" but "%" found./,
4344
'should throw w/ attribute modifiers'
4445
)
4546

46-
t.throws(
47+
assert.throws(
4748
() => {
4849
fromSelector('[foo~=bar]')
4950
},
5051
/Error: Cannot handle attribute equality modifier `~=`/,
5152
'should throw w/ attribute modifiers'
5253
)
5354

54-
t.throws(
55+
assert.throws(
5556
() => {
5657
fromSelector(':active')
5758
},
5859
/Error: Cannot handle pseudo-selector `active`/,
5960
'should throw on pseudo classes'
6061
)
6162

62-
t.throws(
63+
assert.throws(
6364
() => {
6465
fromSelector(':nth-foo(2n+1)')
6566
},
6667
/Error: Cannot handle pseudo-selector `nth-foo`/,
6768
'should throw on pseudo class “functions”'
6869
)
6970

70-
t.throws(
71+
assert.throws(
7172
() => {
7273
fromSelector('::before')
7374
},
7475
/Error: Cannot handle pseudo-element or empty pseudo-class/,
7576
'should throw on invalid pseudo elements'
7677
)
7778

78-
t.deepEqual(fromSelector(), h(''), 'should support no selector')
79-
t.deepEqual(fromSelector(''), h(''), 'should support the empty string')
80-
t.deepEqual(fromSelector(' '), h(''), 'should support whitespace only')
81-
t.deepEqual(fromSelector('*'), h(''), 'should support the universal selector')
79+
assert.deepEqual(fromSelector(), h(''), 'should support no selector')
80+
assert.deepEqual(fromSelector(''), h(''), 'should support the empty string')
81+
assert.deepEqual(fromSelector(' '), h(''), 'should support whitespace only')
82+
assert.deepEqual(
83+
fromSelector('*'),
84+
h(''),
85+
'should support the universal selector'
86+
)
8287

83-
t.deepEqual(
88+
assert.deepEqual(
8489
fromSelector('p i s'),
8590
h('p', h('i', h('s'))),
8691
'should support the descendant combinator'
8792
)
8893

89-
t.deepEqual(
94+
assert.deepEqual(
9095
fromSelector('p > i > s'),
9196
h('p', h('i', h('s'))),
9297
'should support the child combinator'
9398
)
9499

95-
t.deepEqual(
100+
assert.deepEqual(
96101
fromSelector('p i + s'),
97102
h('p', [h('i'), h('s')]),
98103
'should support the next-sibling combinator'
99104
)
100105

101-
t.deepEqual(
106+
assert.deepEqual(
102107
fromSelector('p i ~ s'),
103108
h('p', [h('i'), h('s')]),
104109
'should support the subsequent-sibling combinator'
105110
)
106111

107-
t.deepEqual(fromSelector('a'), h('a'), 'should support a tag name')
108-
t.deepEqual(fromSelector('.a'), h('.a'), 'should support a class')
109-
t.deepEqual(fromSelector('a.b'), h('a.b'), 'should support a tag and a class')
110-
t.deepEqual(fromSelector('#b'), h('#b'), 'should support an id')
111-
t.deepEqual(fromSelector('a#b'), h('a#b'), 'should support a tag and an id')
112-
t.deepEqual(
112+
assert.deepEqual(fromSelector('a'), h('a'), 'should support a tag name')
113+
assert.deepEqual(fromSelector('.a'), h('.a'), 'should support a class')
114+
assert.deepEqual(
115+
fromSelector('a.b'),
116+
h('a.b'),
117+
'should support a tag and a class'
118+
)
119+
assert.deepEqual(fromSelector('#b'), h('#b'), 'should support an id')
120+
assert.deepEqual(
121+
fromSelector('a#b'),
122+
h('a#b'),
123+
'should support a tag and an id'
124+
)
125+
assert.deepEqual(
113126
fromSelector('a#b.c.d'),
114127
h('a#b.c.d'),
115128
'should support all together'
116129
)
117-
t.deepEqual(fromSelector('a#b#c'), h('a#c'), 'should use the last id')
118-
t.deepEqual(fromSelector('A').tagName, 'a', 'should normalize casing')
130+
assert.deepEqual(fromSelector('a#b#c'), h('a#c'), 'should use the last id')
131+
assert.deepEqual(fromSelector('A').tagName, 'a', 'should normalize casing')
119132

120-
t.deepEqual(
133+
assert.deepEqual(
121134
fromSelector('[a]'),
122135
h('', {a: true}),
123136
'should support attributes (#1)'
124137
)
125-
t.deepEqual(
138+
assert.deepEqual(
126139
fromSelector('[a=b]'),
127140
h('', {a: 'b'}),
128141
'should support attributes (#2)'
129142
)
130143

131-
t.deepEqual(
144+
assert.deepEqual(
132145
fromSelector('.a.b[class=c]'),
133146
h('.a.b.c'),
134147
'should support class and class attributes'
135148
)
136149

137-
t.deepEqual(fromSelector('altGlyph').tagName, 'altglyph', 'space (#1)')
150+
assert.deepEqual(fromSelector('altGlyph').tagName, 'altglyph', 'space (#1)')
138151

139-
t.deepEqual(fromSelector('altGlyph', 'svg').tagName, 'altGlyph', 'space (#2)')
152+
assert.deepEqual(
153+
fromSelector('altGlyph', 'svg').tagName,
154+
'altGlyph',
155+
'space (#2)'
156+
)
140157

141-
t.deepEqual(
158+
assert.deepEqual(
142159
fromSelector('altGlyph', {space: 'svg'}).tagName,
143160
'altGlyph',
144161
'space (#3)'
145162
)
146163

147-
t.deepEqual(
164+
assert.deepEqual(
148165
// @ts-expect-error: fine.
149166
fromSelector('svg altGlyph').children[0].tagName,
150167
'altGlyph',
151168
'space (#4)'
152169
)
153170

154-
t.deepEqual(
171+
assert.deepEqual(
155172
// @ts-expect-error: fine.
156173
fromSelector('div svg + altGlyph').children[1].tagName,
157174
'altglyph',
158175
'space (#5)'
159176
)
160177

161-
t.deepEqual(
178+
assert.deepEqual(
162179
fromSelector(
163180
'p svg[viewbox=0 0 10 10] circle[cx=10][cy=10][r=10] altGlyph'
164181
),
@@ -169,6 +186,4 @@ test('fromSelector()', (t) => {
169186
]),
170187
'space (#6)'
171188
)
172-
173-
t.end()
174189
})

0 commit comments

Comments
 (0)