Skip to content

Commit

Permalink
Merge pull request #793 from cucumber/fake-cucumber-use-cucumber-expr…
Browse files Browse the repository at this point in the history
…essions

Use cucumber-expressions to generate the match in fake-cucumber
  • Loading branch information
aslakhellesoy authored Nov 22, 2019
2 parents 5f718e3 + 0f43b81 commit 503e7b3
Show file tree
Hide file tree
Showing 68 changed files with 1,272 additions and 607 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ workflows:
requires:
- cucumber-messages-javascript
- gherkin-javascript
- cucumber-expressions-javascript-node-12
- cucumber-react-javascript:
requires:
- cucumber-messages-javascript
Expand Down
4 changes: 2 additions & 2 deletions .templates/javascript/default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := /usr/bin/env bash
TYPESCRIPT_SOURCE_FILES = $(shell find src test -type f -name "*.ts" -o -name "*.tsx")
PRIVATE = $(shell node -e "console.log(require('./package.json').private)")

default: .tested .built
default: .linted .tested .built
.PHONY: default

.deps: package-lock.json
Expand All @@ -22,7 +22,7 @@ endif
TS_NODE_TRANSPILE_ONLY=1 npm run test
touch $@

.linted: $(TYPESCRIPT_SOURCE_FILES)
.linted: $(TYPESCRIPT_SOURCE_FILES) package-lock.json
npm run lint-fix
touch $@

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ SHELL := /usr/bin/env bash
MAKEFILES=c21e/Makefile \
cucumber-messages/Makefile \
gherkin/Makefile \
cucumber-expressions/Makefile \
fake-cucumber/Makefile \
cucumber-query/Makefile \
cucumber-react/Makefile \
html-formatter/Makefile \
json-formatter/Makefile \
datatable/Makefile \
config/Makefile \
cucumber-expressions/Makefile \
tag-expressions/Makefile \
cucumber-demo-formatter/Makefile

Expand Down
4 changes: 2 additions & 2 deletions c21e/javascript/default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := /usr/bin/env bash
TYPESCRIPT_SOURCE_FILES = $(shell find src test -type f -name "*.ts" -o -name "*.tsx")
PRIVATE = $(shell node -e "console.log(require('./package.json').private)")

default: .tested .built
default: .linted .tested .built
.PHONY: default

.deps: package-lock.json
Expand All @@ -22,7 +22,7 @@ endif
TS_NODE_TRANSPILE_ONLY=1 npm run test
touch $@

.linted: $(TYPESCRIPT_SOURCE_FILES)
.linted: $(TYPESCRIPT_SOURCE_FILES) package-lock.json
npm run lint-fix
touch $@

Expand Down
2 changes: 2 additions & 0 deletions cucumber-expressions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

* [JavaScript] export `Argument` and `Expression` types

### Changed

### Deprecated
Expand Down
4 changes: 2 additions & 2 deletions cucumber-expressions/javascript/default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := /usr/bin/env bash
TYPESCRIPT_SOURCE_FILES = $(shell find src test -type f -name "*.ts" -o -name "*.tsx")
PRIVATE = $(shell node -e "console.log(require('./package.json').private)")

default: .tested .built
default: .linted .tested .built
.PHONY: default

.deps: package-lock.json
Expand All @@ -22,7 +22,7 @@ endif
TS_NODE_TRANSPILE_ONLY=1 npm run test
touch $@

.linted: $(TYPESCRIPT_SOURCE_FILES)
.linted: $(TYPESCRIPT_SOURCE_FILES) package-lock.json
npm run lint-fix
touch $@

Expand Down
6 changes: 5 additions & 1 deletion cucumber-expressions/javascript/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import Argument from './Argument'
import Expression from './Expression'
import CucumberExpression from './CucumberExpression'
import RegularExpression from './RegularExpression'
import CucumberExpressionGenerator from './CucumberExpressionGenerator'
import ParameterTypeRegistry from './ParameterTypeRegistry'
import ParameterType from './ParameterType'

export = {
export {
Argument,
Expression,
CucumberExpression,
RegularExpression,
CucumberExpressionGenerator,
Expand Down
2 changes: 1 addition & 1 deletion cucumber-expressions/javascript/src/web.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import CucumberExpressions from './index'
import * as CucumberExpressions from './index'

// @ts-ignore
window.CucumberExpressions = CucumberExpressions
1 change: 1 addition & 0 deletions cucumber-messages/dotnet/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ message TestCase {
// Pointer to the PickleStep (if derived from a PickleStep)
string pickleStepId = 2;
// Pointer to all the matching StepDefinitions (if derived from a PickleStep)
// TODO: Should be renamed stepDefinitionIds
repeated string stepDefinitionId = 3;
// All the arguments from the match (if derived from a PickleStep and there was exactly 1 StepDefinition)
repeated StepMatchArgument stepMatchArguments = 4;
Expand Down
1 change: 1 addition & 0 deletions cucumber-messages/go/messages.pb.go

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

1 change: 1 addition & 0 deletions cucumber-messages/go/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ message TestCase {
// Pointer to the PickleStep (if derived from a PickleStep)
string pickleStepId = 2;
// Pointer to all the matching StepDefinitions (if derived from a PickleStep)
// TODO: Should be renamed stepDefinitionIds
repeated string stepDefinitionId = 3;
// All the arguments from the match (if derived from a PickleStep and there was exactly 1 StepDefinition)
repeated StepMatchArgument stepMatchArguments = 4;
Expand Down
1 change: 1 addition & 0 deletions cucumber-messages/java/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ message TestCase {
// Pointer to the PickleStep (if derived from a PickleStep)
string pickleStepId = 2;
// Pointer to all the matching StepDefinitions (if derived from a PickleStep)
// TODO: Should be renamed stepDefinitionIds
repeated string stepDefinitionId = 3;
// All the arguments from the match (if derived from a PickleStep and there was exactly 1 StepDefinition)
repeated StepMatchArgument stepMatchArguments = 4;
Expand Down
4 changes: 2 additions & 2 deletions cucumber-messages/javascript/default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := /usr/bin/env bash
TYPESCRIPT_SOURCE_FILES = $(shell find src test -type f -name "*.ts" -o -name "*.tsx")
PRIVATE = $(shell node -e "console.log(require('./package.json').private)")

default: .tested .built
default: .linted .tested .built
.PHONY: default

.deps: package-lock.json
Expand All @@ -22,7 +22,7 @@ endif
TS_NODE_TRANSPILE_ONLY=1 npm run test
touch $@

.linted: $(TYPESCRIPT_SOURCE_FILES)
.linted: $(TYPESCRIPT_SOURCE_FILES) package-lock.json
npm run lint-fix
touch $@

Expand Down
1 change: 1 addition & 0 deletions cucumber-messages/javascript/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ message TestCase {
// Pointer to the PickleStep (if derived from a PickleStep)
string pickleStepId = 2;
// Pointer to all the matching StepDefinitions (if derived from a PickleStep)
// TODO: Should be renamed stepDefinitionIds
repeated string stepDefinitionId = 3;
// All the arguments from the match (if derived from a PickleStep and there was exactly 1 StepDefinition)
repeated StepMatchArgument stepMatchArguments = 4;
Expand Down
8 changes: 4 additions & 4 deletions cucumber-messages/javascript/test/ProtobufNdjsonStreamTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('ProtobufNdjsonStream', () => {
status: messages.TestResult.Status.UNKNOWN,
}),
}),
}),
})
)
})

Expand All @@ -38,7 +38,7 @@ describe('ProtobufNdjsonStream', () => {
testCase: messages.TestCase.create({
pickleId: '123',
}),
}),
})
)
})

Expand All @@ -52,7 +52,7 @@ describe('ProtobufNdjsonStream', () => {
stream.write(
messages.Envelope.create({
testCase: messages.TestCase.create({ pickleId: '' }),
}),
})
)
})

Expand Down Expand Up @@ -80,7 +80,7 @@ describe('ProtobufNdjsonStream', () => {
}),
}),
}),
}),
})
)
})
})
1 change: 1 addition & 0 deletions cucumber-messages/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ message TestCase {
// Pointer to the PickleStep (if derived from a PickleStep)
string pickleStepId = 2;
// Pointer to all the matching StepDefinitions (if derived from a PickleStep)
// TODO: Should be renamed stepDefinitionIds
repeated string stepDefinitionId = 3;
// All the arguments from the match (if derived from a PickleStep and there was exactly 1 StepDefinition)
repeated StepMatchArgument stepMatchArguments = 4;
Expand Down
1 change: 1 addition & 0 deletions cucumber-messages/ruby/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ message TestCase {
// Pointer to the PickleStep (if derived from a PickleStep)
string pickleStepId = 2;
// Pointer to all the matching StepDefinitions (if derived from a PickleStep)
// TODO: Should be renamed stepDefinitionIds
repeated string stepDefinitionId = 3;
// All the arguments from the match (if derived from a PickleStep and there was exactly 1 StepDefinition)
repeated StepMatchArgument stepMatchArguments = 4;
Expand Down
12 changes: 11 additions & 1 deletion cucumber-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@ For example, [cucumber-react]() needs to know the status of a [Step](../cucumber
is rendering the [GherkinDocument](../cucumber-messages/messages.md#io.cucumber.messages.GherkinDocument)

The `cucumber-query` library makes this easy by providing a function to look up the
status of a step, a scenario or an entire file.
status of a step, a scenario or an entire file.

## API

| Query function | .NET | Go | Java | Ruby | TypeScript |
| --------------------------------------------------------------------------------------- | ---- | -- | ---- | ---- | ---------- |
| `getStepResults(uri: string, lineNumber: number): messages.ITestResult[]` | | | | ||
| `getScenarioResults(uri: string, lineNumber: number): messages.ITestResult[]` | | | | ||
| `getDocumentResults(uri: string): messages.ITestResult[]` | | | | ||
| `getStepMatchArguments(uri: string, lineNumber: number): messages.IStepMatchArgument[]` | | | | ||
| `getGherkinStep(gherkinStepId: string): messages.GherkinDocument.Feature.IStep` | | | | ||
4 changes: 2 additions & 2 deletions cucumber-query/javascript/default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := /usr/bin/env bash
TYPESCRIPT_SOURCE_FILES = $(shell find src test -type f -name "*.ts" -o -name "*.tsx")
PRIVATE = $(shell node -e "console.log(require('./package.json').private)")

default: .tested .built
default: .linted .tested .built
.PHONY: default

.deps: package-lock.json
Expand All @@ -22,7 +22,7 @@ endif
TS_NODE_TRANSPILE_ONLY=1 npm run test
touch $@

.linted: $(TYPESCRIPT_SOURCE_FILES)
.linted: $(TYPESCRIPT_SOURCE_FILES) package-lock.json
npm run lint-fix
touch $@

Expand Down
21 changes: 21 additions & 0 deletions cucumber-query/javascript/src/CucumberQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { messages } from 'cucumber-messages'
export default class CucumberQuery {
private readonly uriBySourceId = new Map<string, string>()
private readonly locationBySourceId = new Map<string, messages.ILocation>()
private readonly gherkinStepById = new Map<
string,
messages.GherkinDocument.Feature.IStep
>()

private readonly pickleById = new Map<string, messages.IPickle>()
private readonly pickleStepById = new Map<
Expand Down Expand Up @@ -87,6 +91,15 @@ export default class CucumberQuery {
this.testStepById.set(testStep.id, testStep)

const pickleStep = this.pickleStepById.get(testStep.pickleStepId)
if (pickleStep === undefined) {
throw new Error(
`Did not find a PickleStep with id "${
testStep.pickleStepId
}". Known ids:\n${Array.from(this.pickleStepById.keys()).join(
'\n'
)}`
)
}

for (const sourceId of pickleStep.sourceIds) {
const uri = this.uriBySourceId.get(sourceId)
Expand Down Expand Up @@ -180,6 +193,7 @@ export default class CucumberQuery {
for (const step of background.steps) {
this.uriBySourceId.set(step.id, uri)
this.locationBySourceId.set(step.id, step.location)
this.gherkinStepById.set(step.id, step)
}
}

Expand All @@ -192,6 +206,7 @@ export default class CucumberQuery {
for (const step of scenario.steps) {
this.uriBySourceId.set(step.id, uri)
this.locationBySourceId.set(step.id, step.location)
this.gherkinStepById.set(step.id, step)
}

for (const examples of scenario.examples) {
Expand Down Expand Up @@ -229,4 +244,10 @@ export default class CucumberQuery {
this.testStepMatchArgumentsByUriAndLine.get(`${uri}:${lineNumber}`) || []
)
}

public getGherkinStep(
gherkinStepId: string
): messages.GherkinDocument.Feature.IStep {
return this.gherkinStepById.get(gherkinStepId)
}
}
Loading

0 comments on commit 503e7b3

Please sign in to comment.