Skip to content

Commit 6f25c90

Browse files
committed
Make tests granular
1 parent a53033c commit 6f25c90

File tree

4 files changed

+94
-37
lines changed

4 files changed

+94
-37
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"scripts": {
8181
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage",
8282
"format": "remark . -qfo --ignore-pattern test/ && prettier . -w --loglevel warn && xo --fix",
83-
"test-api": "node --conditions development test/index.js",
83+
"test-api": "tape test/index.js test/other-branches.js",
8484
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
8585
"test": "npm run build && npm run format && npm run test-coverage"
8686
},

test/fixtures/other-branches.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/index.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,31 +1006,3 @@ test('remark-validate-links', async (t) => {
10061006

10071007
t.end()
10081008
})
1009-
1010-
test('links to other branches', async (t) => {
1011-
const {stderr} = await exec(
1012-
[
1013-
bin,
1014-
'--no-config',
1015-
'--no-ignore',
1016-
'--use',
1017-
'"../../index.js=repository:\\"wooorm/test#main\\""',
1018-
'--use',
1019-
'../sort.js',
1020-
'other-branches.md'
1021-
].join(' ')
1022-
)
1023-
t.deepEqual(
1024-
strip(stderr),
1025-
[
1026-
'other-branches.md',
1027-
' 5:3-5:100 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
1028-
' 7:3-7:96 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
1029-
' 7:3-7:96 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
1030-
'',
1031-
'⚠ 3 warnings',
1032-
''
1033-
].join('\n'),
1034-
'should ignore links to other branches'
1035-
)
1036-
})

test/other-branches.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import {remark} from 'remark'
2+
import test from 'tape'
3+
import {engine as engineCb} from 'unified-engine'
4+
import {promisify} from 'node:util'
5+
import {VFile} from 'vfile'
6+
import remarkValidateLinks from '../index.js'
7+
8+
const engine = promisify(engineCb)
9+
10+
// Should ignore links to other branches.
11+
const options = {repository: 'https://github.com/wooorm/test.git#main'}
12+
13+
test('same branch, working link', async (t) => {
14+
t.deepEqual(
15+
await process(
16+
'[](https://github.com/wooorm/test/blob/main/examples/github.md#hello)'
17+
),
18+
[],
19+
'nothing to report'
20+
)
21+
})
22+
23+
test('other branch, working link', async (t) => {
24+
t.deepEqual(
25+
await process(
26+
'[](https://github.com/wooorm/test/blob/foo-bar/examples/github.md#hello)'
27+
),
28+
[],
29+
'nothing to ignore'
30+
)
31+
})
32+
33+
test('same branch, no such heading', async (t) => {
34+
t.deepEqual(
35+
await process(
36+
'[](https://github.com/wooorm/test/blob/main/examples/github.md#world)'
37+
),
38+
[
39+
'input.md:1:1-1:70: Link to unknown heading in `examples/github.md`: `world`'
40+
],
41+
'should be reported'
42+
)
43+
})
44+
45+
test('other branch, no such heading', async (t) => {
46+
t.deepEqual(
47+
await process(
48+
'[](https://github.com/wooorm/test/blob/foo-bar/examples/github.md#world)'
49+
),
50+
[],
51+
'should be ignored'
52+
)
53+
})
54+
55+
test('same branch, no such file', async (t) => {
56+
t.deepEqual(
57+
await process(
58+
'[](https://github.com/wooorm/test/blob/main/examples/world.md#hello)'
59+
),
60+
[
61+
'input.md:1:1-1:69: Link to unknown file: `examples/world.md`',
62+
'input.md:1:1-1:69: Link to unknown heading in `examples/world.md`: `hello`'
63+
],
64+
'should be reported'
65+
)
66+
})
67+
68+
test('other branch, no such file', async (t) => {
69+
t.deepEqual(
70+
await process(
71+
'[](https://github.com/wooorm/test/blob/foo-bar/examples/world.md#hello)'
72+
),
73+
[],
74+
'should be ignored'
75+
)
76+
})
77+
78+
/**
79+
* Run the plugin on a markdown test case and return a list of stringified messages.
80+
* unified-engine is needed to cross-reference links between files, by creating a FileSet.
81+
*
82+
* @param {string} value
83+
*/
84+
async function process(value) {
85+
const file = new VFile({value, path: 'input.md'})
86+
await engine({
87+
processor: remark,
88+
files: [file],
89+
plugins: [[remarkValidateLinks, options]],
90+
silent: true
91+
})
92+
return file.messages.map((message) => String(message))
93+
}

0 commit comments

Comments
 (0)