Skip to content

Commit 26dc4ad

Browse files
committed
Refactor code-style
1 parent c206cec commit 26dc4ad

File tree

2 files changed

+55
-67
lines changed

2 files changed

+55
-67
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function shiftHeading(tree, shift) {
3434
throw new Error('Expected a non-null finite integer, not `' + shift + '`')
3535
}
3636

37-
visit(tree, 'element', (node) => {
37+
visit(tree, 'element', function (node) {
3838
let rank = headingRank(node)
3939

4040
if (rank) {

test.js

Lines changed: 54 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,86 +2,74 @@ import assert from 'node:assert/strict'
22
import test from 'node:test'
33
import {h} from 'hastscript'
44
import {shiftHeading} from './index.js'
5-
import * as mod from './index.js'
65

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

14-
assert.throws(
15-
() => {
16-
// @ts-ignore runtime.
13+
await t.test('should throw when not given a number', async function () {
14+
assert.throws(function () {
15+
// @ts-ignore: check how a missing `shift` is handled.
1716
shiftHeading(h(''))
18-
},
19-
/^Error: Expected a non-null finite integer, not `undefined`$/,
20-
'should throw when not given a number'
21-
)
17+
}, /^Error: Expected a non-null finite integer, not `undefined`$/)
18+
})
2219

23-
assert.throws(
24-
() => {
20+
await t.test('should throw when given not a number', async function () {
21+
assert.throws(function () {
2522
shiftHeading(h(''), Number.NaN)
26-
},
27-
/^Error: Expected a non-null finite integer, not `NaN`$/,
28-
'should throw when given not a number'
29-
)
23+
}, /^Error: Expected a non-null finite integer, not `NaN`$/)
24+
})
3025

31-
assert.throws(
32-
() => {
26+
await t.test('should throw when not given an integer', async function () {
27+
assert.throws(function () {
3328
shiftHeading(h(''), 0.1)
34-
},
35-
/^Error: Expected a non-null finite integer, not `0.1`$/,
36-
'should throw when not given an integer'
37-
)
29+
}, /^Error: Expected a non-null finite integer, not `0.1`$/)
30+
})
3831

39-
assert.throws(
40-
() => {
41-
shiftHeading(h(''), Number.POSITIVE_INFINITY)
42-
},
43-
/^Error: Expected a non-null finite integer, not `Infinity`$/,
44-
'should throw when not given a finite number'
32+
await t.test(
33+
'should throw when not given a finite number',
34+
async function () {
35+
assert.throws(function () {
36+
shiftHeading(h(''), Number.POSITIVE_INFINITY)
37+
}, /^Error: Expected a non-null finite integer, not `Infinity`$/)
38+
}
4539
)
4640

47-
assert.throws(
48-
() => {
49-
shiftHeading(h(''), 0)
50-
},
51-
/^Error: Expected a non-null finite integer, not `0`$/,
52-
'should throw when not given a non-null number'
41+
await t.test(
42+
'should throw when not given a non-null number',
43+
async function () {
44+
assert.throws(function () {
45+
shiftHeading(h(''), 0)
46+
}, /^Error: Expected a non-null finite integer, not `0`$/)
47+
}
5348
)
5449

55-
assert.deepEqual(
56-
shiftHeading(h('h1', 'Alpha'), 1),
57-
h('h2', 'Alpha'),
58-
'should shift nodes upwards'
59-
)
50+
await t.test('should shift nodes upwards', async function () {
51+
assert.deepEqual(shiftHeading(h('h1', 'Alpha'), 1), h('h2', 'Alpha'))
52+
})
6053

61-
assert.deepEqual(
62-
shiftHeading(h('h2', 'Bravo'), -1),
63-
h('h1', 'Bravo'),
64-
'should shift nodes downwards'
65-
)
54+
await t.test('should shift nodes downwards', async function () {
55+
assert.deepEqual(shiftHeading(h('h2', 'Bravo'), -1), h('h1', 'Bravo'))
56+
})
6657

67-
assert.deepEqual(
68-
shiftHeading(h('h2', 'Charlie'), -2),
69-
h('h1', 'Charlie'),
70-
'should not shift upwards past h1'
71-
)
58+
await t.test('should not shift upwards past h1', async function () {
59+
assert.deepEqual(shiftHeading(h('h2', 'Charlie'), -2), h('h1', 'Charlie'))
60+
})
7261

73-
assert.deepEqual(
74-
shiftHeading(h('h5', 'Delta'), 2),
75-
h('h6', 'Delta'),
76-
'should not shift downwards past h6'
77-
)
62+
await t.test('should not shift downwards past h6', async function () {
63+
assert.deepEqual(shiftHeading(h('h5', 'Delta'), 2), h('h6', 'Delta'))
64+
})
7865

79-
assert.deepEqual(
80-
shiftHeading(
81-
h('main', [h('h1', 'Echo'), h('p', 'Foxtrot'), h('h5', 'Golf')]),
82-
2
83-
),
84-
h('main', [h('h3', 'Echo'), h('p', 'Foxtrot'), h('h6', 'Golf')]),
85-
'should change a tree'
86-
)
66+
await t.test('should change a tree', async function () {
67+
assert.deepEqual(
68+
shiftHeading(
69+
h('main', [h('h1', 'Echo'), h('p', 'Foxtrot'), h('h5', 'Golf')]),
70+
2
71+
),
72+
h('main', [h('h3', 'Echo'), h('p', 'Foxtrot'), h('h6', 'Golf')])
73+
)
74+
})
8775
})

0 commit comments

Comments
 (0)