Skip to content

Commit

Permalink
Refactor to use node:test
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 28, 2023
1 parent 7d770ea commit 555f625
Show file tree
Hide file tree
Showing 101 changed files with 3,417 additions and 3,009 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
"@types/hast": "^3.0.0",
"@types/html-minifier": "^4.0.0",
"@types/mdast": "^4.0.0",
"@types/node": "^20.0.0",
"@types/parse-author": "^2.0.0",
"@types/tape": "^5.0.0",
"bail": "^2.0.0",
"bytes": "^3.0.0",
"c8": "^8.0.0",
Expand Down Expand Up @@ -93,7 +93,6 @@
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"strip-indent": "^4.0.0",
"tape": "^5.0.0",
"to-vfile": "^8.0.0",
"trim-trailing-lines": "^2.0.0",
"trough": "^2.0.0",
Expand All @@ -116,7 +115,7 @@
"format": "remark . --frail --output --quiet && prettier . --log-level warn --write && xo --fix",
"prepack": "npm run build && npm run format",
"test": "npm run generate && npm run build && npm run format && npm run test-coverage",
"test-api": "node --conditions development test/index.js && npm run test --workspaces --if-present",
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --100 --check-coverage --reporter lcov npm run test-api"
},
"prettier": {
Expand Down
4 changes: 1 addition & 3 deletions packages/hast-util-from-string/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
"dependencies": {
"@types/hast": "^3.0.0"
},
"scripts": {
"test": "node --conditions development test.js"
},
"scripts": {},
"typeCoverage": {
"atLeast": 100,
"detail": true,
Expand Down
69 changes: 31 additions & 38 deletions packages/hast-util-from-string/test.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,40 @@
import test from 'tape'
import assert from 'node:assert/strict'
import test from 'node:test'
import {u} from 'unist-builder'
import {fromString} from './index.js'

test('hast-util-from-string', (t) => {
t.deepEqual(
// @ts-expect-error: `value` missing.
fromString(u('text'), 'foo'),
u('text', 'foo'),
'should set text nodes'
)
test('hast-util-from-string', async function (t) {
await t.test('should set text nodes', async function () {
assert.deepEqual(
// @ts-expect-error: `value` missing.
fromString(u('text'), 'foo'),
u('text', 'foo')
)
})

t.deepEqual(
// @ts-expect-error: `value` missing.
fromString(u('text')),
u('text', ''),
'should reset text nodes (1)'
)
await t.test('should reset text nodes (1)', async function () {
assert.deepEqual(
// @ts-expect-error: `value` missing.
fromString(u('text')),
u('text', '')
)
})

t.deepEqual(
fromString(u('text', 'foo')),
u('text', ''),
'should reset text nodes (2)'
)
await t.test('should reset text nodes (2)', async function () {
assert.deepEqual(fromString(u('text', 'foo')), u('text', ''))
})

t.deepEqual(
fromString(u('element', {tagName: 'p', properties: {}}, []), 'foo'),
u('element', {tagName: 'p', properties: {}}, [u('text', 'foo')]),
'should set parent nodes'
)

t.deepEqual(
fromString(u('element', {tagName: 'p', properties: {}}, [])),
u('element', {tagName: 'p', properties: {}}, []),
'should reset parent nodes (1)'
)

t.deepEqual(
fromString(
await t.test('should set parent nodes', async function () {
assert.deepEqual(
fromString(u('element', {tagName: 'p', properties: {}}, []), 'foo'),
u('element', {tagName: 'p', properties: {}}, [u('text', 'foo')])
),
u('element', {tagName: 'p', properties: {}}, []),
'should reset parent nodes (2)'
)
)
})

t.end()
await t.test('should reset parent nodes', async function () {
assert.deepEqual(
fromString(u('element', {tagName: 'p', properties: {}}, [])),
u('element', {tagName: 'p', properties: {}}, [])
)
})
})
4 changes: 1 addition & 3 deletions packages/hast-util-is-body-ok-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
"hast-util-has-property": "^3.0.0",
"hast-util-is-element": "^3.0.0"
},
"scripts": {
"test": "node --conditions development test.js"
},
"scripts": {},
"typeCoverage": {
"atLeast": 100,
"detail": true,
Expand Down
104 changes: 65 additions & 39 deletions packages/hast-util-is-body-ok-link/test.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,85 @@
import test from 'tape'
import assert from 'node:assert/strict'
import test from 'node:test'
import {u} from 'unist-builder'
import {h} from 'hastscript'
import {isBodyOkLink} from './index.js'

test('isBodyOkLink', (t) => {
t.equal(
isBodyOkLink(h('link', {itemProp: 'foo'})),
true,
'yes - for `link`s with `itemProp`'
)
test('isBodyOkLink', async function (t) {
await t.test('should be yes for `link`s with `itemProp`', async function () {
assert.equal(isBodyOkLink(h('link', {itemProp: 'foo'})), true)
})

t.equal(
isBodyOkLink(h('link', {rel: ['prefetch'], href: '//example.com'})),
true,
'yes - for `link`s with `rel[prefetch]`'
await t.test(
'should be yes for `link`s with `rel[prefetch]`',
async function () {
assert.equal(
isBodyOkLink(h('link', {rel: ['prefetch'], href: '//example.com'})),
true
)
}
)

t.equal(
isBodyOkLink(h('link', {rel: ['stylesheet'], href: 'index.css'})),
true,
'yes - for `link`s with `rel[stylesheet]`'
await t.test(
'should be yes for `link`s with `rel[stylesheet]`',
async function () {
assert.equal(
isBodyOkLink(h('link', {rel: ['stylesheet'], href: 'index.css'})),
true
)
}
)

t.equal(
isBodyOkLink(h('link', {rel: ['pingback'], href: '//example.com'})),
true,
'yes - for `link`s with `rel[pingback]`'
await t.test(
'should be yes for `link`s with `rel[pingback]`',
async function () {
assert.equal(
isBodyOkLink(h('link', {rel: ['pingback'], href: '//example.com'})),
true
)
}
)

t.equal(
isBodyOkLink(h('link', {rel: ['author'], href: 'index.css'})),
false,
'no - for `link`s with other rel’s'
)
await t.test('should be no for `link`s with other rel’s', async function () {
assert.equal(
isBodyOkLink(h('link', {rel: ['author'], href: 'index.css'})),
false
)
})

t.equal(
isBodyOkLink(h('link', {rel: ['stylesheet', 'author'], href: 'index.css'})),
false,
'no - for `link`s with combined rel’s'
await t.test(
'should be no for `link`s with combined rel’s',
async function () {
assert.equal(
isBodyOkLink(
h('link', {rel: ['stylesheet', 'author'], href: 'index.css'})
),
false
)
}
)

t.equal(
isBodyOkLink(h('link')),
false,
'no - for `link`s without `rel` or `itemProp`'
await t.test(
'should be no for `link`s without `rel` or `itemProp`',
async function () {
assert.equal(isBodyOkLink(h('link')), false)
}
)

t.equal(
isBodyOkLink(u('element', {tagName: 'link', properties: {}}, [])),
false,
'no - for `link`s without `rel` or `itemProp` (2)'
await t.test(
'should be no for `link`s without `rel` or `itemProp` (2)',
async function () {
assert.equal(
isBodyOkLink(u('element', {tagName: 'link', properties: {}}, [])),
false
)
}
)

t.equal(isBodyOkLink(h('p')), false, 'no - for non-links')
await t.test('should be no for non-links', async function () {
assert.equal(isBodyOkLink(h('p')), false)
})

t.equal(isBodyOkLink(u('text', 'foo')), false, 'no - for non-elements')
t.end()
await t.test('should be no for non-elements', async function () {
assert.equal(isBodyOkLink(u('text', 'foo')), false)
})
})
4 changes: 1 addition & 3 deletions packages/hast-util-is-conditional-comment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
"dependencies": {
"@types/hast": "^3.0.0"
},
"scripts": {
"test": "node --conditions development test.js"
},
"scripts": {},
"typeCoverage": {
"atLeast": 100,
"detail": true,
Expand Down
67 changes: 35 additions & 32 deletions packages/hast-util-is-conditional-comment/test.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
import test from 'tape'
import assert from 'node:assert/strict'
import test from 'node:test'
import {u} from 'unist-builder'
import {h} from 'hastscript'
import {isConditionalComment} from './index.js'

test('hast-util-is-conditional-comment', (t) => {
const fixtures = [
'[if IE]>…<![endif]',
'[if IE 6]>…<![endif]',
'[if IE 7]>…<![endif]',
'[if IE 8]>…<![endif]',
'[if IE 9]>…<![endif]',
'[if gte IE 8]>…<![endif]',
'[if lt IE 9]>…<![endif]',
'[if lte IE 7]>…<![endif]',
'[if gt IE 6]>…<![endif]',
'[if !IE]>',
'<![endif]'
]
let index = -1
test('hast-util-is-conditional-comment', async function (t) {
await t.test('should detect a bunch of comments', async function () {
const fixtures = [
'[if IE]>…<![endif]',
'[if IE 6]>…<![endif]',
'[if IE 7]>…<![endif]',
'[if IE 8]>…<![endif]',
'[if IE 9]>…<![endif]',
'[if gte IE 8]>…<![endif]',
'[if lt IE 9]>…<![endif]',
'[if lte IE 7]>…<![endif]',
'[if gt IE 6]>…<![endif]',
'[if !IE]>',
'<![endif]'
]
let index = -1

while (++index < fixtures.length) {
const d = fixtures[index]
t.equal(
isConditionalComment(u('comment', d)),
true,
'yes - <!--' + d + '-->'
while (++index < fixtures.length) {
assert.equal(isConditionalComment(u('comment', fixtures[index])), true)
}
})

await t.test('should be no for other comments', async function () {
assert.equal(
// @ts-expect-error: incorrect node.
isConditionalComment(u('comments', 'foo')),
false
)
}
})

t.equal(
// @ts-expect-error: incorrect node.
isConditionalComment(u('comments', 'foo')),
false,
'no - for other comments'
)
t.equal(isConditionalComment(h('div')), false, 'no - for elements')
t.equal(isConditionalComment(u('text', 'foo')), false, 'no - for texts')
await t.test('should be no for elements', async function () {
assert.equal(isConditionalComment(h('div')), false)
})

t.end()
await t.test('should be no for texts', async function () {
assert.equal(isConditionalComment(u('text', 'foo')), false)
})
})
4 changes: 1 addition & 3 deletions packages/hast-util-is-css-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
"dependencies": {
"@types/hast": "^3.0.0"
},
"scripts": {
"test": "node --conditions development test.js"
},
"scripts": {},
"typeCoverage": {
"atLeast": 100,
"detail": true,
Expand Down
Loading

0 comments on commit 555f625

Please sign in to comment.