Skip to content

Commit

Permalink
Fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 1, 2024
1 parent 036f821 commit 793e28f
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

import assert from 'node:assert/strict'
import {exec as execCallback} from 'node:child_process'
import {createReadStream, promises as fs} from 'node:fs'
import fs from 'node:fs/promises'
import process from 'node:process'
import {fileURLToPath} from 'node:url'
import {PassThrough} from 'node:stream'
import test from 'node:test'
import {fileURLToPath} from 'node:url'
import {promisify} from 'node:util'
import {remark} from 'remark'
import remarkValidateLinks from 'remark-validate-links'
Expand Down Expand Up @@ -244,21 +245,33 @@ test('remark-validate-links', async function (t) {
].join(' ')
)

const stream = new PassThrough()

if (promise.child.stdin) {
createReadStream('github.md').pipe(promise.child.stdin)
stream.pipe(promise.child.stdin)
}

setTimeout(function () {
stream.write('# exists\n')
setTimeout(function () {
stream.write('[ok](#exists) and [also ok](./examples/github.md).\n')

// eslint-disable-next-line max-nested-callbacks
setTimeout(function () {
stream.end('[nok](#not-exist) and [not ok](./examples/missing.md)\n')
}, 4)
}, 4)
}, 4)

const result = await promise

assert.equal(
strip(result.stderr),
[
'<stdin>',
'5:37-5:51 warning Cannot find heading for `#world` missing-heading remark-validate-links:missing-heading',
'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',
'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',
'3:1-3:18 warning Cannot find heading for `#not-exist` missing-heading remark-validate-links:missing-heading',
'',
'⚠ 3 warnings',
'⚠ 1 warning',
''
].join('\n')
)
Expand Down

0 comments on commit 793e28f

Please sign in to comment.