Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cucumber/gherkin-streams

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cucumber/gherkin-streams - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

README.md

23

dist/package.json
{
"name": "@cucumber/gherkin-streams",
"version": "1.0.0",
"version": "2.0.0",
"description": "Streams for reading Gherkin parser output",

@@ -21,15 +21,14 @@ "main": "dist/src/index.js",

"dependencies": {
"@cucumber/messages": "^15.0.0",
"@cucumber/message-streams": "^1.0.0",
"@cucumber/gherkin": "^18.0.0",
"commander": "^7.2.0",
"protobufjs": "^6.10.2",
"source-map-support": "^0.5.19"
"@cucumber/messages": "16.0.0",
"@cucumber/message-streams": "1.0.0",
"@cucumber/gherkin": "19.0.0",
"commander": "7.2.0",
"source-map-support": "0.5.19"
},
"devDependencies": {
"@types/mocha": "^8.2.2",
"@types/node": "^14.14.35",
"mocha": "^8.3.2",
"nyc": "^15.1.0",
"typescript": "^4.2.3"
"@types/mocha": "8.2.2",
"@types/node": "15.3.0",
"mocha": "8.4.0",
"nyc": "15.1.0",
"typescript": "4.2.4"
},

@@ -36,0 +35,0 @@ "bugs": {

@@ -17,3 +17,2 @@ "use strict";

program.option('--predictable-ids', 'Use predictable ids', false);
program.option('-f, --format <format>', 'output format: ndjson|protobuf', 'protobuf');
program.parse(process.argv);

@@ -28,17 +27,3 @@ const paths = program.args;

};
const messageStream = paths.length === 0
? GherkinStreams_1.default.fromStream(process.stdin, options)
: GherkinStreams_1.default.fromPaths(paths, options);
let encodedStream;
switch (program.opts().format) {
case 'ndjson':
encodedStream = new message_streams_1.MessageToNdjsonStream();
break;
case 'protobuf':
encodedStream = new message_streams_1.MessageToBinaryStream();
break;
default:
throw new Error(`Unsupported format: ${program.opts().format}`);
}
messageStream.pipe(encodedStream).pipe(process.stdout);
GherkinStreams_1.default.fromPaths(paths, options).pipe(new message_streams_1.MessageToNdjsonStream()).pipe(process.stdout);
//# sourceMappingURL=main.js.map
/// <reference types="node" />
import { Readable } from 'stream';
import { messages } from '@cucumber/messages';
import ParserMessageStream from './ParserMessageStream';
import * as messages from '@cucumber/messages';
import { IGherkinOptions } from '@cucumber/gherkin';
declare function fromStream(stream: Readable, options: IGherkinOptions): ParserMessageStream;
declare function fromPaths(paths: ReadonlyArray<string>, options: IGherkinOptions): Readable;
declare function fromSources(envelopes: ReadonlyArray<messages.IEnvelope>, options: IGherkinOptions): Readable;
export interface IGherkinStreamOptions extends IGherkinOptions {
relativeTo?: string;
}
declare function fromPaths(paths: readonly string[], options: IGherkinStreamOptions): Readable;
declare function fromSources(envelopes: readonly messages.Envelope[], options: IGherkinOptions): Readable;
declare const _default: {
fromPaths: typeof fromPaths;
fromStream: typeof fromStream;
fromSources: typeof fromSources;

@@ -13,0 +13,0 @@ };

@@ -7,4 +7,2 @@ "use strict";

const stream_1 = require("stream");
const messages_1 = require("@cucumber/messages");
const message_streams_1 = require("@cucumber/message-streams");
const ParserMessageStream_1 = __importDefault(require("./ParserMessageStream"));

@@ -14,5 +12,2 @@ const SourceMessageStream_1 = __importDefault(require("./SourceMessageStream"));

const makeGherkinOptions_1 = __importDefault(require("./makeGherkinOptions"));
function fromStream(stream, options) {
return stream_1.pipeline(stream, new message_streams_1.BinaryToMessageStream(messages_1.messages.Envelope.decodeDelimited), new ParserMessageStream_1.default(options));
}
function fromPaths(paths, options) {

@@ -37,3 +32,3 @@ const pathsCopy = paths.slice();

.on('error', (err) => combinedMessageStream.emit('error', err))
.pipe(new SourceMessageStream_1.default(path))
.pipe(new SourceMessageStream_1.default(path, options.relativeTo))
.on('error', (err) => combinedMessageStream.emit('error', err))

@@ -71,5 +66,4 @@ .pipe(parserMessageStream)

fromPaths,
fromStream,
fromSources,
};
//# sourceMappingURL=GherkinStreams.js.map

@@ -1,3 +0,3 @@

import GherkinStreams from './GherkinStreams';
export { GherkinStreams };
import GherkinStreams, { IGherkinStreamOptions } from './GherkinStreams';
export { GherkinStreams, IGherkinStreamOptions };
//# sourceMappingURL=index.d.ts.map
/// <reference types="node" />
import { Transform, TransformCallback } from 'stream';
import { messages } from '@cucumber/messages';
import * as messages from '@cucumber/messages';
import { IGherkinOptions } from '@cucumber/gherkin';

@@ -11,4 +11,4 @@ /**

constructor(options: IGherkinOptions);
_transform(envelope: messages.IEnvelope, encoding: string, callback: TransformCallback): void;
_transform(envelope: messages.Envelope, encoding: string, callback: TransformCallback): void;
}
//# sourceMappingURL=ParserMessageStream.d.ts.map

@@ -15,3 +15,3 @@ "use strict";

if (envelope.source) {
const messageList = gherkin_1.generateMessages(envelope.source.data, envelope.source.uri, this.options);
const messageList = gherkin_1.generateMessages(envelope.source.data, envelope.source.uri, envelope.source.mediaType, this.options);
for (const message of messageList) {

@@ -25,3 +25,2 @@ this.push(message);

exports.default = ParserMessageStream;
module.exports = ParserMessageStream;
//# sourceMappingURL=ParserMessageStream.js.map

@@ -8,4 +8,5 @@ /// <reference types="node" />

private readonly uri;
private readonly relativeTo?;
private buffer;
constructor(uri: string);
constructor(uri: string, relativeTo?: string);
_transform(chunk: Buffer, encoding: string, callback: TransformCallback): void;

@@ -12,0 +13,0 @@ _flush(callback: TransformCallback): void;

@@ -5,2 +5,3 @@ "use strict";

const stream_1 = require("stream");
const path_1 = require("path");
/**

@@ -10,5 +11,6 @@ * Stream that reads a string and writes a single Source message.

class SourceMessageStream extends stream_1.Transform {
constructor(uri) {
constructor(uri, relativeTo) {
super({ readableObjectMode: true, writableObjectMode: false });
this.uri = uri;
this.relativeTo = relativeTo;
this.buffer = Buffer.alloc(0);

@@ -22,3 +24,3 @@ }

const data = this.buffer.toString('utf8');
const chunk = gherkin_1.makeSourceEnvelope(data, this.uri);
const chunk = gherkin_1.makeSourceEnvelope(data, this.relativeTo ? path_1.relative(this.relativeTo, this.uri) : this.uri);
this.push(chunk);

@@ -25,0 +27,0 @@ callback();

@@ -23,2 +23,5 @@ "use strict";

assert_1.default.strictEqual(envelopes.length, 3);
assert_1.default.strictEqual(envelopes[0].source.uri, 'testdata/good/minimal.feature');
assert_1.default.strictEqual(envelopes[1].gherkinDocument.uri, 'testdata/good/minimal.feature');
assert_1.default.strictEqual(envelopes[2].pickle.uri, 'testdata/good/minimal.feature');
}));

@@ -28,2 +31,9 @@ it('throws an error when the path is a directory', () => __awaiter(void 0, void 0, void 0, function* () {

}));
it('emits uris relative to a given path', () => __awaiter(void 0, void 0, void 0, function* () {
const envelopes = yield streamToArray(src_1.GherkinStreams.fromPaths(['testdata/good/minimal.feature'], Object.assign(Object.assign({}, defaultOptions), { relativeTo: 'testdata/good' })));
assert_1.default.strictEqual(envelopes.length, 3);
assert_1.default.strictEqual(envelopes[0].source.uri, 'minimal.feature');
assert_1.default.strictEqual(envelopes[1].gherkinDocument.uri, 'minimal.feature');
assert_1.default.strictEqual(envelopes[2].pickle.uri, 'minimal.feature');
}));
it('parses gherkin from STDIN', () => __awaiter(void 0, void 0, void 0, function* () {

@@ -30,0 +40,0 @@ const source = gherkin_1.makeSourceEnvelope(`Feature: Minimal

{
"name": "@cucumber/gherkin-streams",
"version": "1.0.0",
"version": "2.0.0",
"description": "Streams for reading Gherkin parser output",

@@ -21,15 +21,14 @@ "main": "dist/src/index.js",

"dependencies": {
"@cucumber/messages": "^15.0.0",
"@cucumber/message-streams": "^1.0.0",
"@cucumber/gherkin": "^18.0.0",
"commander": "^7.2.0",
"protobufjs": "^6.10.2",
"source-map-support": "^0.5.19"
"@cucumber/messages": "16.0.0",
"@cucumber/message-streams": "1.0.0",
"@cucumber/gherkin": "19.0.0",
"commander": "7.2.0",
"source-map-support": "0.5.19"
},
"devDependencies": {
"@types/mocha": "^8.2.2",
"@types/node": "^14.14.35",
"mocha": "^8.3.2",
"nyc": "^15.1.0",
"typescript": "^4.2.3"
"@types/mocha": "8.2.2",
"@types/node": "15.3.0",
"mocha": "8.4.0",
"nyc": "15.1.0",
"typescript": "4.2.4"
},

@@ -36,0 +35,0 @@ "bugs": {

@@ -5,4 +5,3 @@ import { Command } from 'commander'

import { IdGenerator } from '@cucumber/messages'
import { MessageToBinaryStream, MessageToNdjsonStream } from '@cucumber/message-streams'
import { Readable, Transform } from 'stream'
import { MessageToNdjsonStream } from '@cucumber/message-streams'
import { IGherkinOptions } from '@cucumber/gherkin'

@@ -16,3 +15,2 @@

program.option('--predictable-ids', 'Use predictable ids', false)
program.option('-f, --format <format>', 'output format: ndjson|protobuf', 'protobuf')
program.parse(process.argv)

@@ -29,19 +27,2 @@ const paths = program.args

const messageStream =
paths.length === 0
? GherkinStreams.fromStream((process.stdin as unknown) as Readable, options)
: GherkinStreams.fromPaths(paths, options)
let encodedStream: Transform
switch (program.opts().format) {
case 'ndjson':
encodedStream = new MessageToNdjsonStream()
break
case 'protobuf':
encodedStream = new MessageToBinaryStream()
break
default:
throw new Error(`Unsupported format: ${program.opts().format}`)
}
messageStream.pipe(encodedStream).pipe(process.stdout)
GherkinStreams.fromPaths(paths, options).pipe(new MessageToNdjsonStream()).pipe(process.stdout)

@@ -1,4 +0,3 @@

import { PassThrough, pipeline, Readable } from 'stream'
import { messages } from '@cucumber/messages'
import { BinaryToMessageStream } from '@cucumber/message-streams'
import { PassThrough, Readable } from 'stream'
import * as messages from '@cucumber/messages'
import ParserMessageStream from './ParserMessageStream'

@@ -10,11 +9,7 @@ import SourceMessageStream from './SourceMessageStream'

function fromStream(stream: Readable, options: IGherkinOptions) {
return pipeline(
stream,
new BinaryToMessageStream(messages.Envelope.decodeDelimited),
new ParserMessageStream(options)
)
export interface IGherkinStreamOptions extends IGherkinOptions {
relativeTo?: string
}
function fromPaths(paths: ReadonlyArray<string>, options: IGherkinOptions): Readable {
function fromPaths(paths: readonly string[], options: IGherkinStreamOptions): Readable {
const pathsCopy = paths.slice()

@@ -40,3 +35,3 @@ options = makeGherkinOptions(options)

.on('error', (err) => combinedMessageStream.emit('error', err))
.pipe(new SourceMessageStream(path))
.pipe(new SourceMessageStream(path, options.relativeTo))
.on('error', (err) => combinedMessageStream.emit('error', err))

@@ -52,6 +47,3 @@ .pipe(parserMessageStream)

function fromSources(
envelopes: ReadonlyArray<messages.IEnvelope>,
options: IGherkinOptions
): Readable {
function fromSources(envelopes: readonly messages.Envelope[], options: IGherkinOptions): Readable {
const envelopesCopy = envelopes.slice()

@@ -82,4 +74,3 @@ options = makeGherkinOptions(options)

fromPaths,
fromStream,
fromSources,
}

@@ -1,3 +0,3 @@

import GherkinStreams from './GherkinStreams'
import GherkinStreams, { IGherkinStreamOptions } from './GherkinStreams'
export { GherkinStreams }
export { GherkinStreams, IGherkinStreamOptions }
import { Transform, TransformCallback } from 'stream'
import { messages } from '@cucumber/messages'
import * as messages from '@cucumber/messages'
import { generateMessages, IGherkinOptions } from '@cucumber/gherkin'

@@ -13,5 +13,10 @@

public _transform(envelope: messages.IEnvelope, encoding: string, callback: TransformCallback) {
public _transform(envelope: messages.Envelope, encoding: string, callback: TransformCallback) {
if (envelope.source) {
const messageList = generateMessages(envelope.source.data, envelope.source.uri, this.options)
const messageList = generateMessages(
envelope.source.data,
envelope.source.uri,
envelope.source.mediaType,
this.options
)
for (const message of messageList) {

@@ -24,3 +29,1 @@ this.push(message)

}
module.exports = ParserMessageStream
import { makeSourceEnvelope } from '@cucumber/gherkin'
import { Transform, TransformCallback } from 'stream'
import { relative } from 'path'

@@ -10,3 +11,3 @@ /**

constructor(private readonly uri: string) {
constructor(private readonly uri: string, private readonly relativeTo?: string) {
super({ readableObjectMode: true, writableObjectMode: false })

@@ -22,3 +23,6 @@ }

const data = this.buffer.toString('utf8')
const chunk = makeSourceEnvelope(data, this.uri)
const chunk = makeSourceEnvelope(
data,
this.relativeTo ? relative(this.relativeTo, this.uri) : this.uri
)
this.push(chunk)

@@ -25,0 +29,0 @@ callback()

import assert from 'assert'
import { Readable } from 'stream'
import { messages } from '@cucumber/messages'
import * as messages from '@cucumber/messages'
import { dialects, IGherkinOptions, makeSourceEnvelope } from '@cucumber/gherkin'

@@ -15,2 +15,5 @@ import { GherkinStreams } from '../src'

assert.strictEqual(envelopes.length, 3)
assert.strictEqual(envelopes[0].source.uri, 'testdata/good/minimal.feature')
assert.strictEqual(envelopes[1].gherkinDocument.uri, 'testdata/good/minimal.feature')
assert.strictEqual(envelopes[2].pickle.uri, 'testdata/good/minimal.feature')
})

@@ -24,2 +27,15 @@

it('emits uris relative to a given path', async () => {
const envelopes = await streamToArray(
GherkinStreams.fromPaths(['testdata/good/minimal.feature'], {
...defaultOptions,
relativeTo: 'testdata/good',
})
)
assert.strictEqual(envelopes.length, 3)
assert.strictEqual(envelopes[0].source.uri, 'minimal.feature')
assert.strictEqual(envelopes[1].gherkinDocument.uri, 'minimal.feature')
assert.strictEqual(envelopes[2].pickle.uri, 'minimal.feature')
})
it('parses gherkin from STDIN', async () => {

@@ -58,6 +74,6 @@ const source = makeSourceEnvelope(

async function streamToArray(readableStream: Readable): Promise<messages.IEnvelope[]> {
return new Promise<messages.IEnvelope[]>(
(resolve: (wrappers: messages.IEnvelope[]) => void, reject: (err: Error) => void) => {
const items: messages.IEnvelope[] = []
async function streamToArray(readableStream: Readable): Promise<messages.Envelope[]> {
return new Promise<messages.Envelope[]>(
(resolve: (wrappers: messages.Envelope[]) => void, reject: (err: Error) => void) => {
const items: messages.Envelope[] = []
readableStream.on('data', items.push.bind(items))

@@ -64,0 +80,0 @@ readableStream.on('error', (err: Error) => reject(err))

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc