question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`--config` changes working directory, Cypress 9 -> 10/11/12

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
AriPerkkiocommented, Aug 11, 2022

@gsouf that’s best solution for now.

I really want to keep Cypress configuration file under a sub directory config/ since that’s where I store configuration files for all sorts of tooling. So as a work-around I’m now using a separate configuration file in project root which simply imports the actual config. This way I don’t need to apply any other work-arounds, e.g. prefixing all paths with .../../ or running process.chdir() anywhere.

<project-root>
β”œβ”€β”€ cypress.config.ts
└── config
   └── cypress
      └── cypress.config.ts
// TODO: Remove when https://github.com/cypress-io/cypress/issues/22689 is fixed
export { default } from './config/cypress/cypress.config';
0reactions
gsoufcommented, Aug 11, 2022

@jhpedemonte maybe it is simpler to keep the config file at the root until this is fixed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration - Cypress Documentation
This gives you the ability to change configuration options without modifying any code or build scripts. For example, these enviroment variables in the...
Read more >
cypress-io/cypress - CircleCI Developer Hub
Run your Cypress.io end-to-end & component tests without spending time configuring CircleCI. This orb can also record results on the Cypress ...
Read more >
Integrate Cypress with Universal Agent - Tricentis
For Windows, open the command prompt. Navigate to the source code folder. For Mac or Linux, navigate to cd /usr/local/var/cypress-sample ...
Read more >
Configurations in Cypress and How to Disable Default ...
What are the default Configurations for folder/files provided by ... Cypress provides two ways to override/change the configuration values:.
Read more >
Tutorial - Set up fullstack project - Vue - AWS Amplify Docs
12345678910111213141516. npm init vue@3 Need to install the following packages: create-vue@3 Ok to proceed? (y) y βœ“ Project name: … myamplifyproject βœ“ AddΒ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found