-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#341 start refactor, use proper name of TestCaseStarted rather than P…
…ickle for handler during execution
- Loading branch information
1 parent
b540080
commit 5a1eace
Showing
55 changed files
with
1,100 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Feature: Attachments | ||
It is sometimes useful to take a screenshot while a scenario runs. | ||
Or capture some logs. | ||
|
||
Cucumber lets you `attach` arbitrary files during execution, and you can | ||
specify a content type for the contents. | ||
|
||
Formatters can then render these attachments in reports. | ||
|
||
Attachments must have a body and a content type | ||
|
||
Scenario: Strings can be attached with a media type | ||
Beware that some formatters such as @cucumber/react use the media type | ||
to determine how to display an attachment. | ||
|
||
When the string "hello" is attached as "application/octet-stream" | ||
|
||
Scenario: Log JSON | ||
When the following string is attached as "application/json": | ||
``` | ||
{"message": "The <b>big</b> question", "foo": "bar"} | ||
``` | ||
|
||
Scenario: Log text | ||
When the string "hello" is logged | ||
|
||
Scenario: Log ANSI coloured text | ||
When text with ANSI escapes is logged | ||
|
||
Scenario: Byte arrays are base64-encoded regardless of media type | ||
When an array with 10 bytes is attached as "text/plain" | ||
|
||
Scenario: Streams are always base64-encoded | ||
When a JPEG image is attached | ||
|
||
Scenario: Attaching images in examples | ||
When the <image> png is attached | ||
|
||
Examples: | ||
| image | | ||
| cucumber.png | |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Before, When } from '@cucumber/fake-cucumber' | ||
import { ReadableStreamBuffer } from 'stream-buffers' | ||
import fs from 'fs' | ||
|
||
// Cucumber-JVM needs to use a Before hook in order to create attachments | ||
Before(() => undefined) | ||
|
||
When('the string {string} is attached as {string}', function (text: string, mediaType: string) { | ||
this.attach(text, mediaType) | ||
}) | ||
|
||
When('the string {string} is logged', function (text: string) { | ||
this.log(text) | ||
}) | ||
|
||
When('text with ANSI escapes is logged', function () { | ||
this.log( | ||
'This displays a \x1b[31mr\x1b[0m\x1b[91ma\x1b[0m\x1b[33mi\x1b[0m\x1b[32mn\x1b[0m\x1b[34mb\x1b[0m\x1b[95mo\x1b[0m\x1b[35mw\x1b[0m' | ||
) | ||
}) | ||
|
||
When('the following string is attached as {string}:', function (mediaType: string, text: string) { | ||
this.attach(text, mediaType) | ||
}) | ||
|
||
When( | ||
'an array with {int} bytes is attached as {string}', | ||
function (size: number, mediaType: string) { | ||
const data = [...Array(size).keys()] | ||
const buffer = Buffer.from(data) | ||
this.attach(buffer, mediaType) | ||
} | ||
) | ||
|
||
When( | ||
'a stream with {int} bytes are attached as {string}', | ||
async function (size: number, mediaType: string) { | ||
const data = [...Array(size).keys()] | ||
const buffer = Buffer.from(data) | ||
const stream = new ReadableStreamBuffer({ chunkSize: 1, frequency: 1 }) | ||
stream.put(buffer) | ||
stream.stop() | ||
|
||
await this.attach(stream, mediaType) | ||
} | ||
) | ||
|
||
When('a JPEG image is attached', async function () { | ||
await this.attach(fs.createReadStream(__dirname + '/cucumber.png'), 'image/png') | ||
}) | ||
|
||
When('the {word} png is attached', async function (filename) { | ||
await this.attach(fs.createReadStream(__dirname + `/${filename}`), 'image/png') | ||
}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Feature: Data Tables | ||
Data Tables can be places underneath a step and will be passed as the last | ||
argument to the step definition. They can be used to represent richer data | ||
structures, and can also be transformed to other types. | ||
|
||
Scenario: transposed table | ||
When the following table is transposed: | ||
| a | b | | ||
| 1 | 2 | | ||
Then it should be: | ||
| a | 1 | | ||
| b | 2 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{"meta":{"ci":{"buildNumber":"154666429","git":{"remote":"https://github.com/cucumber-ltd/shouty.rb.git","revision":"99684bcacf01d95875834d87903dcb072306c9ad"},"name":"GitHub Actions","url":"https://github.com/cucumber-ltd/shouty.rb/actions/runs/154666429"},"cpu":{"name":"x64"},"implementation":{"name":"fake-cucumber","version":"16.0.0"},"os":{"name":"linux","version":"5.10.102.1-microsoft-standard-WSL2"},"protocolVersion":"19.1.2","runtime":{"name":"node.js","version":"16.4.0"}}} | ||
{"source":{"data":"Feature: Data Tables\n Data Tables can be places underneath a step and will be passed as the last\n argument to the step definition. They can be used to represent richer data\n structures, and can also be transformed to other types.\n\n Scenario: transposed table\n When the following table is transposed:\n | a | b |\n | 1 | 2 |\n Then it should be:\n | a | 1 |\n | b | 2 |\n","mediaType":"text/x.cucumber.gherkin+plain","uri":"samples/data-tables/data-tables.feature"}} | ||
{"gherkinDocument":{"comments":[],"feature":{"children":[{"scenario":{"description":"","examples":[],"id":"8","keyword":"Scenario","location":{"column":3,"line":6},"name":"transposed table","steps":[{"dataTable":{"location":{"column":7,"line":8},"rows":[{"cells":[{"location":{"column":9,"line":8},"value":"a"},{"location":{"column":13,"line":8},"value":"b"}],"id":"2","location":{"column":7,"line":8}},{"cells":[{"location":{"column":9,"line":9},"value":"1"},{"location":{"column":13,"line":9},"value":"2"}],"id":"3","location":{"column":7,"line":9}}]},"id":"4","keyword":"When ","keywordType":"Action","location":{"column":5,"line":7},"text":"the following table is transposed:"},{"dataTable":{"location":{"column":7,"line":11},"rows":[{"cells":[{"location":{"column":9,"line":11},"value":"a"},{"location":{"column":13,"line":11},"value":"1"}],"id":"5","location":{"column":7,"line":11}},{"cells":[{"location":{"column":9,"line":12},"value":"b"},{"location":{"column":13,"line":12},"value":"2"}],"id":"6","location":{"column":7,"line":12}}]},"id":"7","keyword":"Then ","keywordType":"Outcome","location":{"column":5,"line":10},"text":"it should be:"}],"tags":[]}}],"description":" Data Tables can be places underneath a step and will be passed as the last\n argument to the step definition. They can be used to represent richer data\n structures, and can also be transformed to other types.","keyword":"Feature","language":"en","location":{"column":1,"line":1},"name":"Data Tables","tags":[]},"uri":"samples/data-tables/data-tables.feature"}} | ||
{"pickle":{"astNodeIds":["8"],"id":"11","language":"en","name":"transposed table","steps":[{"argument":{"dataTable":{"rows":[{"cells":[{"value":"a"},{"value":"b"}]},{"cells":[{"value":"1"},{"value":"2"}]}]}},"astNodeIds":["4"],"id":"9","text":"the following table is transposed:","type":"Action"},{"argument":{"dataTable":{"rows":[{"cells":[{"value":"a"},{"value":"1"}]},{"cells":[{"value":"b"},{"value":"2"}]}]}},"astNodeIds":["7"],"id":"10","text":"it should be:","type":"Outcome"}],"tags":[],"uri":"samples/data-tables/data-tables.feature"}} | ||
{"stepDefinition":{"id":"0","pattern":{"source":"the following table is transposed:","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"location":{"line":5},"uri":"samples/data-tables/data-tables.feature.ts"}}} | ||
{"stepDefinition":{"id":"1","pattern":{"source":"it should be:","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"location":{"line":9},"uri":"samples/data-tables/data-tables.feature.ts"}}} | ||
{"testRunStarted":{"timestamp":{"nanos":0,"seconds":0}}} | ||
{"testCase":{"id":"14","pickleId":"11","testSteps":[{"id":"12","pickleStepId":"9","stepDefinitionIds":["0"],"stepMatchArgumentsLists":[{"stepMatchArguments":[]}]},{"id":"13","pickleStepId":"10","stepDefinitionIds":["1"],"stepMatchArgumentsLists":[{"stepMatchArguments":[]}]}]}} | ||
{"testCaseStarted":{"attempt":0,"id":"15","testCaseId":"14","timestamp":{"nanos":1000000,"seconds":0}}} | ||
{"testStepStarted":{"testCaseStartedId":"15","testStepId":"12","timestamp":{"nanos":2000000,"seconds":0}}} | ||
{"testStepFinished":{"testCaseStartedId":"15","testStepId":"12","testStepResult":{"duration":{"nanos":1000000,"seconds":0},"status":"PASSED"},"timestamp":{"nanos":3000000,"seconds":0}}} | ||
{"testStepStarted":{"testCaseStartedId":"15","testStepId":"13","timestamp":{"nanos":4000000,"seconds":0}}} | ||
{"testStepFinished":{"testCaseStartedId":"15","testStepId":"13","testStepResult":{"duration":{"nanos":1000000,"seconds":0},"status":"PASSED"},"timestamp":{"nanos":5000000,"seconds":0}}} | ||
{"testCaseFinished":{"testCaseStartedId":"15","timestamp":{"nanos":6000000,"seconds":0},"willBeRetried":false}} | ||
{"testRunFinished":{"success":true,"timestamp":{"nanos":7000000,"seconds":0}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { When, Then } from '@cucumber/fake-cucumber' | ||
// TODO: Figure out a better way to export this | ||
import DataTable from '@cucumber/fake-cucumber/dist/src/DataTable' | ||
|
||
When('the following table is transposed:', function (table: DataTable) { | ||
this.transposed = table.transpose() | ||
}) | ||
|
||
Then('it should be:', function (expected: DataTable) { | ||
this.transposed.diff(expected) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Feature: Examples Tables | ||
Sometimes it can be desireable to run the same scenario multiple times | ||
with different data each time. This can be done by placing an Examples | ||
section with an Examples Table underneath a Scenario, and use <placeholders> | ||
in the Scenario, matching the table headers. | ||
|
||
Scenario Outline: eating cucumbers | ||
Given there are <start> cucumbers | ||
When I eat <eat> cucumbers | ||
Then I should have <left> cucumbers | ||
|
||
@passing | ||
Examples: These are passing | ||
| start | eat | left | | ||
| 12 | 5 | 7 | | ||
| 20 | 5 | 15 | | ||
|
||
@failing | ||
Examples: These are failing | ||
| start | eat | left | | ||
| 12 | 20 | 0 | | ||
| 0 | 1 | 0 | | ||
|
||
@undefined | ||
Examples: These are undefined because the value is not an {int} | ||
| start | eat | left | | ||
| 12 | banana | 12 | | ||
| 0 | 1 | apple | |
Oops, something went wrong.