abhinaba-ghosh / cypress-react-selector

:zap: cypress plugin to locate react elements by component, props and state

Home Page:https://www.cypress.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

waitForReact throws an error when using Webpack

ajhenry opened this issue · comments

When using webpack with require.resolve, this will return a number rather than a path so this breaks the waitForReact function.

Webpack warning when using require.resolve: https://webpack.js.org/api/module-methods/#requireresolve
Issue describing that require.resolve returns a dependency ID in webpack: webpack/webpack#1554

Module ID's type can be a number or a string depending on the optimization.moduleIds configuration.

Code that uses require.resolve

const file = require.hasOwnProperty('resolve')
? require.resolve('resq')
: 'node_modules/resq/dist/index.js';
cy.readFile(file, 'utf8', {
log: false,
}).then((script) => {

Error

readFile: 27, utf8, {log: false}

cy.readFile() must be passed a non-empty string as its 1st argument. You passed: 27.

Versions

"cypress": "^8.5.0"
"cypress-react-selector": "^2.3.13"
"webpack": "^4",

Hi @ajhenry thanks for raising this issue.
According to this comment, it seems using eval could be a viable solution. Can you give it a try and raise a PR?

Sure I can take a crack at that this week

So I tried the solution with eval and that returned a weird webpack internal object rather than a path so I'm going to keep investigating

Closed via #279