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 Jan 24, 2023
1 parent 8372200 commit 2fae894
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ jobs:
strategy:
matrix:
node:
- lts/fermium
- lts/gallium
- node
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@
"unist-util-is": "^5.0.0"
},
"devDependencies": {
"@types/tape": "^4.0.0",
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"mdast-util-from-markdown": "^1.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.53.0"
Expand Down
68 changes: 33 additions & 35 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* @typedef {import('unist').Node} Node
*/

import assert from 'node:assert'
import test from 'tape'
import assert from 'node:assert/strict'
import test from 'node:test'
import {fromMarkdown} from 'mdast-util-from-markdown'
import {findBefore} from './index.js'

test('`findBefore`', (t) => {
test('`findBefore`', () => {
const tree = fromMarkdown('Some *emphasis*, **importance**, and `code`.')

assert(tree.type === 'root')
Expand All @@ -18,7 +18,7 @@ test('`findBefore`', (t) => {
const next = paragraph.children[1]
assert(next.type === 'emphasis')

t.throws(
assert.throws(
() => {
// @ts-expect-error runtime
findBefore()
Expand All @@ -27,7 +27,7 @@ test('`findBefore`', (t) => {
'should fail without parent'
)

t.throws(
assert.throws(
() => {
// @ts-expect-error runtime
findBefore({type: 'foo'})
Expand All @@ -36,7 +36,7 @@ test('`findBefore`', (t) => {
'should fail without parent node'
)

t.throws(
assert.throws(
() => {
// @ts-expect-error runtime
findBefore({type: 'foo', children: []})
Expand All @@ -45,23 +45,23 @@ test('`findBefore`', (t) => {
'should fail without index (#1)'
)

t.throws(
assert.throws(
() => {
findBefore({type: 'foo', children: []}, -1)
},
/Expected positive finite number as index/,
'should fail without index (#2)'
)

t.throws(
assert.throws(
() => {
findBefore({type: 'foo', children: []}, {type: 'bar'})
},
/Expected child node or index/,
'should fail without index (#3)'
)

t.throws(
assert.throws(
() => {
// @ts-expect-error runtime
findBefore({type: 'foo', children: [{type: 'bar'}]}, 1, false)
Expand All @@ -70,7 +70,7 @@ test('`findBefore`', (t) => {
'should fail for invalid `test` (#1)'
)

t.throws(
assert.throws(
() => {
// @ts-expect-error runtime
findBefore({type: 'foo', children: [{type: 'bar'}]}, 1, true)
Expand All @@ -79,102 +79,100 @@ test('`findBefore`', (t) => {
'should fail for invalid `test` (#2)'
)

t.strictEqual(
assert.strictEqual(
findBefore(paragraph, paragraph.children[1]),
head,
'should return the preceding node when without `test` (#1)'
)
t.strictEqual(
assert.strictEqual(
findBefore(paragraph, 1),
head,
'should return the preceding node when without `test` (#2)'
)
t.strictEqual(
assert.strictEqual(
findBefore(paragraph, 0),
null,
'should return the preceding node when without `test` (#3)'
)

t.strictEqual(
assert.strictEqual(
findBefore(paragraph, 100, head),
head,
'should return `node` when given a `node` and existing (#1)'
)
t.strictEqual(
assert.strictEqual(
findBefore(paragraph, paragraph.children[1], head),
head,
'should return `node` when given a `node` and existing (#2)'
)
t.strictEqual(
assert.strictEqual(
findBefore(paragraph, 1, head),
head,
'should return `node` when given a `node` and existing (#3)'
)
t.strictEqual(
assert.strictEqual(
findBefore(paragraph, head, head),
null,
'should return `node` when given a `node` and existing (#4)'
)
t.strictEqual(
assert.strictEqual(
findBefore(paragraph, 0, head),
null,
'should return `node` when given a `node` and existing (#5)'
)
t.strictEqual(
assert.strictEqual(
findBefore(paragraph, 1, next),
null,
'should return `node` when given a `node` and existing (#6)'
)

t.strictEqual(
assert.strictEqual(
findBefore(paragraph, 100, 'strong'),
paragraph.children[3],
'should return a child when given a `type` and existing (#1)'
)
t.strictEqual(
assert.strictEqual(
findBefore(paragraph, 3, 'strong'),
null,
'should return a child when given a `type` and existing (#2)'
)
t.strictEqual(
assert.strictEqual(
findBefore(paragraph, paragraph.children[4], 'strong'),
paragraph.children[3],
'should return a child when given a `type` and existing (#3)'
)
t.strictEqual(
assert.strictEqual(
findBefore(paragraph, paragraph.children[3], 'strong'),
null,
'should return a child when given a `type` and existing (#4)'
)

t.strictEqual(
findBefore(paragraph, 100, test),
assert.strictEqual(
findBefore(paragraph, 100, check),
paragraph.children[3],
'should return a child when given a `test` and existing (#1)'
)
t.strictEqual(
findBefore(paragraph, 3, test),
assert.strictEqual(
findBefore(paragraph, 3, check),
null,
'should return a child when given a `test` and existing (#2)'
)
t.strictEqual(
findBefore(paragraph, paragraph.children[4], test),
assert.strictEqual(
findBefore(paragraph, paragraph.children[4], check),
paragraph.children[3],
'should return a child when given a `test` and existing (#3)'
)
t.strictEqual(
findBefore(paragraph, paragraph.children[3], test),
assert.strictEqual(
findBefore(paragraph, paragraph.children[3], check),
null,
'should return a child when given a `test` and existing (#4)'
)

/**
* @param {Node} _
* @param {number} n
* @param {number | null | undefined} n
*/
function test(_, n) {
function check(_, n) {
return n === 3
}

t.end()
})

0 comments on commit 2fae894

Please sign in to comment.