|
9 | 9 |
|
10 | 10 | import assert from 'node:assert/strict' |
11 | 11 | import {exec as execCallback} from 'node:child_process' |
12 | | -import {createReadStream, promises as fs} from 'node:fs' |
| 12 | +import fs from 'node:fs/promises' |
13 | 13 | import process from 'node:process' |
14 | | -import {fileURLToPath} from 'node:url' |
| 14 | +import {PassThrough} from 'node:stream' |
15 | 15 | import test from 'node:test' |
| 16 | +import {fileURLToPath} from 'node:url' |
16 | 17 | import {promisify} from 'node:util' |
17 | 18 | import {remark} from 'remark' |
18 | 19 | import remarkValidateLinks from 'remark-validate-links' |
@@ -244,21 +245,33 @@ test('remark-validate-links', async function (t) { |
244 | 245 | ].join(' ') |
245 | 246 | ) |
246 | 247 |
|
| 248 | + const stream = new PassThrough() |
| 249 | + |
247 | 250 | if (promise.child.stdin) { |
248 | | - createReadStream('github.md').pipe(promise.child.stdin) |
| 251 | + stream.pipe(promise.child.stdin) |
249 | 252 | } |
250 | 253 |
|
| 254 | + setTimeout(function () { |
| 255 | + stream.write('# exists\n') |
| 256 | + setTimeout(function () { |
| 257 | + stream.write('[ok](#exists)\n') |
| 258 | + |
| 259 | + // eslint-disable-next-line max-nested-callbacks |
| 260 | + setTimeout(function () { |
| 261 | + stream.end('[nok](#not-exist)\n') |
| 262 | + }, 4) |
| 263 | + }, 4) |
| 264 | + }, 4) |
| 265 | + |
251 | 266 | const result = await promise |
252 | 267 |
|
253 | 268 | assert.equal( |
254 | 269 | strip(result.stderr), |
255 | 270 | [ |
256 | 271 | '<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', |
260 | 273 | '', |
261 | | - '⚠ 3 warnings', |
| 274 | + '⚠ 1 warning', |
262 | 275 | '' |
263 | 276 | ].join('\n') |
264 | 277 | ) |
|
0 commit comments