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

Cypress errors when shared lib is imported #883

Closed
bernardo-cs opened this issue Nov 7, 2018 · 21 comments · Fixed by #1512
Closed

Cypress errors when shared lib is imported #883

bernardo-cs opened this issue Nov 7, 2018 · 21 comments · Fixed by #1512
Assignees

Comments

@bernardo-cs
Copy link

bernardo-cs commented Nov 7, 2018

Importing from a shared lib into cypress e2e spec, breaks the build process with:

The plugins file is missing or invalid.

Your pluginsFile is set to '...dist/out-tsc/apps/my-app-e2e/src/plugins/index.js', but either the file is missing, it contains a syntax error, or threw an error when required. The pluginsFile must be a .js or .coffee file.

Please fix this, or set 'pluginsFile' to 'false' if a plugins file is not necessary for your project.

Reproduction steps

  • create-nx-workspace farm
  • ng generate jest
  • ng generate application myApp ( pick cypress )
  • ng generate lib fixtures --no-module
  • ng e2e ( everything is fine )
  • Export a const from a shared lib into a cypress spec.
  • ng e2e ( build is broken )

Reproduction Repo
https://github.com/golfadas/farm

Angular & node versions
Angular CLI: 7.0.1
Node: 10.12.0
OS: darwin x64
Angular: 7.0.2

@paesku
Copy link

paesku commented Nov 16, 2018

Hi folks, I currently struggle with a similar problem.
I'd like to have my .po-ts within my libs/foo unfortunately I face the same error as mentioned above.
Any ideas how to setup cypress to make this work?

@skorunka
Copy link

skorunka commented Nov 20, 2018

Facing same issue when referencing a code in cypress spec file from a lib folder.

@paesku
Copy link

paesku commented Jan 27, 2019

I'd like to mention, that when I move support code outside the support folder, the copy process completely messes up.

Example:

// top level
- apps
   --app-1
   --app-1-e2e
      --src
         --fixtures
         --integration
         --plugins
         --support
             app.po.ts // this file is importing and exporting code from foo.po.ts
   --po
     foo.po.ts 

Then the out-tsc will completely pull out the fixtures folder from the src folder and will look like this:

// out-tsc
- apps
   --app-1-e2e
      --src
         --app-1-e2e
            --src
               --integration
               --plugins
               --support
         --fixtures
         --po 
            foo.po.ts 

@skorunka
Copy link

skorunka commented Feb 17, 2019

No feedback from the NX team :(

@markgoho
Copy link
Contributor

For multiple apps reusing helpers, importing interfaces, etc. would be super helpful but basically everything causes the build to break. Is there anyone that could look into this?

@hevans90
Copy link

This is causing us a lot of pain, help!!

@vsavkin vsavkin assigned vsavkin and FrozenPandaz and unassigned vsavkin May 23, 2019
@yglin
Copy link

yglin commented May 31, 2019

Same problem here.

Currently to me the inconvenience is that I can not use serialization functions of my custom data types.
Such as dates, I have to convert string to date explicitly in my support file.
This makes 2 duplicate serialization code for a same data type, one in shared library and another in e2e specs.
When the custom data types grow complex this could be nightmare...

Not sure if this demand breaks the concept of e2e test: to simulate a totally ignorant user, IDK.

Please help, or can someone give a clue about how the typescript compiler arrange out-tsc/ files, when there are shared library codes imported ?

@Amakaev
Copy link

Amakaev commented Jun 5, 2019

Same issue.
Have a lib with all my app Models, can't use them in cypress.

@skydever
Copy link
Contributor

skydever commented Jun 6, 2019

this seems related to #1238

@skydever
Copy link
Contributor

skydever commented Jun 7, 2019

in #263 I shared my setup, I am using code from a lib within my cypress tests.

I think in #1238 @diginikkari also has a solution (there is a repo linked within the issue), but notice in both solutions the path mappings do not work...

@diginikkari
Copy link
Contributor

Yep, I have been sharing models with cypress and also with firebase cloud functions in my nx-workspace, but only by using relative paths, which is not optimal.

I think that now with custom builders support, I need to figure out how to make builder with using webpack for all apps in my workspace which are now using tsc. Problem is that because of angular I have been spoiled to not need to learn webpack before 😉

@FrozenPandaz
Copy link
Collaborator

Hi all, thanks for your patience waiting for a response.

I bring good news though. :)
I've been experimenting creating a Cypress plugin which would use Webpack to preprocess files. This would allow importing from tsconfig paths. 🎉

@bahmutov
Copy link

Hey, I have described how to use TypeScript type aliases in Cypress tests in this blog post: https://glebbahmutov.com/blog/using-ts-aliases-in-cypress-tests/

Hint: you need to configure both webpack and tsconfig

@markgoho
Copy link
Contributor

Hey @bahmutov thanks for sharing this article. It's super awesome to see you popping into this repo to help out. 😍

I think this may help Jason out, but for the end user, it's pretty rare for us to alter the webpack config directly. I think (and I hope Jason agrees) we're all looking for Nx to solve this in a way that doesn't require us to eject from the Angular CLI.

@FrozenPandaz
Copy link
Collaborator

FrozenPandaz commented Jun 14, 2019

@bahmutov Can we simplify this for users by making a separate package under @cypress that sets up typescript?

Here's my PoC: FrozenPandaz/demos@7f7ad57#diff-be5a146c9304da3c97d343c015bb4287R23

@bahmutov
Copy link

bahmutov commented Jun 14, 2019

We are actually switching to Webpack internally soon cypress-io/cypress#4103 - this would simplify things. Handles js, ts, coffeescript, jsx/tsx, and scss

@FrozenPandaz
Copy link
Collaborator

That's absolutely fantastic! 🎉Let me try it locally.

@FrozenPandaz
Copy link
Collaborator

Works perfectly except it cannot resolve typescript paths. Left a comment to help address this cypress-io/cypress#4103 (comment). This is super exciting!

@FrozenPandaz
Copy link
Collaborator

Nevermind. Perhaps I misunderstood @bahmutov This is only for building cypress, not the runner? Is supporting loading TS planned somewhere?

@paesku
Copy link

paesku commented Jun 25, 2019

@vsavkin @FrozenPandaz thank you so much <3

@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 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.