Skip to content

Commit 793e28f

Browse files
committed
Fix test case
1 parent 036f821 commit 793e28f

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

test/index.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
import assert from 'node:assert/strict'
1111
import {exec as execCallback} from 'node:child_process'
12-
import {createReadStream, promises as fs} from 'node:fs'
12+
import fs from 'node:fs/promises'
1313
import process from 'node:process'
14-
import {fileURLToPath} from 'node:url'
14+
import {PassThrough} from 'node:stream'
1515
import test from 'node:test'
16+
import {fileURLToPath} from 'node:url'
1617
import {promisify} from 'node:util'
1718
import {remark} from 'remark'
1819
import remarkValidateLinks from 'remark-validate-links'
@@ -244,21 +245,33 @@ test('remark-validate-links', async function (t) {
244245
].join(' ')
245246
)
246247

248+
const stream = new PassThrough()
249+
247250
if (promise.child.stdin) {
248-
createReadStream('github.md').pipe(promise.child.stdin)
251+
stream.pipe(promise.child.stdin)
249252
}
250253

254+
setTimeout(function () {
255+
stream.write('# exists\n')
256+
setTimeout(function () {
257+
stream.write('[ok](#exists) and [also ok](./examples/github.md).\n')
258+
259+
// eslint-disable-next-line max-nested-callbacks
260+
setTimeout(function () {
261+
stream.end('[nok](#not-exist) and [not ok](./examples/missing.md)\n')
262+
}, 4)
263+
}, 4)
264+
}, 4)
265+
251266
const result = await promise
252267

253268
assert.equal(
254269
strip(result.stderr),
255270
[
256271
'<stdin>',
257-
'5:37-5:51 warning Cannot find heading for `#world` missing-heading remark-validate-links:missing-heading',
258-
'11:31-11:58 warning Cannot find file `/Users/tilde/Projects/oss/remark-validate-links/examples/github.md` missing-file remark-validate-links:missing-file',
259-
'23:34-23:60 warning Cannot find file `/Users/tilde/Projects/oss/remark-validate-links/examples/world.md` missing-file remark-validate-links:missing-file',
272+
'3:1-3:18 warning Cannot find heading for `#not-exist` missing-heading remark-validate-links:missing-heading',
260273
'',
261-
'⚠ 3 warnings',
274+
'⚠ 1 warning',
262275
''
263276
].join('\n')
264277
)

0 commit comments

Comments
 (0)