Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(testing): support vite configOverrides for cypress #26554

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

TimvdEijnden
Copy link
Contributor

@TimvdEijnden TimvdEijnden commented Jun 14, 2024

We'd like to use shared cypress commands, but that's currently not working because vite cannot resolve the import.
By allowing to pass options to the vite config we have the possibility to add an alias or a plugin to fix this.

This adds support for an optional viteConfigOverrides object.

Current Behavior

Screenshot 2024-06-14 at 15 19 21

cypress.config.ts:

import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';

export default defineConfig({
  e2e: {
    ...nxE2EPreset(__filename, { cypressDir: 'cypress', bundler: 'vite' }),
  },
});

Expected Behavior

Screenshot 2024-06-14 at 15 23 56

cypress.config.ts:

import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';

const viteConfigOverrides = {
  resolve: {
    alias: {
      '@cypress-shared-commands': '../../../shared-cypress-commands',
    },
  },
};

export default defineConfig({
  e2e: {
    ...nxE2EPreset(__filename, { cypressDir: 'cypress', bundler: 'vite', viteConfigOverrides }),
  },
});

Related Issue(s)

Fixes #

@TimvdEijnden TimvdEijnden requested a review from a team as a code owner June 14, 2024 13:26
Copy link

vercel bot commented Jun 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Jul 22, 2024 3:52pm

@TimvdEijnden
Copy link
Contributor Author

TimvdEijnden commented Jun 20, 2024

@jaysoo @ndcunningham @Coly010 @isaacplmann Could someone from nx review this PR? Because we would like to make use of this feature 😃

@TimvdEijnden TimvdEijnden reopened this Jul 1, 2024
@TimvdEijnden
Copy link
Contributor Author

@AgentEnder @mandarini @FrozenPandaz @Cammisuli @jdpearce @xiongemi @MaxKless

It would be great if someone could please review this rather small change, we could really make use of it 😀

@Coly010 Coly010 force-pushed the feat/cypress-viteconfig-overrides branch from f81e18c to 1bfecfe Compare July 22, 2024 15:49
@Coly010 Coly010 enabled auto-merge (squash) July 22, 2024 15:49
@@ -40,7 +40,9 @@ const cache = new Map<string, string>();
* This preprocessor shouldn't be used directly.
* Instead, use the nxE2EPreset(__filename, { bundler: 'vite' }) function instead.
*/
function vitePreprocessor(userConfigPath?: string): CypressPreprocessor {
function vitePreprocessor(
configOverrides: InlineConfig = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usages of vitePreprocessor('/path/to/vite.config.ts') will break right? Do we need to overload the function or deprecate something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, it's an internal API. :)

@Coly010 Coly010 disabled auto-merge July 22, 2024 16:51
@jaysoo jaysoo merged commit 764ecee into nrwl:master Jul 22, 2024
6 checks passed
@TimvdEijnden
Copy link
Contributor Author

TimvdEijnden commented Jul 22, 2024

Thanks for merging 😊

FrozenPandaz pushed a commit that referenced this pull request Jul 22, 2024
We'd like to use shared cypress commands, but that's currently not
working because vite cannot resolve the import.
By allowing to pass options to the vite config we have the possibility
to add an alias or a plugin to fix this.

This adds support for an **optional** `viteConfigOverrides` object.

## Current Behavior
![Screenshot 2024-06-14 at 15 19
21](https://github.com/nrwl/nx/assets/951290/78f5037f-c839-4227-a3ea-4de4142006cf)

cypress.config.ts:
```ts
import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';

export default defineConfig({
  e2e: {
    ...nxE2EPreset(__filename, { cypressDir: 'cypress', bundler: 'vite' }),
  },
});
```

## Expected Behavior
![Screenshot 2024-06-14 at 15 23
56](https://github.com/nrwl/nx/assets/951290/385cde67-91b9-462e-9bfa-0c784d3947b7)

cypress.config.ts:
```ts
import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';

const viteConfigOverrides = {
  resolve: {
    alias: {
      '@cypress-shared-commands': '../../../shared-cypress-commands',
    },
  },
};

export default defineConfig({
  e2e: {
    ...nxE2EPreset(__filename, { cypressDir: 'cypress', bundler: 'vite', viteConfigOverrides }),
  },
});
```
## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #

(cherry picked from commit 764ecee)
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants