Skip to content

Commit 8ca2ec0

Browse files
committed
Refactor code-style
1 parent 2cca65a commit 8ca2ec0

File tree

2 files changed

+69
-56
lines changed

2 files changed

+69
-56
lines changed

lib/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* @typedef Options
55
* Configuration (optional).
66
* @property {boolean | null | undefined} [includeImageAlt=true]
7-
* Whether to use `alt` for `image`s.
7+
* Whether to use `alt` for `image`s (default: `true`).
88
* @property {boolean | null | undefined} [includeHtml=true]
9-
* Whether to use `value` of HTML.
9+
* Whether to use `value` of HTML (default: `true`).
1010
*/
1111

1212
/** @type {Options} */
@@ -18,7 +18,7 @@ const emptyOptions = {}
1818
* Prefers the node’s plain-text fields, otherwise serializes its children,
1919
* and if the given value is an array, serialize the nodes in it.
2020
*
21-
* @param {unknown} value
21+
* @param {unknown} [value]
2222
* Thing to serialize, typically `Node`.
2323
* @param {Options | null | undefined} [options]
2424
* Configuration (optional).

test.js

+66-53
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,84 @@
11
import assert from 'node:assert/strict'
22
import test from 'node:test'
33
import {toString} from './index.js'
4-
import * as mod from './index.js'
54

6-
test('toString', () => {
7-
assert.deepEqual(
8-
Object.keys(mod).sort(),
9-
['toString'],
10-
'should expose the public api'
11-
)
5+
test('toString', async function (t) {
6+
await t.test('should expose the public api', async function () {
7+
assert.deepEqual(Object.keys(await import('./index.js')).sort(), [
8+
'toString'
9+
])
10+
})
1211

13-
// @ts-expect-error: runtime.
14-
assert.equal(toString(), '', 'should not fail on a missing node')
15-
assert.equal(toString(null), '', 'should not fail on `null` missing node')
12+
await t.test('should not fail on a missing node', async function () {
13+
assert.equal(toString(), '')
14+
})
1615

17-
assert.equal(
18-
toString({value: 'foo'}),
19-
'foo',
20-
'should not fail on nodes w/o type'
21-
)
16+
await t.test('should not fail on `null` missing node', async function () {
17+
assert.equal(toString(null), '')
18+
})
2219

23-
assert.equal(
24-
toString({
25-
value: 'foo',
26-
alt: 'bar',
27-
title: 'baz',
28-
children: [{value: 'qux'}]
29-
}),
30-
'foo',
31-
'should prefer `value` over all others'
32-
)
20+
await t.test('should not fail on nodes w/o type', async function () {
21+
assert.equal(toString({value: 'foo'}), 'foo')
22+
})
3323

34-
assert.equal(
35-
toString({alt: 'bar', title: 'baz', children: [{value: 'qux'}]}),
36-
'bar',
37-
'should prefer `alt` over all others'
38-
)
24+
await t.test('should prefer `value` over all others', async function () {
25+
assert.equal(
26+
toString({
27+
value: 'foo',
28+
alt: 'bar',
29+
title: 'baz',
30+
children: [{value: 'qux'}]
31+
}),
32+
'foo'
33+
)
34+
})
3935

40-
assert.equal(
41-
toString({title: 'baz', children: [{value: 'qux'}]}),
42-
'qux',
43-
'should *not* prefer `title` over all others'
44-
)
36+
await t.test('should prefer `alt` over all others', async function () {
37+
assert.equal(
38+
toString({alt: 'bar', title: 'baz', children: [{value: 'qux'}]}),
39+
'bar'
40+
)
41+
})
4542

46-
assert.equal(
47-
toString({alt: 'bar'}, {includeImageAlt: false}),
48-
'',
49-
'should *not* include `alt` w/ `includeImageAlt: false`'
43+
await t.test(
44+
'should *not* prefer `title` over all others',
45+
async function () {
46+
assert.equal(toString({title: 'baz', children: [{value: 'qux'}]}), 'qux')
47+
}
5048
)
5149

52-
assert.equal(
53-
toString({type: 'html', value: 'a'}, {includeHtml: false}),
54-
'',
55-
'should *not* include `html` w/ `includeHtml: false`'
50+
await t.test(
51+
'should *not* include `alt` w/ `includeImageAlt: false`',
52+
async function () {
53+
assert.equal(toString({alt: 'bar'}, {includeImageAlt: false}), '')
54+
}
5655
)
5756

58-
assert.equal(
59-
toString({children: [{value: 'foo'}, {alt: 'bar'}, {title: 'baz'}]}),
60-
'foobar',
61-
'should serialize children'
57+
await t.test(
58+
'should *not* include `html` w/ `includeHtml: false`',
59+
async function () {
60+
assert.equal(
61+
toString({type: 'html', value: 'a'}, {includeHtml: false}),
62+
''
63+
)
64+
}
6265
)
6366

64-
assert.equal(
65-
toString([{value: 'foo'}, {alt: 'bar'}, {title: 'baz'}]),
66-
'foobar',
67-
'should serialize a list of nodes'
68-
)
67+
await t.test('should serialize children', async function () {
68+
assert.equal(
69+
toString({children: [{value: 'foo'}, {alt: 'bar'}, {title: 'baz'}]}),
70+
'foobar'
71+
)
72+
})
73+
74+
await t.test('should serialize a list of nodes', async function () {
75+
assert.equal(
76+
toString([{value: 'foo'}, {alt: 'bar'}, {title: 'baz'}]),
77+
'foobar'
78+
)
79+
})
6980

70-
assert.equal(toString({}), '', 'should produce an empty string otherwise')
81+
await t.test('should produce an empty string otherwise', async function () {
82+
assert.equal(toString({}), '')
83+
})
7184
})

0 commit comments

Comments
 (0)