Webpack Compilation error when trying to run a ORM library inside Cypress test. #25594
Replies: 1 comment
-
I faced a similar issue in our company when trying to implement ORM-like functionality in Cypress tests. After some exploration, we decided to shift away from using full-fledged ORM libraries like MikroORM within Cypress due to the complexities introduced by browser vs. Node.js environments. Instead, we adopted a SQL query builder library—specifically, Kysely—as our solution. In our setup, the query-building logic resides on the browser side, allowing us to construct queries as objects. These queries are then serialized and sent to the Cypress back-end, where they are compiled and executed. This approach separates the concerns of query construction and execution, avoiding environment compatibility issues like the one you're encountering. This method worked well for us because it provided a clean way to dynamically generate and execute queries in tests without the need for ORM-related dependencies that aren't browser-compatible. You might want to explore a similar architecture for your Cypress tests. If you’d like, I can give you more details about solution. |
Beta Was this translation helpful? Give feedback.
-
I have a complex app with many models and objects interacting in my back-end. I wanted to implement
Factory
pattern functions to easily build objects and sets of objects that exist inside my Cypress tests. To do so I wanted to implement a third party ORM library inside Cypress such asSequelize
orMikroORM
. While trying to import and initialize one of my models' factory function inside a test, I get the following error:This error happens with a
MikroORM
implementation that successfully connects to the DB and can create objects in a testing shell outside of Cypress. The Cypress test simply looks like this:I'm aware that node-like code pertaining to the ORM libraries should be run in
setUpNodeEvents
, but I don't see a reason as to why it cannot be run inside tests.Beta Was this translation helpful? Give feedback.
All reactions