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

break circular dependency on gherkin-streams #92

Merged
merged 3 commits into from
Jan 29, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions javascript/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GHERKIN_PARSER = src/Parser.ts
GHERKIN_RAZOR = gherkin-javascript.razor
SOURCE_FILES = $(shell find . -name "*.js" | grep -v $(GHERKIN_PARSER))

GHERKIN = npx gherkin-javascript
GHERKIN = node ./test-cli.mjs

GOOD_FEATURE_FILES = $(shell find ../testdata/good -name "*.feature" -o -name "*.feature.md")
BAD_FEATURE_FILES = $(shell find ../testdata/bad -name "*.feature" -o -name "*.feature.md")
Expand Down Expand Up @@ -33,18 +33,22 @@ clean-gherkin-languages: ## Remove gherkin-languages.json and any derived files
clean: ## Remove all build artifacts and files generated by the acceptance tests
rm -rf .built
rm -rf acceptance
rm -rf dist
rm -rf node_modules

.DELETE_ON_ERROR:

acceptance: .built $(ASTS) $(PICKLES) $(ERRORS) $(SOURCES) ## Build acceptance test dir and compare results with reference

.built: node_modules $(SOURCE_FILES)
.built: node_modules dist $(SOURCE_FILES)
touch $@

node_modules:
npm install

dist:
npm run build

$(GHERKIN_PARSER): $(GHERKIN_RAZOR) ../gherkin.berp
berp -g ../gherkin.berp -t $< -o $@ --noBOM

Expand All @@ -53,20 +57,20 @@ $(GHERKIN_LANGUAGES_JSON):

acceptance/testdata/%.ast.ndjson: ../testdata/% ../testdata/%.ast.ndjson
mkdir -p $(@D)
$(GHERKIN) --no-source --no-pickles --predictable-ids $< | jq --sort-keys --compact-output "." > $@
$(GHERKIN) --no-source --no-pickles $< | jq --sort-keys --compact-output "." > $@
diff --unified <(jq "." $<.ast.ndjson) <(jq "." $@)

acceptance/testdata/%.pickles.ndjson: ../testdata/% ../testdata/%.pickles.ndjson
mkdir -p $(@D)
$(GHERKIN) --no-source --no-ast --predictable-ids $< | jq --sort-keys --compact-output "." > $@
$(GHERKIN) --no-source --no-ast $< | jq --sort-keys --compact-output "." > $@
diff --unified <(jq "." $<.pickles.ndjson) <(jq "." $@)

acceptance/testdata/%.source.ndjson: ../testdata/% ../testdata/%.source.ndjson
mkdir -p $(@D)
$(GHERKIN) --no-ast --no-pickles --predictable-ids $< | jq --sort-keys --compact-output "." > $@
$(GHERKIN) --no-ast --no-pickles $< | jq --sort-keys --compact-output "." > $@
diff --unified <(jq "." $<.source.ndjson) <(jq "." $@)

acceptance/testdata/%.errors.ndjson: ../testdata/% ../testdata/%.errors.ndjson
mkdir -p $(@D)
$(GHERKIN) --no-source --predictable-ids $< | jq --sort-keys --compact-output "." > $@
$(GHERKIN) --no-source $< | jq --sort-keys --compact-output "." > $@
diff --unified <(jq "." $<.errors.ndjson) <(jq "." $@)
157 changes: 8 additions & 149 deletions javascript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
},
"homepage": "https://github.com/cucumber/gherkin",
"devDependencies": {
"@cucumber/gherkin-streams": "^5.0.1",
"@types/mocha": "10.0.1",
"@types/node": "18.11.18",
"commander": "^10.0.0",
"core-js": "3.27.2",
"mocha": "10.2.0",
"ts-node": "10.9.1",
Expand Down
24 changes: 24 additions & 0 deletions javascript/test-cli.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { IdGenerator } from '@cucumber/messages'
import { Command } from 'commander'
import { readFileSync } from "fs";
import { generateMessages, makeSourceEnvelope } from './dist/src/index.js'

const program = new Command()
program.option('--no-source', 'Do not output Source messages')
program.option('--no-ast', 'Do not output GherkinDocument messages')
program.option('--no-pickles', 'Do not output Pickle messages')
program.parse(process.argv)
const [path] = program.args

const options = {
defaultDialect: 'en',
includeSource: program.opts().source,
includeGherkinDocument: program.opts().ast,
includePickles: program.opts().pickles,
newId: IdGenerator.incrementing()
}

const content = readFileSync(path, { encoding: 'utf-8' })
const { source: { data, uri, mediaType } } = makeSourceEnvelope(content, path)
const results = generateMessages(data, uri, mediaType, options)
process.stdout.write(results.map(item => JSON.stringify(item)).join('\n'))