Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Badeball restore native javascript gherkin #709

Merged
merged 18 commits into from Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions .circleci/config.yml
Expand Up @@ -210,7 +210,6 @@ jobs:
paths:
- gherkin/javascript/dist
- gherkin/javascript/node_modules
- gherkin/javascript/executables

tag-expressions-javascript:
executor: docker-circleci-node
Expand Down Expand Up @@ -583,7 +582,6 @@ workflows:
- checkout
- gherkin-javascript:
requires:
- c21e-javascript
- cucumber-messages-javascript
- gherkin-go
- tag-expressions-javascript:
Expand All @@ -592,12 +590,10 @@ workflows:
- fake-cucumber-javascript:
requires:
- cucumber-messages-javascript
- c21e-javascript
- gherkin-javascript
- cucumber-react-javascript:
requires:
- cucumber-messages-javascript
- c21e-javascript
- gherkin-javascript
- fake-cucumber-javascript
- html-formatter-javascript:
Expand Down
4 changes: 2 additions & 2 deletions .templates/javascript/default.mk
Expand Up @@ -18,11 +18,11 @@ endif
npm run build
touch $@

.tested: .codegen $(TYPESCRIPT_SOURCE_FILES)
.tested: .built $(TYPESCRIPT_SOURCE_FILES)
TS_NODE_TRANSPILE_ONLY=1 npm run test
touch $@

.linted: .codegen $(TYPESCRIPT_SOURCE_FILES)
.linted: $(TYPESCRIPT_SOURCE_FILES)
npm run lint-fix
touch $@

Expand Down
4 changes: 2 additions & 2 deletions c21e/javascript/default.mk
Expand Up @@ -18,11 +18,11 @@ endif
npm run build
touch $@

.tested: .codegen $(TYPESCRIPT_SOURCE_FILES)
.tested: .built $(TYPESCRIPT_SOURCE_FILES)
TS_NODE_TRANSPILE_ONLY=1 npm run test
touch $@

.linted: .codegen $(TYPESCRIPT_SOURCE_FILES)
.linted: $(TYPESCRIPT_SOURCE_FILES)
npm run lint-fix
touch $@

Expand Down
4 changes: 2 additions & 2 deletions cucumber-expressions/javascript/default.mk
Expand Up @@ -18,11 +18,11 @@ endif
npm run build
touch $@

.tested: .codegen $(TYPESCRIPT_SOURCE_FILES)
.tested: .built $(TYPESCRIPT_SOURCE_FILES)
TS_NODE_TRANSPILE_ONLY=1 npm run test
touch $@

.linted: .codegen $(TYPESCRIPT_SOURCE_FILES)
.linted: $(TYPESCRIPT_SOURCE_FILES)
npm run lint-fix
touch $@

Expand Down
4 changes: 2 additions & 2 deletions cucumber-messages/javascript/default.mk
Expand Up @@ -18,11 +18,11 @@ endif
npm run build
touch $@

.tested: .codegen $(TYPESCRIPT_SOURCE_FILES)
.tested: .built $(TYPESCRIPT_SOURCE_FILES)
TS_NODE_TRANSPILE_ONLY=1 npm run test
touch $@

.linted: .codegen $(TYPESCRIPT_SOURCE_FILES)
.linted: $(TYPESCRIPT_SOURCE_FILES)
npm run lint-fix
touch $@

Expand Down
17 changes: 17 additions & 0 deletions cucumber-messages/javascript/src/ProtobufBinaryStream.ts
@@ -0,0 +1,17 @@
import { Transform, TransformCallback } from 'stream'
import { Writer } from 'protobufjs'

/**
* Transforms a stream of protobuf messages to bytes
*/
export default class ProtobufBinaryStream<T> extends Transform {
constructor(private readonly encodeDelimited: (message: T) => Writer) {
super({ objectMode: true })
}

public _transform(message: T, encoding: string, callback: TransformCallback) {
const chunk = this.encodeDelimited(message).finish()
this.push(chunk)
callback()
}
}
4 changes: 1 addition & 3 deletions cucumber-messages/javascript/src/ProtobufMessageStream.ts
Expand Up @@ -4,7 +4,7 @@ import { Reader } from 'protobufjs'
/**
* Transforms a stream of bytes to protobuf messages
*/
class ProtobufMessageStream<T> extends Transform {
export default class ProtobufMessageStream<T> extends Transform {
private buffer = Buffer.alloc(0)

constructor(
Expand Down Expand Up @@ -34,5 +34,3 @@ class ProtobufMessageStream<T> extends Transform {
callback()
}
}

export default ProtobufMessageStream
43 changes: 43 additions & 0 deletions cucumber-messages/javascript/src/ProtobufNdjsonStream.ts
@@ -0,0 +1,43 @@
import { Transform, TransformCallback } from 'stream'

export default class ProtobufNdjsonStream<T> extends Transform {
constructor() {
super({
writableObjectMode: true,
readableObjectMode: true,
})
}

public _transform(message: T, encoding: string, callback: TransformCallback) {
// @ts-ignore
if (!message.constructor.toObject) {
return callback(
new Error(`Not a protobuf object: ${JSON.stringify(message)}`)
)
}
// @ts-ignore
const ob = message.constructor.toObject(message, { defaults: true })

// This reviver omits printing fields with empty values
// This is to make it behave the same as Golang's protobuf->JSON converter
const json = JSON.stringify(ob, (key: string, value: any) => {
return value === null ||
value === '' ||
value === 0 ||
(Array.isArray(value) && value.length === 0)
? undefined
: fixEnum(key, value)
})
this.push(json + '\n')
callback()
}
}

// Enum values are incorrectly represented in JSON as the enum value index,
// rather than the enum value string. This function works around that.
function fixEnum(key: string, value: any) {
if (key === 'encoding') {
return ['BASE64', 'UTF8'][value]
}
return value
}
9 changes: 8 additions & 1 deletion cucumber-messages/javascript/src/index.ts
@@ -1,5 +1,12 @@
import ProtobufBinaryStream from './ProtobufBinaryStream'
import ProtobufNdjsonStream from './ProtobufNdjsonStream'
import ProtobufMessageStream from './ProtobufMessageStream'
import { io } from './cucumber-messages'
import messages = io.cucumber.messages

export { messages, ProtobufMessageStream }
export {
messages,
ProtobufBinaryStream,
ProtobufNdjsonStream,
ProtobufMessageStream,
}
4 changes: 2 additions & 2 deletions cucumber-react/javascript/default.mk
Expand Up @@ -18,11 +18,11 @@ endif
npm run build
touch $@

.tested: .codegen $(TYPESCRIPT_SOURCE_FILES)
.tested: .built $(TYPESCRIPT_SOURCE_FILES)
TS_NODE_TRANSPILE_ONLY=1 npm run test
touch $@

.linted: .codegen $(TYPESCRIPT_SOURCE_FILES)
.linted: $(TYPESCRIPT_SOURCE_FILES)
npm run lint-fix
touch $@

Expand Down
4 changes: 2 additions & 2 deletions fake-cucumber/javascript/default.mk
Expand Up @@ -18,11 +18,11 @@ endif
npm run build
touch $@

.tested: .codegen $(TYPESCRIPT_SOURCE_FILES)
.tested: .built $(TYPESCRIPT_SOURCE_FILES)
TS_NODE_TRANSPILE_ONLY=1 npm run test
touch $@

.linted: .codegen $(TYPESCRIPT_SOURCE_FILES)
.linted: $(TYPESCRIPT_SOURCE_FILES)
npm run lint-fix
touch $@

Expand Down
2 changes: 1 addition & 1 deletion fake-cucumber/javascript/src/main.ts
Expand Up @@ -27,7 +27,7 @@ const fakeTestResultsStream = new FakeTestResultsStream(
fakeTestResultsStream.on('error', (err: Error) => exit(err))

gherkin
.fromPaths(paths)
.fromPaths(paths, {})
.pipe(fakeTestResultsStream)
.pipe(process.stdout)

Expand Down
20 changes: 10 additions & 10 deletions fake-cucumber/javascript/test/FakeTestResultsStreamTest.ts
Expand Up @@ -3,8 +3,6 @@ import { messages } from 'cucumber-messages'
import FakeTestResultsStream from '../src/FakeTestResultsStream'
import { Readable } from 'stream'
import * as assert from 'assert'
import Source = messages.Source
import Media = messages.Media

describe('FakeTestResultsStream', () => {
it('generates failed pickle result', async () => {
Expand Down Expand Up @@ -106,17 +104,19 @@ async function generateMessages(
gherkinSource: string,
results: 'none' | 'pattern' | 'random'
): Promise<messages.IEnvelope[]> {
const source = Source.fromObject({
uri: 'test.feature',
data: gherkinSource,
media: Media.fromObject({
encoding: 'UTF8',
contentType: 'text/x.cucumber.gherkin+plain',
}),
const source = messages.Envelope.fromObject({
source: {
uri: 'test.feature',
data: gherkinSource,
media: messages.Media.fromObject({
encoding: 'UTF8',
contentType: 'text/x.cucumber.gherkin+plain',
}),
},
})

const fakeTestResultsStream = gherkin
.fromSources([source])
.fromSources([source], {})
.pipe(new FakeTestResultsStream('protobuf-objects', results))
return streamToArray(fakeTestResultsStream)
}
Expand Down
7 changes: 7 additions & 0 deletions gherkin/CHANGELOG.md
Expand Up @@ -14,6 +14,12 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
### Changed

* Upgrade cucumber-messages to 6.0.0
* [JavaScript] restore native JavaScript parser
([#709](https://github.com/cucumber/cucumber/pull/709)
[#689](https://github.com/cucumber/cucumber/pull/689)
[badeball]
[aslakhellesoy])
([#702](https://github.com/cucumber/cucumber/pull/702) [brasmusson])
* [Ruby] restore native ruby parser
([#702](https://github.com/cucumber/cucumber/pull/702) [brasmusson])

Expand Down Expand Up @@ -564,6 +570,7 @@ to Gherkin 2.
[Ahmed-Ali]: https://github.com/Ahmed-Ali
[ajspadial]: https://github.com/ajspadial
[aslakhellesoy]: https://github.com/aslakhellesoy
[badeball]: https://github.com/badeball
[brasmusson]: https://github.com/brasmusson
[charlierudolph]: https://github.com/charlierudolph
[cyocum]: https://github.com/cyocum
Expand Down
1 change: 0 additions & 1 deletion gherkin/javascript/.internal-dependencies
@@ -1,2 +1 @@
cucumber-messages
cucumber-react
1 change: 1 addition & 0 deletions gherkin/javascript/.npmignore
@@ -1,3 +1,4 @@
berp
test
testdata
Makefile
3 changes: 3 additions & 0 deletions gherkin/javascript/.rsync
Expand Up @@ -2,3 +2,6 @@
../../.templates/github/ .github/
../../.templates/javascript/ .
../testdata/ testdata/
../gherkin.berp gherkin.berp
../bin/ berp/
../gherkin-languages.json src/legacy/gherkin/gherkin-languages.json
27 changes: 15 additions & 12 deletions gherkin/javascript/Makefile
Expand Up @@ -10,39 +10,42 @@ ERRORS = $(patsubst testdata/%.feature,acceptance/testdata/%.feature.error

.DELETE_ON_ERROR:

.deps: executables
.codegen: src/Parser.ts

executables:
cp -R "$$(pwd)/../go/dist" $@
src/Parser.ts: gherkin.berp gherkin-javascript.razor berp/berp.exe
# We're allowing mono to fail. The monorepo build runs in a docker image which
# doesn't have mono installed. This looks like it will be fixed post Alpine 3.9:
# https://pkgs.alpinelinux.org/packages?name=mono&branch=edge
-mono berp/berp.exe -g gherkin.berp -t gherkin-javascript.razor -o $@
# Remove BOM
awk 'NR==1{sub(/^\xef\xbb\xbf/,"")}{print}' < $@ > $@.nobom
mv $@.nobom $@

.tested: dist/src/index.js .compared
.tested: .compared

.compared: $(ASTS) $(PICKLES) $(ERRORS) $(SOURCES)
touch $@

dist/src/index.js: src/index.ts
npm run build

acceptance/testdata/%.feature.ast.ndjson: testdata/%.feature testdata/%.feature.ast.ndjson .deps
mkdir -p `dirname $@`
bin/gherkin --no-source --no-pickles $< | jq --sort-keys --compact-output "." > $@
bin/gherkin --no-source --no-pickles --json $< | jq --sort-keys --compact-output "." > $@
diff --unified <(jq "." $<.ast.ndjson) <(jq "." $@)

acceptance/testdata/%.feature.pickles.ndjson: testdata/%.feature testdata/%.feature.pickles.ndjson .deps
mkdir -p `dirname $@`
bin/gherkin --no-source --no-ast $< | jq --sort-keys --compact-output "." > $@
bin/gherkin --no-source --no-ast --json $< | jq --sort-keys --compact-output "." > $@
diff --unified <(jq "." $<.pickles.ndjson) <(jq "." $@)

acceptance/testdata/%.feature.source.ndjson: testdata/%.feature testdata/%.feature.source.ndjson .deps
mkdir -p `dirname $@`
bin/gherkin --no-ast --no-pickles $< | jq --sort-keys --compact-output "." > $@
bin/gherkin --no-ast --no-pickles --json $< | jq --sort-keys --compact-output "." > $@
diff --unified <(jq "." $<.source.ndjson) <(jq "." $@)

acceptance/testdata/%.feature.errors.ndjson: testdata/%.feature testdata/%.feature.errors.ndjson .deps
mkdir -p `dirname $@`
bin/gherkin --no-source $< | jq --sort-keys --compact-output "." > $@
bin/gherkin --no-source --json $< | jq --sort-keys --compact-output "." > $@
diff --unified <(jq "." $<.errors.ndjson) <(jq "." $@)

clean:
rm -rf acceptance executables
rm -rf acceptance
.PHONY: clean
Binary file added gherkin/javascript/berp/CommandLine.dll
Binary file not shown.
Binary file added gherkin/javascript/berp/RazorEngine.dll
Binary file not shown.
Binary file added gherkin/javascript/berp/RazorEngine.pdb
Binary file not shown.
Binary file added gherkin/javascript/berp/System.Web.Razor.dll
Binary file not shown.
Binary file added gherkin/javascript/berp/berp.exe
Binary file not shown.
Binary file added gherkin/javascript/berp/berp.pdb
Binary file not shown.