Skip to content

diagnostics - Cypress.env is not a function when referring to env object as const #1120

@jessica-jorgenson

Description

@jessica-jorgenson

Current behavior

Upon running npx cypress-cucumber-diagnostics, I am met with the error:

TypeError: Cypress.env is not a function
    at cypress/support/appOne/pages.ts (C:\Users\JessicaJorgenson\Repos\CypressExample\.output-7bedd1.cjs:15748:22)
    at __init (C:\Users\JessicaJorgenson\Repos\CypressExample\.output-7bedd1.cjs:10:58)
    at cypress/support/appOne/step-definitions/preconditions.steps.ts (C:\Users\JessicaJorgenson\Repos\CypressExample\.output-7bedd1.cjs:15762:7)
    at __init (C:\Users\JessicaJorgenson\Repos\CypressExample\.output-7bedd1.cjs:10:58)
    at C:\Users\JessicaJorgenson\Repos\CypressExample\.output-7bedd1.cjs:15770:3
    at Object.<anonymous> (C:\Users\JessicaJorgenson\Repos\CypressExample\.output-7bedd1.cjs:15771:3)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
Error: Failed to evaluate step definitions, with errors shown above...
    at C:\Users\JessicaJorgenson\Repos\CypressExample\node_modules\@badeball\cypress-cucumber-preprocessor\dist\diagnostics\diagnose.js:110:27
    at withRegistry (C:\Users\JessicaJorgenson\Repos\CypressExample\node_modules\@badeball\cypress-cucumber-preprocessor\dist\registry.js:188:5)
    at diagnose (C:\Users\JessicaJorgenson\Repos\CypressExample\node_modules\@badeball\cypress-cucumber-preprocessor\dist\diagnostics\diagnose.js:103:52)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async execute (C:\Users\JessicaJorgenson\Repos\CypressExample\node_modules\@badeball\cypress-cucumber-preprocessor\dist\diagnostics\index.js:189:20)

When I have a constant equal to a Cypress.env value.
See here: https://github.com/jessica-jorgenson/cucumber-preprocessor-error/blob/main/cypress/support/appOne/pages.ts

When referring to the env like so: return Cypress.env("urls").main.replace("bing", "google"), the error doesn't occur.

Desired behavior

Cypress behaves as usual, so this shouldn't raise an error on cypress-cucumber-preprocessor...riiight?

Test code to reproduce

Repo: https://github.com/jessica-jorgenson/cucumber-preprocessor-error

Versions

  • Cypress version: ^13.3.0
  • Preprocessor version: ^19.0.1
  • Node version: 18.18.0

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