Skip to content

Commit 1514cbd

Browse files
committed
Use Node test runner
1 parent 72e87df commit 1514cbd

File tree

3 files changed

+51
-75
lines changed

3 files changed

+51
-75
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ jobs:
77
name: ${{matrix.node}}
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v2
11-
- uses: dcodeIO/setup-node-nvm@master
10+
- uses: actions/checkout@v3
11+
- uses: actions/setup-node@v3
1212
with:
1313
node-version: ${{matrix.node}}
1414
- run: npm install
@@ -17,5 +17,5 @@ jobs:
1717
strategy:
1818
matrix:
1919
node:
20-
- lts/erbium
20+
- lts/hydrogen
2121
- node

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@
2727
"index.js"
2828
],
2929
"devDependencies": {
30-
"@types/tape": "^4.0.0",
30+
"@types/node": "^18.0.00",
3131
"c8": "^7.0.0",
3232
"cept": "^2.0.0",
3333
"prettier": "^2.0.0",
3434
"remark-cli": "^11.0.0",
3535
"remark-preset-wooorm": "^9.0.0",
36-
"tape": "^5.0.0",
3736
"type-coverage": "^2.0.0",
3837
"typescript": "^4.0.0",
3938
"xo": "^0.52.0"

test.js

Lines changed: 47 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,88 @@
1-
import test from 'tape'
1+
import assert from 'node:assert/strict'
2+
import test from 'node:test'
23
import {cept} from 'cept'
34
import {toJson} from './index.js'
45

5-
test('toJson', function (t) {
6-
t.equal(typeof toJson, 'function', 'should be a `function`')
7-
t.end()
6+
test('toJson', function () {
7+
assert.equal(typeof toJson, 'function', 'should be a `function`')
88
})
99

10-
test('Comments', function (t) {
11-
t.deepEqual(
10+
test('Comments', function () {
11+
assert.deepEqual(
1212
toJson(['% This is a completely commented line.', 'unicorn'].join('\n')),
1313
['unicorn'],
1414
'should strip line comments'
1515
)
1616

17-
t.deepEqual(
17+
assert.deepEqual(
1818
toJson('unicorn % This is a partially commented line.'),
1919
['unicorn'],
2020
'should strip partial line comments'
2121
)
2222

23-
t.deepEqual(
23+
assert.deepEqual(
2424
toJson('unicorn % This is a partially commented line.', {
2525
comment: false
2626
}),
2727
['unicorn % This is a partially commented line.'],
2828
'should honour `comment: false`'
2929
)
3030

31-
t.deepEqual(
31+
assert.deepEqual(
3232
toJson(['# This is a completely commented line.', 'unicorn'].join('\n'), {
3333
comment: '#'
3434
}),
3535
['unicorn'],
3636
'should strip line comments based on a given token'
3737
)
3838

39-
t.deepEqual(
39+
assert.deepEqual(
4040
toJson('unicorn # This is a partially commented line.', {
4141
comment: '#'
4242
}),
4343
['unicorn'],
4444
'should strip partial comments based on a given token'
4545
)
4646

47-
t.deepEqual(
47+
assert.deepEqual(
4848
toJson('unicorn # 1\n% 2\ndoge', {
4949
comment: ['#', '%']
5050
}),
5151
['doge', 'unicorn'],
5252
'should strip partial comments based on a given token'
5353
)
54-
55-
t.end()
5654
})
5755

58-
test('White space', function (t) {
59-
t.deepEqual(
56+
test('White space', function () {
57+
assert.deepEqual(
6058
toJson(' \tunicorn \t'),
6159
['unicorn'],
6260
'should trim prefixed and suffixed white space'
6361
)
64-
65-
t.end()
6662
})
6763

68-
test('Blank lines', function (t) {
69-
t.deepEqual(
64+
test('Blank lines', function () {
65+
assert.deepEqual(
7066
toJson('\n \t \ndoge\n\nunicorn\r\n'),
7167
['doge', 'unicorn'],
7268
'should remove empty / blank lines'
7369
)
74-
75-
t.end()
7670
})
7771

78-
test('EOF', function (t) {
79-
t.deepEqual(toJson('unicorn'), ['unicorn'], 'No EOL')
80-
t.deepEqual(toJson('unicorn\n'), ['unicorn'], 'LF')
81-
t.deepEqual(toJson('unicorn\r\n'), ['unicorn'], 'CR+LF')
82-
83-
t.end()
72+
test('EOF', function () {
73+
assert.deepEqual(toJson('unicorn'), ['unicorn'], 'No EOL')
74+
assert.deepEqual(toJson('unicorn\n'), ['unicorn'], 'LF')
75+
assert.deepEqual(toJson('unicorn\r\n'), ['unicorn'], 'CR+LF')
8476
})
8577

86-
test('Property-value pairs', function (t) {
87-
t.deepEqual(
78+
test('Property-value pairs', function () {
79+
assert.deepEqual(
8880
toJson('unicorn: magic creature'),
8981
{unicorn: 'magic creature'},
9082
'should support pair delimiters'
9183
)
9284

93-
t.deepEqual(
85+
assert.deepEqual(
9486
toJson(
9587
[
9688
'unicorn : magic creature',
@@ -106,55 +98,49 @@ test('Property-value pairs', function (t) {
10698
'white-space around pair delimiters'
10799
)
108100

109-
t.deepEqual(
101+
assert.deepEqual(
110102
toJson('unicorn\tmagic creature', {delimiter: '\t'}),
111103
{unicorn: 'magic creature'},
112104
'given delimiters'
113105
)
114-
115-
t.end()
116106
})
117107

118-
test('Values', function (t) {
119-
t.deepEqual(toJson('unicorn'), ['unicorn'], 'one value')
108+
test('Values', function () {
109+
assert.deepEqual(toJson('unicorn'), ['unicorn'], 'one value')
120110

121-
t.deepEqual(
111+
assert.deepEqual(
122112
toJson('unicorn \n doge\n\trainbow'),
123113
['doge', 'rainbow', 'unicorn'],
124114
'multiple values'
125115
)
126-
127-
t.end()
128116
})
129117

130-
test('Mixed values', function (t) {
131-
t.throws(
118+
test('Mixed values', function () {
119+
assert.throws(
132120
function () {
133121
toJson('unicorn\nrainbow: double')
134122
},
135123
/^Error: Error at `rainbow,double`/,
136124
'should throw when both property-value pairs and values are provided'
137125
)
138-
139-
t.end()
140126
})
141127

142-
test('Invalid lists', function (t) {
143-
t.throws(
128+
test('Invalid lists', async function (t) {
129+
assert.throws(
144130
function () {
145131
toJson('unicorn\nrainbow\nunicorn')
146132
},
147133
/^Error: Error at `unicorn`: Duplicate data found/,
148134
'should throw when duplicate values exist'
149135
)
150136

151-
t.deepEqual(
137+
assert.deepEqual(
152138
toJson('unicorn\nrainbow\nunicorn', {forgiving: true}),
153139
['rainbow', 'unicorn', 'unicorn'],
154140
'should honour forgiving'
155141
)
156142

157-
t.test('should log duplicate values when `forgiving`', function (st) {
143+
await t.test('should log duplicate values when `forgiving`', function () {
158144
const stop = cept(console, 'log', hoist)
159145
/** @type {Array<unknown>} */
160146
let parameters = []
@@ -163,15 +149,14 @@ test('Invalid lists', function (t) {
163149

164150
stop()
165151

166-
st.equal(parameters[0], 'Ignoring duplicate key for `unicorn`')
167-
st.end()
152+
assert.equal(parameters[0], 'Ignoring duplicate key for `unicorn`')
168153

169154
function hoist() {
170155
parameters = [...arguments]
171156
}
172157
})
173158

174-
t.test('should honour `log: false`', function (st) {
159+
await t.test('should honour `log: false`', function () {
175160
const stop = cept(console, 'log', hoist)
176161
/** @type {Array<unknown>|undefined} */
177162
let parameters
@@ -180,35 +165,32 @@ test('Invalid lists', function (t) {
180165

181166
stop()
182167

183-
st.equal(parameters, undefined)
184-
st.end()
168+
assert.equal(parameters, undefined)
185169

186170
function hoist() {
187171
parameters = [...arguments]
188172
}
189173
})
190-
191-
t.end()
192174
})
193175

194-
test('Invalid objects', function (t) {
195-
t.throws(
176+
test('Invalid objects', async function (t) {
177+
assert.throws(
196178
function () {
197179
toJson('doge: so scare\nunicorn: magic\ndoge: double')
198180
},
199181
/^Error: Error at `doge,double`: Duplicate data found/,
200182
'should throw when duplicate values exist'
201183
)
202184

203-
t.deepEqual(
185+
assert.deepEqual(
204186
toJson('doge: so scare\nunicorn: magic creature\ndoge: so scare\n', {
205187
forgiving: true
206188
}),
207189
{doge: 'so scare', unicorn: 'magic creature'},
208190
'should honour forgiving'
209191
)
210192

211-
t.test('should log duplicate values when `forgiving`', function (st) {
193+
await t.test('should log duplicate values when `forgiving`', function () {
212194
const stop = cept(console, 'log', hoist)
213195
/** @type {Array<unknown>} */
214196
let parameters = []
@@ -219,15 +201,14 @@ test('Invalid objects', function (t) {
219201

220202
stop()
221203

222-
st.equal(parameters[0], 'Ignoring duplicate key for `doge`')
223-
st.end()
204+
assert.equal(parameters[0], 'Ignoring duplicate key for `doge`')
224205

225206
function hoist() {
226207
parameters = [...arguments]
227208
}
228209
})
229210

230-
t.test('should honour `log: false`', function (st) {
211+
await t.test('should honour `log: false`', function () {
231212
const stop = cept(console, 'log', hoist)
232213
/** @type {Array<unknown>|undefined} */
233214
let parameters
@@ -239,33 +220,32 @@ test('Invalid objects', function (t) {
239220

240221
stop()
241222

242-
st.equal(parameters, undefined)
243-
st.end()
223+
assert.equal(parameters, undefined)
244224

245225
function hoist() {
246226
parameters = [...arguments]
247227
}
248228
})
249229

250-
t.deepEqual(
230+
assert.deepEqual(
251231
toJson('doge: so scare\nunicorn: magic creature\ndoge: so scare\n', {
252232
forgiving: 'fix'
253233
}),
254234
{doge: 'so scare', unicorn: 'magic creature'},
255235
"should honour `forgiving: 'fix'`"
256236
)
257237

258-
t.deepEqual(
238+
assert.deepEqual(
259239
toJson('doge: so scare\nunicorn: magic creature\ndoge: rainbows\n', {
260240
forgiving: 'fix'
261241
}),
262242
{doge: 'rainbows', unicorn: 'magic creature'},
263243
'duplicate keys with different values'
264244
)
265245

266-
t.test(
246+
await t.test(
267247
'should log for duplicate keys when `forgiving` is `"fix"',
268-
function (st) {
248+
function () {
269249
const stop = cept(console, 'log', hoist)
270250
/** @type {Array<unknown>} */
271251
let parameters = []
@@ -276,14 +256,11 @@ test('Invalid objects', function (t) {
276256

277257
stop()
278258

279-
st.equal(parameters[0], 'Ignoring duplicate key for `doge`')
280-
st.end()
259+
assert.equal(parameters[0], 'Ignoring duplicate key for `doge`')
281260

282261
function hoist() {
283262
parameters = [...arguments]
284263
}
285264
}
286265
)
287-
288-
t.end()
289266
})

0 commit comments

Comments
 (0)