Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: badeball/cypress-cucumber-preprocessor
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v20.0.2
Choose a base ref
...
head repository: badeball/cypress-cucumber-preprocessor
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v20.0.3
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on Mar 26, 2024

  1. Handle browser / page crash gracefully

    This fixes #1172 [1].
    
    [1] #1172
    badeball committed Mar 26, 2024
    Copy the full SHA
    622a280 View commit details
  2. v20.0.3

    badeball committed Mar 26, 2024
    Copy the full SHA
    055d8df View commit details
Showing with 125 additions and 2 deletions.
  1. +1 −1 .github/workflows/build.yml
  2. +4 −0 CHANGELOG.md
  3. +70 −0 features/browser_crash.feature
  4. +15 −0 features/step_definitions/cli_steps.ts
  5. +34 −0 lib/plugin-event-handlers.ts
  6. +1 −1 package.json
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ jobs:
needs: prepare-versions
runs-on: ubuntu-20.04
container:
image: cypress/base:20.5.0
image: cypress/browsers:node-20.5.0-chrome-114.0.5735.133-1-ff-114.0.2-edge-114.0.1823.51-1
strategy:
matrix:
cypress-version: ${{fromJson(needs.prepare-versions.outputs.matrix)}}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## v20.0.3

- Handle browser / page crash gracefully, fixes [#1172](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1172).

## v20.0.2

- Add support for skipped / pending scenario hooks, fixes [#1159](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1159).
70 changes: 70 additions & 0 deletions features/browser_crash.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
@cypress>=12
Feature: browser crash

# Crash-behavior is a mess, ref. https://github.com/cypress-io/cypress/issues/22631.
# Pre-12.17.0, enabling video recording actually made a difference, ref. https://github.com/cypress-io/cypress/pull/27167.
# Post-12.17.0 behavior seems to be consistent enough that it's testable.

Background:
Given additional preprocessor configuration
"""
{
"json": {
"enabled": true
}
}
"""

Rule: report generation should fail gracefully in the event of a browser crash

Scenario: Chromium process crash
Given a file named "cypress/e2e/a.feature" with:
"""
Feature: a feature
Scenario: a scenario
Given a step
"""
And a file named "cypress/support/step_definitions/steps.js" with:
"""
const { Given, attach } = require("@badeball/cypress-cucumber-preprocessor");
Given("a step", function() {
new Cypress.Promise(() => {
Cypress.automation("remote:debugger:protocol", {
command: "Browser.crash",
});
});
});
"""
When I run cypress with a chromium-family browser
Then it fails
And the output should contain
"""
Due to browser crash, no reports are created for cypress/e2e/a.feature.
"""
And the JSON report shouldn't contain any specs

Scenario: Renderer process crash
Given a file named "cypress/e2e/a.feature" with:
"""
Feature: a feature
Scenario: a scenario
Given a step
"""
And a file named "cypress/support/step_definitions/steps.js" with:
"""
const { Given, attach } = require("@badeball/cypress-cucumber-preprocessor");
Given("a step", function() {
new Cypress.Promise(() => {
Cypress.automation("remote:debugger:protocol", {
command: "Page.crash",
});
});
});
"""
When I run cypress with a chromium-family browser
Then it fails
And the output should contain
"""
Due to browser crash, no reports are created for cypress/e2e/a.feature.
"""
And the JSON report shouldn't contain any specs
15 changes: 15 additions & 0 deletions features/step_definitions/cli_steps.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ import * as glob from "glob";
import ICustomWorld from "../support/ICustomWorld";
import { assertAndReturn } from "../support/helpers";

const isCI = process.env.CI === "true";

function execAsync(
command: string
): Promise<{ stdout: string; stderr: string }> {
@@ -74,6 +76,19 @@ When(
}
);

When(
"I run cypress with a chromium-family browser",
{ timeout: 60 * 1000 },
async function (this: ICustomWorld) {
/**
* Chrome is installed in CI, Chromium is installed in my (maintainer) environment.
*/
await this.runCypress({
extraArgs: ["--browser", isCI ? "chrome" : "chromium"],
});
}
);

When(
"I run diagnostics",
{ timeout: 60 * 1000 },
34 changes: 34 additions & 0 deletions lib/plugin-event-handlers.ts
Original file line number Diff line number Diff line change
@@ -496,6 +496,40 @@ export async function afterSpecHandler(
return;
}

/**
* This pretty much can't happen and the check is merely to satisfy TypeScript in the next block.
*/
switch (state.state) {
case "uninitialized":
case "after-run":
throw createError("Unexpected state in afterSpecHandler: " + state.state);
}

const browserCrashExprCol = [
/We detected that the .+ process just crashed/,
/We detected that the .+ Renderer process just crashed/,
];

const error = results.error;

if (error != null && browserCrashExprCol.some((expr) => expr.test(error))) {
console.log(
chalk.yellow(
`\nDue to browser crash, no reports are created for ${spec.relative}.`
)
);

state = {
state: "after-spec",
pretty: state.pretty,
messages: {
accumulation: state.messages.accumulation,
},
};

return;
}

switch (state.state) {
case "test-finished": // This is the normal case.
case "before-spec": // This can happen if a spec doesn't contain any tests.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@badeball/cypress-cucumber-preprocessor",
"version": "20.0.2",
"version": "20.0.3",
"author": "Jonas Amundsen",
"license": "MIT",
"homepage": "https://github.com/badeball/cypress-cucumber-preprocessor",