Skip to content

Commit

Permalink
Use Node test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 14, 2022
1 parent 5680db9 commit ecebfef
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
name: ${{matrix.node}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dcodeIO/setup-node-nvm@master
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{matrix.node}}
- run: npm install
Expand All @@ -17,5 +17,5 @@ jobs:
strategy:
matrix:
node:
- lts/erbium
- lts/hydrogen
- node
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@
"index.js"
],
"devDependencies": {
"@types/tape": "^4.0.0",
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.52.0"
Expand Down
55 changes: 33 additions & 22 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,75 @@
import test from 'tape'
import assert from 'node:assert/strict'
import test from 'node:test'
import {parse, stringify} from './index.js'

test('comma-separated-tokens', function (t) {
t.test('.parse()', function (st) {
// @ts-ignore runtime.
st.deepEqual(parse(), [], 'should return an empty array for an empty value')
test('comma-separated-tokens', async function (t) {
await t.test('.parse()', function () {
assert.deepEqual(
// @ts-expect-error runtime.
parse(),
[],
'should return an empty array for an empty value'
)

st.deepEqual(
assert.deepEqual(
parse(','),
[''],
'should return one empty entry for a single comma'
)

st.deepEqual(
assert.deepEqual(
parse(',,'),
['', ''],
'should return two empty entry for a two comma’s'
)

st.deepEqual(parse(' a ,b,,d d '), ['a', 'b', '', 'd d'], 'should work')

st.end()
assert.deepEqual(parse(' a ,b,,d d '), ['a', 'b', '', 'd d'], 'should work')
})

t.test('.stringify()', function (st) {
st.deepEqual(
await t.test('.stringify()', function () {
assert.deepEqual(
stringify([]),
'',
'should return an empty string for an empty array'
)

st.deepEqual(
assert.deepEqual(
stringify(['']),
',',
'should return a single comma for an empty entry'
)

st.deepEqual(
assert.deepEqual(
stringify(['', '']),
', ,',
'should return two comma’s for two empty entries'
)

st.deepEqual(stringify(['', 'foo']), ', foo', 'should add an initial comma')
assert.deepEqual(
stringify(['', 'foo']),
', foo',
'should add an initial comma'
)

st.deepEqual(stringify(['foo', '']), 'foo, ,', 'should add a final comma')
assert.deepEqual(
stringify(['foo', '']),
'foo, ,',
'should add a final comma'
)

st.deepEqual(stringify(['a', 'b', '', 'd d']), 'a, b, , d d', 'should work')
assert.deepEqual(
stringify(['a', 'b', '', 'd d']),
'a, b, , d d',
'should work'
)

st.deepEqual(
assert.deepEqual(
stringify(['a', 'b', '', 'd d'], {
padRight: true,
padLeft: false
}),
'a ,b , ,d d',
'should accept padding'
)

st.end()
})

t.end()
})

0 comments on commit ecebfef

Please # to comment.