Skip to content

Esbuild bundled configurations that set prettySourceMap do not show code frames properly in open mode in Cypress correctly #1285

@ryanthemanuel

Description

@ryanthemanuel

Current behavior

If I take the esbuild-cjs example as is with prettySourceMap set in the configuration, and modify the test as follows:

Then("I should see a search bar", () => {
  cy.get("input[type=text]")
    .should("have.attr", "placeholdr")
    .and(
      "match",
      /Search the web without being tracked|Search without being tracked/
    );

  assert.deepEqual({}, {});
});

it fails as I would expect, but in open mode of Cypress you do not see a proper stack trace:

Image

Desired behavior

If I change the config to set sourcemap on the esbuild bundler directly:

const { defineConfig } = require("cypress");
const createBundler = require("@bahmutov/cypress-esbuild-preprocessor");
const {
  addCucumberPreprocessorPlugin,
} = require("@badeball/cypress-cucumber-preprocessor");
const {
  createEsbuildPlugin,
} = require("@badeball/cypress-cucumber-preprocessor/esbuild");

async function setupNodeEvents(on, config) {
  // This is required for the preprocessor to be able to generate JSON reports after each run, and more,
  await addCucumberPreprocessorPlugin(on, config);

  on(
    "file:preprocessor",
    createBundler({
      sourcemap: 'inline',
      plugins: [createEsbuildPlugin(config)],
    })
  );

  // Make sure to return the config object as it might have been modified by the plugin.
  return config;
}

module.exports = defineConfig({
  projectId: 'kh9ew9',
  e2e: {
    baseUrl: "https://duckduckgo.com",
    specPattern: "**/*.feature",
    setupNodeEvents,
  },
});

I get a proper stack trace:

Image

Cypress version

any

Preprocessor version

v22.0.1

Node version

v22

Operating system

macOS 14.16.1

Checklist

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions