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

Implement writer::Json (#127) #159

Merged
merged 6 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ jobs:
strategy:
fail-fast: false
matrix:
feature: ["<none>", "macros", "timestamps", "output-junit"]
feature:
- <none>
- macros
- timestamps
- output-json
- output-junit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ All user visible changes to `cucumber` crate will be documented in this file. Th
### Added

- Ability for step functions to return `Result`. ([#151])
- Arbitrary output for `writer::Basic` ([#147])
- `writer::JUnit` ([JUnit XML report][0110-1]) behind the `output-junit` feature flag ([#147])
- Arbitrary output for `writer::Basic`. ([#147])
- `writer::JUnit` ([JUnit XML report][0110-1]) behind the `output-junit` feature flag. ([#147])
- `writer::Json` ([Cucumber JSON format][0110-2]) behind the `output-json` feature flag. ([#159])

[#147]: /../../pull/147
[#151]: /../../pull/151
[#159]: /../../pull/159
[0110-1]: https://llg.cubic.org/docs/junit
[0110-2]: https://github.com/cucumber/cucumber-json-schema



Expand Down
14 changes: 13 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repository = "https://github.com/cucumber-rs/cucumber"
readme = "README.md"
categories = ["asynchronous", "development-tools::testing"]
keywords = ["cucumber", "testing", "bdd", "atdd", "async"]
include = ["/src/", "/tests/junit.rs", "/tests/wait.rs", "/LICENSE-*", "/README.md", "/CHANGELOG.md"]
include = ["/src/", "/tests/json.rs", "/tests/junit.rs", "/tests/wait.rs", "/LICENSE-*", "/README.md", "/CHANGELOG.md"]

[package.metadata.docs.rs]
all-features = true
Expand All @@ -29,6 +29,8 @@ rustdoc-args = ["--cfg", "docsrs"]
default = ["macros"]
# Enables step attributes and auto-wiring.
macros = ["cucumber-codegen", "inventory"]
# Enables support for outputting in Cucumber JSON format.
output-json = ["Inflector", "serde", "serde_json", "timestamps"]
# Enables support for outputting JUnit XML report.
output-junit = ["junit-report", "timestamps"]
# Enables timestamps collecting for all events.
Expand All @@ -54,6 +56,11 @@ structopt = "0.3.25"
cucumber-codegen = { version = "0.11.0-dev", path = "./codegen", optional = true }
inventory = { version = "0.1.10", optional = true }

# "output-json" feature dependencies
serde = { version = "1.0", features = ["derive"], optional = true }
serde_json = { version = "1.0", optional = true }
Inflector = { version = "0.11", default-features = false, optional = true }

# "output-junit" feature dependencies
junit-report = { version = "0.7", optional = true }

Expand All @@ -62,6 +69,11 @@ humantime = "2.1"
tempfile = "3.2"
tokio = { version = "1.12", features = ["macros", "rt-multi-thread", "time"] }

[[test]]
name = "json"
required-features = ["output-json"]
harness = false

[[test]]
name = "junit"
required-features = ["output-junit"]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ For more examples check out the Book ([current][1] | [edge][2]).

- `macros` (default): Enables step attributes and auto-wiring.
- `timestamps`: Enables timestamps collecting for all [Cucumber] events.
- `output-json` (implies `timestamps`): Enables support for outputting in [Cucumber JSON format].
- `output-junit` (implies `timestamps`): Enables support for outputting [JUnit XML report].


Expand Down Expand Up @@ -132,6 +133,7 @@ at your option.


[Cucumber]: https://cucumber.io
[Cucumber JSON format]: https://github.com/cucumber/cucumber-json-schema
[Gherkin]: https://cucumber.io/docs/gherkin/reference
[JUnit XML report]: https://llg.cubic.org/docs/junit

Expand Down
44 changes: 44 additions & 0 deletions book/src/Features.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,50 @@ World::cucumber()



## Cucumber JSON format output

Library provides an ability to output tests result in a [Cucumber JSON format].

Just enable `output-json` library feature in your `Cargo.toml`:
```toml
cucumber = { version = "0.11", features = ["output-json"] }
```

And configure [Cucumber]'s output to `writer::Json`:
```rust
# use std::{convert::Infallible, fs, io};
#
# use async_trait::async_trait;
# use cucumber::WorldInit;
use cucumber::writer;

# #[derive(Debug, WorldInit)]
# struct World;
#
# #[async_trait(?Send)]
# impl cucumber::World for World {
# type Error = Infallible;
#
# async fn new() -> Result<Self, Self::Error> {
# Ok(World)
# }
# }
#
# #[tokio::main]
# async fn main() -> io::Result<()> {
let file = fs::File::create(dbg!(format!("{}/target/schema.json", env!("CARGO_MANIFEST_DIR"))))?;
World::cucumber()
.with_writer(writer::Json::new(file))
.run("tests/features/book")
.await;
# Ok(())
# }
```




[Cucumber]: https://cucumber.io
[Cucumber JSON format]: https://github.com/cucumber/cucumber-json-schema
[Gherkin]: https://cucumber.io/docs/gherkin
[JUnit XML report]: https://llg.cubic.org/docs/junit
2 changes: 1 addition & 1 deletion book/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ publish = false

[dependencies]
async-trait = "0.1"
cucumber = { version = "0.11.0-dev", path = "../..", features = ["output-junit"] }
cucumber = { version = "0.11.0-dev", path = "../..", features = ["output-json", "output-junit"] }
futures = "0.3"
skeptic = "0.13"
tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] }
Expand Down
Loading