Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Refactor to use node:test
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 22, 2023
1 parent 33376bf commit 4c2769e
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 84 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@
"unist-util-visit": "^4.0.0"
},
"devDependencies": {
"@types/tape": "^5.0.0",
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"prettier": "^3.0.0",
"remark": "^14.0.0",
"remark-cli": "^11.0.0",
"remark-html": "^15.0.0",
"remark-preset-wooorm": "^9.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"xo": "^0.56.0"
Expand Down
190 changes: 108 additions & 82 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,98 +1,124 @@
import test from 'tape'
import assert from 'node:assert/strict'
import test from 'node:test'
import {remark} from 'remark'
import remarkHtml from 'remark-html'
import remarkUnwrapImages from './index.js'

test('remarkUnwrapImages', (t) => {
t.equal(
remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('![hi](there.png)')
.toString(),
'<img src="there.png" alt="hi">\n',
'should unwrap images'
)
test('remarkUnwrapImages', async function (t) {
await t.test('should unwrap images', async function () {
assert.equal(
String(
await remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.process('![hi](there.png)')
),
'<img src="there.png" alt="hi">\n'
)
})

t.equal(
remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('![alpha](alpha.png) ![bravo](bravo.png)')
.toString(),
'<img src="alpha.png" alt="alpha">\n \n<img src="bravo.png" alt="bravo">\n',
'should unwrap multiple images'
)
await t.test('should unwrap multiple images', async function () {
assert.equal(
String(
await remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.process('![alpha](alpha.png) ![bravo](bravo.png)')
),
'<img src="alpha.png" alt="alpha">\n \n<img src="bravo.png" alt="bravo">\n'
)
})

t.equal(
remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('some text ![and](and.png) an image')
.toString(),
'<p>some text <img src="and.png" alt="and"> an image</p>\n',
'should not unwrap images next to other content'
await t.test(
'should not unwrap images next to other content',
async function () {
assert.equal(
String(
await remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.process('some text ![and](and.png) an image')
),
'<p>some text <img src="and.png" alt="and"> an image</p>\n'
)
}
)

t.equal(
remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('some text')
.toString(),
'<p>some text</p>\n',
'should not unwrap if there are no images'
)
await t.test('should not unwrap if there are no images', async function () {
assert.equal(
String(
await remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.process('some text')
),
'<p>some text</p>\n'
)
})

t.equal(
remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('[](#remark)')
.toString(),
'<p><a href="#remark"></a></p>\n',
'should not unwrap if there are no images in links'
await t.test(
'should not unwrap if there are no images in links',
async function () {
assert.equal(
String(
await remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.process('[](#remark)')
),
'<p><a href="#remark"></a></p>\n'
)
}
)

t.equal(
remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('[![hi](there.png)](#remark)')
.toString(),
'<a href="#remark"><img src="there.png" alt="hi"></a>\n',
'should supports links'
)
await t.test('should supports links', async function () {
assert.equal(
String(
await remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.process('[![hi](there.png)](#remark)')
),
'<a href="#remark"><img src="there.png" alt="hi"></a>\n'
)
})

t.equal(
remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('[![hi](there.png)](#remark)!')
.toString(),
'<p><a href="#remark"><img src="there.png" alt="hi"></a>!</p>\n',
'should not unwrap links next to other content'
await t.test(
'should not unwrap links next to other content',
async function () {
assert.equal(
String(
await remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.process('[![hi](there.png)](#remark)!')
),
'<p><a href="#remark"><img src="there.png" alt="hi"></a>!</p>\n'
)
}
)

t.equal(
remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('[![Hello](there.png), world](#remark)')
.toString(),
'<p><a href="#remark"><img src="there.png" alt="Hello">, world</a></p>\n',
'should not unwrap links with other content'
)

t.equal(
remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('![hi][image]\n\n[image]: kitten.png')
.toString(),
'<img src="kitten.png" alt="hi">\n',
'should supports image references'
)
await t.test('should not unwrap links with other content', async function () {
assert.equal(
String(
await remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.process('[![Hello](there.png), world](#remark)')
),
'<p><a href="#remark"><img src="there.png" alt="Hello">, world</a></p>\n'
)
})

t.end()
await t.test('should supports image references', async function () {
assert.equal(
String(
await remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.process('![hi][image]\n\n[image]: kitten.png')
),
'<img src="kitten.png" alt="hi">\n'
)
})
})

0 comments on commit 4c2769e

Please sign in to comment.