Skip to content

Commit

Permalink
Provide a cucumber-js example
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekthompson committed Apr 25, 2024
0 parents commit c150f95
Show file tree
Hide file tree
Showing 9 changed files with 1,936 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .captain/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test-suites:
captain-examples-cucumber-js:
command: npx cucumber-js --format message:tmp/cucumber.json --format summary
results:
path: tmp/cucumber.json
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "Captain Cucumber Integration Example"
on:
- push

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: 22.x
- uses: rwx-research/setup-captain@v1
- run: npm install
- run: captain run captain-examples-cucumber-js
env:
RWX_ACCESS_TOKEN: ${{ secrets.RWX_ACCESS_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
tmp
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT LICENSE

Copyright (c) 2022 ReadWriteExecute, Inc. and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Getting Captain working with Cucumber

To configure cucumber-js such that it works with Captain, we need to:

1. 🧪 Ensure cucumber produces json output

`cucumber-js --format messages:tmp/cucumber.jsonl` will produce Captain-compatible JSON output in `tmp/cucumber.jsonl`.
To ensure GitHub logs continue to have test output, also include a stdout-friendly formatter (for example, `--format summary`)

```yaml
# .captain/config.yaml
test-suites:
captain-examples-cucumber-js:
command: cucumber-js --format message:tmp/cucumber.json --format summary
results:
path: tmp/cucumber.json
```
2. 🔐 Create an Access Token
Create an Access Token for your organization within [Captain][captain] ([more documentation here][create-access-token]).
Add the new token as an action secret to your repository. Conventionally, we call this secret `RWX_ACCESS_TOKEN`.

3. 💌 Install the Captain CLI, and then call it when running tests

See the [full documentation on test suite integration][test-suite-integration].

```yaml
- uses: rwx-research/setup-captain@v1
- run: captain run captain-examples-cucumber-js
env:
RWX_ACCESS_TOKEN: ${{ secrets.RWX_ACCESS_TOKEN }}
```

4. 🎉 See your test results in Captain!

Take a look at the [final workflow!][workflow-with-captain]

[captain]: https://account.rwx.com/deep_link/manage/access_tokens
[create-access-token]: https://www.rwx.com/docs/access-tokens
[workflow-with-captain]: https://github.com/captain-examples/cucumber-ruby/blob/main/.github/workflows/ci.yml
[test-suite-integration]: https://www.rwx.com/captain/docs/test-suite-integration
44 changes: 44 additions & 0 deletions features/rule.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@feature_tag
Feature: Rule Sample

@rule_tag
Rule: This is a rule

Example: A passing example
Given this will pass
When I do an action
Then some results should be there

@failing
Example: A failing example
Given this will fail
When I do an action
Then some results should be there

Example: A pending example
Given this is pending
When I do an action
Then nothing should happen

Example: A skipped example
Given this is skipped
When I do an action
Then nothing should happen

Example: An undefined example
Given this is undefined
When I do an action
Then nothing should happen

@failing_before_hook
Example: With a failing before hook
Given this will pass
When I do an action
Then some results should be there


@failing_after_hook
Example: With a failing after hook
Given this will pass
When I do an action
Then some results should be there
32 changes: 32 additions & 0 deletions features/support/steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const assert = require("assert");
const { After, Before, Given, When, Then } = require("@cucumber/cucumber");

Given("this will pass", function () {
this.this_will_pass = true;
});

Given("this will fail", function () {
this.this_will_pass = false;
});

When("I do an action", function () {});

Then("some results should be there", function () {
assert(this.this_will_pass === true);
});

Given("this is pending", function () {
return "pending";
});

Given(/skip/, function () {
return "skipped";
});

Before("@failing_before_hook", function (scenario) {
throw new Error("failed in before hook");
});

After("@failing_after_hook", function (scenario) {
throw new Error("failed in after hook");
});
Loading

0 comments on commit c150f95

Please sign in to comment.