Skip to content

Commit

Permalink
break circular dependency on gherkin-streams (#92)
Browse files Browse the repository at this point in the history
* change dependencies

* replace gherkin-streams use with simple script

* ensure we build before doing acceptance tests
  • Loading branch information
davidjgoss authored Jan 29, 2023
1 parent 2b5578a commit 8264bd0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 156 deletions.
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'))

0 comments on commit 8264bd0

Please sign in to comment.