Skip to content

Commit

Permalink
Refactor everything about Cucumber messages
Browse files Browse the repository at this point in the history
Messages are no longer lingering in the runtime, but passed along to the
backend using tasks immediately. This is a prerequisite for the
following issues:

 - 810 [1]
 - 824 [2]
 - 944 [3]

This is not to say that these will be fixed shortly or even at all, but
at least now it will be remotely possible.

Furthermore, this removes any doubt regarding whether reports work in
interactive mode. The experimental flag simply turns out to be too
broken [4-5]. Interactive mode is now detected and reports turned off.

Lastly, detecting interactive mode is a somewhat broken feature [6]. The
workaround (using `isTextTerminal`) is only available in Cypress v10 and
beyond. Thus is Cypress v9 now unsupported.

[1] #810
[2] #824
[3] #944
[4] cypress-io/cypress#18955
[5] cypress-io/cypress#26634
[6] cypress-io/cypress#20789
  • Loading branch information
badeball committed May 1, 2023
1 parent 870207d commit abc3467
Show file tree
Hide file tree
Showing 20 changed files with 650 additions and 396 deletions.
2 changes: 0 additions & 2 deletions augmentations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ declare module "@cucumber/cucumber" {

declare global {
namespace globalThis {
var __cypress_cucumber_preprocessor_dont_use_this: true | undefined;

var __cypress_cucumber_preprocessor_registry_dont_use_this:
| Registry
| undefined;
Expand Down
2 changes: 1 addition & 1 deletion docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ You may have stumbled upon a configuration caveat (see [docs/configuration.md: C

## JSON reports aren't generated in open / interactive mode

JSON reports aren't typically generated in open / interactive mode. They rely on some events that aren't available in open-mode, at least not without `experimentalInteractiveRunEvents: true`. However, this experimental flag broke some time ago, ref. [cypress-io/cypress#18955](https://github.com/cypress-io/cypress/issues/18955).
JSON reports aren't generated in open / interactive mode. They rely on some events that aren't available in open-mode, at least not without `experimentalInteractiveRunEvents: true`. However, this experimental flag broke some time ago, ref. [cypress-io/cypress#18955](https://github.com/cypress-io/cypress/issues/18955), [cypress-io/cypress#26634](https://github.com/cypress-io/cypress/issues/26634). There's unfortunately little indication that these issues will be fixed and meanwhile reports will not be available in open / interactive mode.

## I get `cypress_esbuild_preprocessor_1.createBundler is not a function`

Expand Down
4 changes: 2 additions & 2 deletions features/fixtures/attachments/screenshot.ndjson
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{"source":{"data":"Feature: a feature\n Scenario: a scenario\n Given a step","uri":"cypress/e2e/a.feature","mediaType":"text/x.cucumber.gherkin+plain"}}
{"gherkinDocument":{"feature":{"tags":[],"location":{"line":1,"column":1},"language":"en","keyword":"Feature","name":"a feature","description":"","children":[{"scenario":{"id":"id","tags":[],"location":{"line":2,"column":3},"keyword":"Scenario","name":"a scenario","description":"","steps":[{"id":"id","location":{"line":3,"column":5},"keyword":"Given ","keywordType":"Context","text":"a step"}],"examples":[]}}]},"comments":[],"uri":"cypress/e2e/a.feature"}}
{"pickle":{"id":"id","uri":"cypress/e2e/a.feature","astNodeIds":["id"],"tags":[],"name":"a scenario","language":"en","steps":[{"id":"id","text":"a step","type":"Context","astNodeIds":["id"]}]}}
{"stepDefinition":{"id":"id","pattern":{"source":"a step","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"stepDefinition":{"id":"id","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a step"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"testCase":{"id":"id","pickleId":"id","testSteps":[{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]}]}}
{"testCaseStarted":{"id":"id","testCaseId":"id","attempt":0,"timestamp":{"seconds":0,"nanos":0}}}
{"attachment":{"testCaseStartedId": "id", "testStepId":"id","body":"iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAM0lEQVR4Aa3BAQEAAAiDMKR/51uC7QYjJDGJSUxiEpOYxCQmMYlJTGISk5jEJCYxiUnsARwEAibDACoRAAAAAElFTkSuQmCC","mediaType":"image/png","contentEncoding":"BASE64"}}
{"testStepStarted":{"testStepId":"id","testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0}}}
{"attachment":{"testCaseStartedId":"id","testStepId":"id","body":"iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAM0lEQVR4Aa3BAQEAAAiDMKR/51uC7QYjJDGJSUxiEpOYxCQmMYlJTGISk5jEJCYxiUnsARwEAibDACoRAAAAAElFTkSuQmCC","mediaType":"image/png","contentEncoding":"BASE64"}}
{"testStepFinished":{"testStepId":"id","testCaseStartedId":"id","testStepResult":{"status":"PASSED","duration":0},"timestamp":{"seconds":0,"nanos":0}}}
{"testCaseFinished":{"testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0},"willBeRetried":false}}
{"testRunFinished":{"timestamp":{"seconds":0,"nanos":0}}}
4 changes: 2 additions & 2 deletions features/fixtures/failing-step.ndjson
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{"source":{"data":"Feature: a feature\n Scenario: a scenario\n Given a failing step\n And another step","uri":"cypress/e2e/a.feature","mediaType":"text/x.cucumber.gherkin+plain"}}
{"gherkinDocument":{"feature":{"tags":[],"location":{"line":1,"column":1},"language":"en","keyword":"Feature","name":"a feature","description":"","children":[{"scenario":{"id":"id","tags":[],"location":{"line":2,"column":3},"keyword":"Scenario","name":"a scenario","description":"","steps":[{"id":"id","location":{"line":3,"column":5},"keyword":"Given ","keywordType":"Context","text":"a failing step"},{"id":"id","location":{"line":4,"column":5},"keyword":"And ","keywordType":"Conjunction","text":"another step"}],"examples":[]}}]},"comments":[],"uri":"cypress/e2e/a.feature"}}
{"pickle":{"id":"id","uri":"cypress/e2e/a.feature","astNodeIds":["id"],"tags":[],"name":"a scenario","language":"en","steps":[{"id":"id","text":"a failing step","type":"Context","astNodeIds":["id"]},{"id":"id","text":"another step","type":"Context","astNodeIds":["id"]}]}}
{"stepDefinition":{"id":"id","pattern":{"source":"a step","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"stepDefinition":{"id":"id","pattern":{"source":"a step","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"stepDefinition":{"id":"id","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a failing step"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"stepDefinition":{"id":"id","pattern":{"type":"CUCUMBER_EXPRESSION","source":"another step"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"testCase":{"id":"id","pickleId":"id","testSteps":[{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]},{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]}]}}
{"testCaseStarted":{"id":"id","testCaseId":"id","attempt":0,"timestamp":{"seconds":0,"nanos":0}}}
{"testStepStarted":{"testStepId":"id","testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0}}}
Expand Down
3 changes: 1 addition & 2 deletions features/fixtures/passed-outline.ndjson
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
{"gherkinDocument":{"feature":{"tags":[],"location":{"line":1,"column":1},"language":"en","keyword":"Feature","name":"a feature","description":"","children":[{"scenario":{"id":"id","tags":[],"location":{"line":2,"column":3},"keyword":"Scenario Outline","name":"a scenario","description":"","steps":[{"id":"id","location":{"line":3,"column":5},"keyword":"Given ","keywordType":"Context","text":"a step"}],"examples":[{"id":"id","tags":[],"location":{"line":4,"column":5},"keyword":"Examples","name":"","description":"","tableHeader":{"id":"id","location":{"line":5,"column":7},"cells":[{"location":{"line":5,"column":9},"value":"value"}]},"tableBody":[{"id":"id","location":{"line":6,"column":7},"cells":[{"location":{"line":6,"column":9},"value":"foo"}]},{"id":"id","location":{"line":7,"column":7},"cells":[{"location":{"line":7,"column":9},"value":"bar"}]}]}]}}]},"comments":[],"uri":"cypress/e2e/a.feature"}}
{"pickle":{"id":"id","uri":"cypress/e2e/a.feature","astNodeIds":["id","id"],"name":"a scenario","language":"en","steps":[{"id":"id","text":"a step","type":"Context","astNodeIds":["id","id"]}],"tags":[]}}
{"pickle":{"id":"id","uri":"cypress/e2e/a.feature","astNodeIds":["id","id"],"name":"a scenario","language":"en","steps":[{"id":"id","text":"a step","type":"Context","astNodeIds":["id","id"]}],"tags":[]}}
{"stepDefinition":{"id":"id","pattern":{"source":"a step","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"stepDefinition":{"id":"id","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a step"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"testCase":{"id":"id","pickleId":"id","testSteps":[{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]}]}}
{"stepDefinition":{"id":"id","pattern":{"source":"a step","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"testCase":{"id":"id","pickleId":"id","testSteps":[{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]}]}}
{"testCaseStarted":{"id":"id","testCaseId":"id","attempt":0,"timestamp":{"seconds":0,"nanos":0}}}
{"testStepStarted":{"testStepId":"id","testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0}}}
Expand Down
6 changes: 3 additions & 3 deletions features/fixtures/pending-steps.ndjson
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{"source":{"data":"Feature: a feature\n Scenario: a scenario\n Given a pending step\n And another pending step\n And an implemented step","uri":"cypress/e2e/a.feature","mediaType":"text/x.cucumber.gherkin+plain"}}
{"gherkinDocument":{"feature":{"tags":[],"location":{"line":1,"column":1},"language":"en","keyword":"Feature","name":"a feature","description":"","children":[{"scenario":{"id":"id","tags":[],"location":{"line":2,"column":3},"keyword":"Scenario","name":"a scenario","description":"","steps":[{"id":"id","location":{"line":3,"column":5},"keyword":"Given ","keywordType":"Context","text":"a pending step"},{"id":"id","location":{"line":4,"column":5},"keyword":"And ","keywordType":"Conjunction","text":"another pending step"},{"id":"id","location":{"line":5,"column":5},"keyword":"And ","keywordType":"Conjunction","text":"an implemented step"}],"examples":[]}}]},"comments":[],"uri":"cypress/e2e/a.feature"}}
{"pickle":{"id":"id","uri":"cypress/e2e/a.feature","astNodeIds":["id"],"tags":[],"name":"a scenario","language":"en","steps":[{"id":"id","text":"a pending step","type":"Context","astNodeIds":["id"]},{"id":"id","text":"another pending step","type":"Context","astNodeIds":["id"]},{"id":"id","text":"an implemented step","type":"Context","astNodeIds":["id"]}]}}
{"stepDefinition":{"id":"id","pattern":{"source":"a step","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"stepDefinition":{"id":"id","pattern":{"source":"a step","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"stepDefinition":{"id":"id","pattern":{"source":"a step","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"stepDefinition":{"id":"id","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a pending step"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"stepDefinition":{"id":"id","pattern":{"type":"CUCUMBER_EXPRESSION","source":"another pending step"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"stepDefinition":{"id":"id","pattern":{"type":"CUCUMBER_EXPRESSION","source":"an implemented step"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"testCase":{"id":"id","pickleId":"id","testSteps":[{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]},{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]},{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]}]}}
{"testCaseStarted":{"id":"id","testCaseId":"id","attempt":0,"timestamp":{"seconds":0,"nanos":0}}}
{"testStepStarted":{"testStepId":"id","testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0}}}
Expand Down
3 changes: 0 additions & 3 deletions features/fixtures/rescued-error.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
"result": {
"status": "unknown",
"duration": 0
},
"match": {
"location": "not available:0"
}
}
],
Expand Down
5 changes: 2 additions & 3 deletions features/fixtures/rescued-error.ndjson
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
{"source":{"data":"Feature: a feature\n Scenario: a scenario\n Given a failing step\n And an unimplemented step","uri":"cypress/e2e/a.feature","mediaType":"text/x.cucumber.gherkin+plain"}}
{"gherkinDocument":{"feature":{"tags":[],"location":{"line":1,"column":1},"language":"en","keyword":"Feature","name":"a feature","description":"","children":[{"scenario":{"id":"id","tags":[],"location":{"line":2,"column":3},"keyword":"Scenario","name":"a scenario","description":"","steps":[{"id":"id","location":{"line":3,"column":5},"keyword":"Given ","keywordType":"Context","text":"a failing step"},{"id":"id","location":{"line":4,"column":5},"keyword":"And ","keywordType":"Conjunction","text":"an unimplemented step"}],"examples":[]}}]},"comments":[],"uri":"cypress/e2e/a.feature"}}
{"pickle":{"id":"id","uri":"cypress/e2e/a.feature","astNodeIds":["id"],"tags":[],"name":"a scenario","language":"en","steps":[{"id":"id","text":"a failing step","type":"Context","astNodeIds":["id"]},{"id":"id","text":"an unimplemented step","type":"Context","astNodeIds":["id"]}]}}
{"stepDefinition":{"id":"id","pattern":{"source":"a step","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"stepDefinition":{"id":"id","pattern":{"source":"a step","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"testCase":{"id":"id","pickleId":"id","testSteps":[{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]},{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]}]}}
{"stepDefinition":{"id":"id","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a failing step"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"testCase":{"id":"id","pickleId":"id","testSteps":[{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]},{"id":"id","pickleStepId":"id","stepDefinitionIds":[]}]}}
{"testCaseStarted":{"id":"id","testCaseId":"id","attempt":0,"timestamp":{"seconds":0,"nanos":0}}}
{"testStepStarted":{"testStepId":"id","testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0}}}
{"testStepStarted":{"testStepId":"id","testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0}}}
Expand Down
6 changes: 0 additions & 6 deletions features/fixtures/undefined-steps.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
"result": {
"status": "undefined",
"duration": 0
},
"match": {
"location": "not available:0"
}
},
{
Expand All @@ -30,9 +27,6 @@
"result": {
"status": "skipped",
"duration": 0
},
"match": {
"location": "not available:0"
}
}
],
Expand Down
5 changes: 2 additions & 3 deletions features/fixtures/undefined-steps.ndjson
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
{"source":{"data":"Feature: a feature\n Scenario: a scenario\n Given an undefined step\n And another step","uri":"cypress/e2e/a.feature","mediaType":"text/x.cucumber.gherkin+plain"}}
{"gherkinDocument":{"feature":{"tags":[],"location":{"line":1,"column":1},"language":"en","keyword":"Feature","name":"a feature","description":"","children":[{"scenario":{"id":"id","tags":[],"location":{"line":2,"column":3},"keyword":"Scenario","name":"a scenario","description":"","steps":[{"id":"id","location":{"line":3,"column":5},"keyword":"Given ","keywordType":"Context","text":"an undefined step"},{"id":"id","location":{"line":4,"column":5},"keyword":"And ","keywordType":"Conjunction","text":"another step"}],"examples":[]}}]},"comments":[],"uri":"cypress/e2e/a.feature"}}
{"pickle":{"id":"id","uri":"cypress/e2e/a.feature","astNodeIds":["id"],"tags":[],"name":"a scenario","language":"en","steps":[{"id":"id","text":"an undefined step","type":"Context","astNodeIds":["id"]},{"id":"id","text":"another step","type":"Context","astNodeIds":["id"]}]}}
{"stepDefinition":{"id":"id","pattern":{"source":"a step","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"stepDefinition":{"id":"id","pattern":{"source":"a step","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"testCase":{"id":"id","pickleId":"id","testSteps":[{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]},{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]}]}}
{"stepDefinition":{"id":"id","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a defined step"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
{"testCase":{"id":"id","pickleId":"id","testSteps":[{"id":"id","pickleStepId":"id","stepDefinitionIds":[]},{"id":"id","pickleStepId":"id","stepDefinitionIds":[]}]}}
{"testCaseStarted":{"id":"id","testCaseId":"id","attempt":0,"timestamp":{"seconds":0,"nanos":0}}}
{"testStepStarted":{"testStepId":"id","testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0}}}
{"testStepFinished":{"testStepId":"id","testCaseStartedId":"id","testStepResult":{"status":"UNDEFINED","duration":0},"timestamp":{"seconds":0,"nanos":0}}}
Expand Down
3 changes: 2 additions & 1 deletion features/reporters/messages.feature
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ Feature: messages report
Given additional Cypress configuration
"""
{
"screenshotOnRunFailure": false
"screenshotOnRunFailure": false,
"experimentalInteractiveRunEvents": true
}
"""
And a file named "cypress/e2e/a.feature" with:
Expand Down
21 changes: 15 additions & 6 deletions lib/add-cucumber-preprocessor-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,26 @@ import {
import { INTERNAL_PROPERTY_NAME, INTERNAL_SUITE_PROPERTIES } from "./constants";

import {
TASK_APPEND_MESSAGES,
TASK_SPEC_ENVELOPES,
TASK_CREATE_STRING_ATTACHMENT,
TASK_TEST_CASE_STARTED,
TASK_TEST_STEP_STARTED,
TASK_TEST_STEP_FINISHED,
TASK_TEST_CASE_FINISHED,
} from "./cypress-task-definitions";

import {
afterRunHandler,
afterScreenshotHandler,
afterSpecHandler,
appendMessagesHandler,
specEnvelopesHandler,
beforeRunHandler,
beforeSpecHandler,
createStringAttachmentHandler,
testCaseStartedHandler,
testStepStartedHandler,
testStepFinishedHandler,
testCaseFinishedHandler,
} from "./plugin-event-handlers";

import { resolve as origResolve } from "./preprocessor-configuration";
Expand Down Expand Up @@ -107,10 +111,15 @@ export default async function addCucumberPreprocessorPlugin(
}

on("task", {
[TASK_APPEND_MESSAGES]: appendMessagesHandler,
[TASK_TEST_CASE_STARTED]: testCaseStartedHandler,
[TASK_TEST_STEP_STARTED]: testStepStartedHandler,
[TASK_CREATE_STRING_ATTACHMENT]: createStringAttachmentHandler,
[TASK_SPEC_ENVELOPES]: specEnvelopesHandler.bind(null, config),
[TASK_TEST_CASE_STARTED]: testCaseStartedHandler.bind(null, config),
[TASK_TEST_STEP_STARTED]: testStepStartedHandler.bind(null, config),
[TASK_TEST_STEP_FINISHED]: testStepFinishedHandler.bind(null, config),
[TASK_TEST_CASE_FINISHED]: testCaseFinishedHandler.bind(null, config),
[TASK_CREATE_STRING_ATTACHMENT]: createStringAttachmentHandler.bind(
null,
config
),
});

const tags = getTags(config.env);
Expand Down
Loading

0 comments on commit abc3467

Please sign in to comment.