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

Vite dev serve not passing defaults to cypress executor #13944

Closed
wingy3181 opened this issue Dec 21, 2022 · 7 comments · Fixed by #14304
Closed

Vite dev serve not passing defaults to cypress executor #13944

wingy3181 opened this issue Dec 21, 2022 · 7 comments · Fixed by #14304
Assignees
Labels
blocked: retry with latest Retry with latest release or head. outdated scope: bundlers Issues related to webpack, rollup type: bug

Comments

@wingy3181
Copy link

Current Behavior

Running nx run app-e2e:e2e when using @nrwl/vite package for build + serving with cypress to execute the e2e tests
does not pass the baseUrl appropriately to the cypress e2e executor when the vite config does not specify a host under the server key config.

See https://github.com/nrwl/nx/blob/master/packages/vite/src/executors/dev-server/dev-server.impl.ts

server: {
+    host: 'localhost',
    port: 3000,

Expected Behavior

Should automatically pick up the value from default values for vite config? (See https://vitejs.dev/config/server-options.html)

As per https://nx.dev/packages/cypress/executors/cypress#providing-a-base-url

If devServerTarget is provided, the url returned from started the dev server will be passed to cypress as the baseUrl option.

Github Repo

No response

Steps to Reproduce

  1. Setup repo with app + e2e using vite + cypress
  2. Execute nx run app:e2e and it should fail waiting for

Nx Report

$ nx report

 >  NX   Report complete - copy this into the issue template

   Node : 16.18.0
   OS   : darwin x64
   yarn : 1.22.19
   
   nx : 15.3.3
   @nrwl/angular : Not Found
   @nrwl/cypress : 15.0.10
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.0.10
   @nrwl/esbuild : 15.0.10
   @nrwl/eslint-plugin-nx : 15.0.10
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.0.10
   @nrwl/js : 15.0.10
   @nrwl/linter : 15.0.10
   @nrwl/nest : Not Found
   @nrwl/next : 15.0.10
   @nrwl/node : 15.0.10
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 15.0.10
   @nrwl/react-native : Not Found
   @nrwl/rollup : 15.0.10
   @nrwl/schematics : Not Found
   @nrwl/storybook : 15.0.10
   @nrwl/web : 15.0.10
   @nrwl/webpack : 15.0.10
   @nrwl/workspace : 15.0.10
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:
         @nrwl/vite: 15.3.0

Failure Logs

➜  Local:   http://localhost:3000/
  ➜  Network: http://192.168.1.187:3000/
Cypress could not verify that this server is running:

  > http://undefined:3000

We are verifying this server because it has been configured as your baseUrl.

Cypress automatically waits until your server is accessible before running tests.

We will try connecting to it 3 more times...
We will try connecting to it 2 more times...

Additional Information

No response

@FrozenPandaz FrozenPandaz added the scope: bundlers Issues related to webpack, rollup label Dec 22, 2022
@mandarini mandarini self-assigned this Jan 3, 2023
@mandarini
Copy link
Member

mandarini commented Jan 3, 2023

Hi @wingy3181 ! I see you are using version 15.0.10. Can you please retry with the latest version of Nx? We are passing the baseUrl and it should work as you are expecting it to.

Here's the PR that fixed it. #13219

@mandarini mandarini added the blocked: retry with latest Retry with latest release or head. label Jan 3, 2023
@wingy3181
Copy link
Author

@mandarini thanks for the suggestion..... i just tried updating the latest version as per https://nx.dev/core-features/automate-updating-dependencies

and the removed the configuration of he host to localhost within the vite.config.ts

still not workign without it.....

If I have sometime I'll see if I can setup a blank workspace to recreate the issue.........it's a bit hard without a failing example

@mandarini
Copy link
Member

Hi there @wingy3181 ! Yes please, if you have time, please do make a reproduction. It will be very very helpful for me! :)

@wingy3181
Copy link
Author

wingy3181 commented Jan 10, 2023

Hi @mandarini,
See the following repo https://github.com/wingy3181/react-cypress-vite-15-4-5
and just run nx run my-app-e2e:e2e which leads to the following:

$ npx nx run my-app-e2e:e2e

> nx run my-app-e2e:e2e

  ➜  Local:   http://localhost:4200/
  ➜  Network: use --host to expose
Cypress could not verify that this server is running:

  > http://undefined:4200

We are verifying this server because it has been configured as your baseUrl.

Cypress automatically waits until your server is accessible before running tests.

We will try connecting to it 3 more times...
We will try connecting to it 2 more times...

Unless I am interpreting the docs incorrectly from https://nx.dev/packages/cypress/executors/cypress#providing-a-base-url

EDIT: Ah i think i forgot to include the information of what vite's default host is...https://vitejs.dev/config/server-options.html#server-host. So when the vite config host is not provided, vite will default the value to 'localhost'. This is not picked up by the cypress executor as the baseUrl and why it is left as undefined

@mandarini
Copy link
Member

mandarini commented Jan 11, 2023

Ahhh yeah, that's it! @barbados-clemens do you think we should default to localhost if no host is provided? Should the change be on the vite side or on the cypress side? Or no change?

@barbados-clemens
Copy link
Contributor

It should be on the vite side @mandarini as if no baseUrl is passed nor one in the executor options, @nrwl/cypress falls back to letting cypress resolve the value from the cypress configuration file. So if we always default to localhost, then the value in cypress configuration file will not be able to be used, which we don't want to prevent.

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: retry with latest Retry with latest release or head. outdated scope: bundlers Issues related to webpack, rollup type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants