Skip to content

--config-file changes working directory, Cypress 9 -> 10/11/12/13 #22689

@AriPerkkio

Description

@AriPerkkio

Current behavior

In after:run task, Cypress 10 is using the location of configuration file as current working directory. In Cypress 9 it is the root of project, or where the actual cypress run command is run.

After migrating from Cypress 9 to 10 some plugins I'm using started failing. They are relying on Cypress 9's functionality when it comes to current working directory, e.g. when reading files from disk.

I keep my cypress.config.ts in a separate folder - not in the project root.

/workspaces/vite-everything
└── config
   └── cypress
      ├── component-index.html
      ├── cypress.config.ts
      ├── support.component.ts
      └── support.ts
cypress run --component --config-file config/cypress/cypress.config.ts
// config/cypress/cypress.config.ts
setupNodeEvents(on) {
    on('after:run', () => {
        console.log('[after:run] cwd is', process.cwd());
        // > [after:run] cwd is /workspaces/vite-everything/config/cypress
    });
},

Desired behavior

The current working directory should match with Cypress 9.

/workspaces/vite-everything
└── config
   └── cypress
      ├── cypress.json
      ├── plugins.ts
      └── support.ts
cypress run-ct --config-file config/cypress/cypress.json
// config/cypress/plugins.ts
on('after:run', () => {
    console.log('[after:run] cwd is', process.cwd());
    // [after:run] cwd is /workspaces/vite-everything
});

Test code to reproduce

I run into this error in separate closed source project but here is another project for reproducing the issue:

yarn # Install dependencies
yarn test:component # Run Cypress Component Test Runner

Cypress Version

10.3.0

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    E2EIssue related to end-to-end testingTriagedIssue has been routed to backlog. This is not a commitment to have it prioritized by the team.type: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions