import assert from 'node:assert' import fs from 'node:fs' import { pipeline, Writable } from 'node:stream' import { promisify } from 'node:util' import { NdjsonToMessageStream } from '@cucumber/message-streams' import type { Envelope } from '@cucumber/messages' import fg from 'fast-glob' import { convertWindowsPathToPattern } from 'fast-glob/out/utils/path.js' import { GherkinDocumentWalker } from '../src/index.js' const asyncPipeline = promisify(pipeline) describe('Walking with messages', () => { const currentDir = convertWindowsPathToPattern(import.meta.dirname) const localMessageFiles = fg.sync(`${currentDir}/messages/**/*.ndjson`) const tckMessageFiles = fg.sync( `${currentDir}/../node_modules/@cucumber/compatibility-kit/features/**/*.ndjson` ) const messageFiles = [].concat(localMessageFiles, tckMessageFiles) it('must have some messages for comparison', () => { assert.notEqual(messageFiles.length, 0) }) for (const messageFile of messageFiles) { it(`can walk through GherkinDocuments in ${messageFile}`, async () => { const messageStream = new NdjsonToMessageStream() await asyncPipeline( fs.createReadStream(messageFile, 'utf-8'), messageStream, new Writable({ objectMode: true, write(envelope: Envelope, _encoding: string, callback: (error?: Error | null) => void) { try { if (envelope.gherkinDocument) { const walker = new GherkinDocumentWalker() walker.walkGherkinDocument(envelope.gherkinDocument) } callback() } catch (error) { error.message += `\n${envelope.gherkinDocument.uri}\n` callback(error) } }, }) ) }).timeout(30000) } })