This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tests. Make IdGenerator pluggable
- Loading branch information
1 parent
620c18b
commit e08cc10
Showing
15 changed files
with
162 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { PassThrough, pipeline, Readable } from 'stream' | ||
import { BinaryToMessageStream, messages } from 'cucumber-messages' | ||
import ParserMessageStream from './stream/ParserMessageStream' | ||
import GherkinExe from './external/GherkinExe' | ||
import fs from 'fs' | ||
import SourceMessageStream from './stream/SourceMessageStream' | ||
import Dialect from './Dialect' | ||
import DIALECTS from './gherkin-languages.json' | ||
import IGherkinOptions from './IGherkinOptions' | ||
import makeGherkinOptions from './makeGherkinOptions' | ||
|
||
function fromStream(stream: Readable, options: IGherkinOptions = {}) { | ||
return pipeline( | ||
stream, | ||
new BinaryToMessageStream(messages.Envelope.decodeDelimited), | ||
new ParserMessageStream(options) | ||
) | ||
} | ||
|
||
function fromPaths(paths: string[], options: IGherkinOptions = {}): Readable { | ||
options = makeGherkinOptions(options) | ||
|
||
if (process.env.GHERKIN_EXECUTABLE) { | ||
return new GherkinExe( | ||
process.env.GHERKIN_EXECUTABLE, | ||
paths, | ||
[], | ||
options | ||
).messageStream() | ||
} | ||
|
||
const combinedMessageStream = new PassThrough({ | ||
writableObjectMode: true, | ||
readableObjectMode: true, | ||
}) | ||
|
||
function pipeSequentially() { | ||
const path = paths.shift() | ||
if (path !== undefined) { | ||
const parserMessageStream = new ParserMessageStream(options) | ||
parserMessageStream.on('end', () => { | ||
pipeSequentially() | ||
}) | ||
|
||
const end = paths.length === 0 | ||
fs.createReadStream(path, { encoding: 'utf-8' }) | ||
.pipe(new SourceMessageStream(path)) | ||
.pipe(parserMessageStream) | ||
.pipe(combinedMessageStream, { end }) | ||
} | ||
} | ||
pipeSequentially() | ||
return combinedMessageStream | ||
} | ||
|
||
function fromSources( | ||
envelopes: messages.IEnvelope[], | ||
options: IGherkinOptions = {} | ||
): Readable { | ||
options = makeGherkinOptions(options) | ||
if (process.env.GHERKIN_EXECUTABLE) { | ||
return new GherkinExe( | ||
process.env.GHERKIN_EXECUTABLE, | ||
[], | ||
envelopes, | ||
options | ||
).messageStream() | ||
} | ||
|
||
const combinedMessageStream = new PassThrough({ objectMode: true }) | ||
|
||
function pipeSequentially() { | ||
const envelope = envelopes.shift() | ||
if (envelope !== undefined && envelope.source) { | ||
const parserMessageStream = new ParserMessageStream(options) | ||
parserMessageStream.pipe(combinedMessageStream, { | ||
end: envelopes.length === 0, | ||
}) | ||
parserMessageStream.on('end', pipeSequentially) | ||
parserMessageStream.end(envelope) | ||
} | ||
} | ||
pipeSequentially() | ||
|
||
return combinedMessageStream | ||
} | ||
|
||
function dialects(): { [key: string]: Dialect } { | ||
return DIALECTS | ||
} | ||
|
||
export default { | ||
fromPaths, | ||
fromStream, | ||
fromSources, | ||
dialects, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { IdGenerator } from 'cucumber-messages' | ||
|
||
export default interface IGherkinOptions { | ||
defaultDialect?: string | ||
includeSource?: boolean | ||
includeGherkinDocument?: boolean | ||
includePickles?: boolean | ||
newId?: IdGenerator.NewId | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,5 @@ | ||
import { gherkinOptions, IGherkinOptions } from './types' | ||
import { PassThrough, Readable, pipeline } from 'stream' | ||
import ParserMessageStream from './stream/ParserMessageStream' | ||
import fs from 'fs' | ||
import SourceMessageStream from './stream/SourceMessageStream' | ||
import { messages, BinaryToMessageStream } from 'cucumber-messages' | ||
import DIALECTS from './gherkin-languages.json' | ||
import Dialect from './Dialect' | ||
import GherkinExe from './external/GherkinExe' | ||
import { uuid, incrementing } from './IdGenerator' | ||
import Gherkin from './Gherkin' | ||
import IGherkinOptions from './IGherkinOptions' | ||
|
||
export function fromStream(stream: Readable, options: IGherkinOptions = {}) { | ||
return pipeline( | ||
stream, | ||
new BinaryToMessageStream(messages.Envelope.decodeDelimited), | ||
new ParserMessageStream(options) | ||
) | ||
} | ||
|
||
export function fromPaths( | ||
paths: string[], | ||
options: IGherkinOptions = {} | ||
): Readable { | ||
options = gherkinOptions(options) | ||
|
||
if (process.env.GHERKIN_EXECUTABLE) { | ||
return new GherkinExe( | ||
process.env.GHERKIN_EXECUTABLE, | ||
paths, | ||
[], | ||
options | ||
).messageStream() | ||
} | ||
|
||
const combinedMessageStream = new PassThrough({ | ||
writableObjectMode: true, | ||
readableObjectMode: true, | ||
}) | ||
|
||
function pipeSequentially() { | ||
const path = paths.shift() | ||
if (path !== undefined) { | ||
const parserMessageStream = new ParserMessageStream(options) | ||
parserMessageStream.on('end', () => { | ||
pipeSequentially() | ||
}) | ||
|
||
const end = paths.length === 0 | ||
fs.createReadStream(path, { encoding: 'utf-8' }) | ||
.pipe(new SourceMessageStream(path)) | ||
.pipe(parserMessageStream) | ||
.pipe(combinedMessageStream, { end }) | ||
} | ||
} | ||
pipeSequentially() | ||
return combinedMessageStream | ||
} | ||
|
||
export function fromSources( | ||
envelopes: messages.IEnvelope[], | ||
options: IGherkinOptions = {} | ||
): Readable { | ||
options = gherkinOptions(options) | ||
if (process.env.GHERKIN_EXECUTABLE) { | ||
return new GherkinExe( | ||
process.env.GHERKIN_EXECUTABLE, | ||
[], | ||
envelopes, | ||
options | ||
).messageStream() | ||
} | ||
|
||
const combinedMessageStream = new PassThrough({ objectMode: true }) | ||
|
||
function pipeSequentially() { | ||
const envelope = envelopes.shift() | ||
if (envelope !== undefined && envelope.source) { | ||
const parserMessageStream = new ParserMessageStream(options) | ||
parserMessageStream.pipe(combinedMessageStream, { | ||
end: envelopes.length === 0, | ||
}) | ||
parserMessageStream.on('end', pipeSequentially) | ||
parserMessageStream.end(envelope) | ||
} | ||
} | ||
pipeSequentially() | ||
|
||
return combinedMessageStream | ||
} | ||
|
||
export function dialects(): { [key: string]: Dialect } { | ||
return DIALECTS | ||
} | ||
|
||
export default { | ||
fromStream, | ||
fromPaths, | ||
fromSources, | ||
dialects, | ||
uuid, | ||
incrementing, | ||
} | ||
export default Gherkin | ||
export { IGherkinOptions } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { IdGenerator } from 'cucumber-messages' | ||
import IGherkinOptions from './IGherkinOptions' | ||
|
||
const defaultOptions: IGherkinOptions = { | ||
defaultDialect: 'en', | ||
includeSource: true, | ||
includeGherkinDocument: true, | ||
includePickles: true, | ||
newId: IdGenerator.uuid(), | ||
} | ||
|
||
export default function gherkinOptions(options: IGherkinOptions) { | ||
return { ...defaultOptions, ...options } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.