Skip to content

Commit 8264bd0

Browse files
authored
break circular dependency on gherkin-streams (#92)
* change dependencies * replace gherkin-streams use with simple script * ensure we build before doing acceptance tests
1 parent 2b5578a commit 8264bd0

File tree

4 files changed

+43
-156
lines changed

4 files changed

+43
-156
lines changed

javascript/Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ GHERKIN_PARSER = src/Parser.ts
55
GHERKIN_RAZOR = gherkin-javascript.razor
66
SOURCE_FILES = $(shell find . -name "*.js" | grep -v $(GHERKIN_PARSER))
77

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

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

3839
.DELETE_ON_ERROR:
3940

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

42-
.built: node_modules $(SOURCE_FILES)
43+
.built: node_modules dist $(SOURCE_FILES)
4344
touch $@
4445

4546
node_modules:
4647
npm install
4748

49+
dist:
50+
npm run build
51+
4852
$(GHERKIN_PARSER): $(GHERKIN_RAZOR) ../gherkin.berp
4953
berp -g ../gherkin.berp -t $< -o $@ --noBOM
5054

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

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

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

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

6973
acceptance/testdata/%.errors.ndjson: ../testdata/% ../testdata/%.errors.ndjson
7074
mkdir -p $(@D)
71-
$(GHERKIN) --no-source --predictable-ids $< | jq --sort-keys --compact-output "." > $@
75+
$(GHERKIN) --no-source $< | jq --sort-keys --compact-output "." > $@
7276
diff --unified <(jq "." $<.errors.ndjson) <(jq "." $@)

javascript/package-lock.json

Lines changed: 8 additions & 149 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

javascript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
},
3232
"homepage": "https://github.com/cucumber/gherkin",
3333
"devDependencies": {
34-
"@cucumber/gherkin-streams": "^5.0.1",
3534
"@types/mocha": "10.0.1",
3635
"@types/node": "18.11.18",
36+
"commander": "^10.0.0",
3737
"core-js": "3.27.2",
3838
"mocha": "10.2.0",
3939
"ts-node": "10.9.1",

javascript/test-cli.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { IdGenerator } from '@cucumber/messages'
2+
import { Command } from 'commander'
3+
import { readFileSync } from "fs";
4+
import { generateMessages, makeSourceEnvelope } from './dist/src/index.js'
5+
6+
const program = new Command()
7+
program.option('--no-source', 'Do not output Source messages')
8+
program.option('--no-ast', 'Do not output GherkinDocument messages')
9+
program.option('--no-pickles', 'Do not output Pickle messages')
10+
program.parse(process.argv)
11+
const [path] = program.args
12+
13+
const options = {
14+
defaultDialect: 'en',
15+
includeSource: program.opts().source,
16+
includeGherkinDocument: program.opts().ast,
17+
includePickles: program.opts().pickles,
18+
newId: IdGenerator.incrementing()
19+
}
20+
21+
const content = readFileSync(path, { encoding: 'utf-8' })
22+
const { source: { data, uri, mediaType } } = makeSourceEnvelope(content, path)
23+
const results = generateMessages(data, uri, mediaType, options)
24+
process.stdout.write(results.map(item => JSON.stringify(item)).join('\n'))

0 commit comments

Comments
 (0)