|
1 | 1 | import assert from 'node:assert/strict'
|
2 | 2 | import test from 'node:test'
|
3 | 3 | import {toString} from './index.js'
|
4 |
| -import * as mod from './index.js' |
5 | 4 |
|
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 | + }) |
12 | 11 |
|
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 | + }) |
16 | 15 |
|
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 | + }) |
22 | 19 |
|
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 | + }) |
33 | 23 |
|
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 | + }) |
39 | 35 |
|
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 | + }) |
45 | 42 |
|
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 | + } |
50 | 48 | )
|
51 | 49 |
|
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 | + } |
56 | 55 | )
|
57 | 56 |
|
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 | + } |
62 | 65 | )
|
63 | 66 |
|
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 | + }) |
69 | 80 |
|
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 | + }) |
71 | 84 | })
|
0 commit comments