I'm running on Cypress version 12.14.0. I have my regular Cypress project structure. I have cypress.config.js and under e2e directory I have the test files such as test1.cy.js
What I'm unable to achieve is that I want to debug the JS code I invoked from my test file.
I have this call in my test1.cy.js test file
cy.task('myTask', '', {
options: { taskTimeout: 3600000 }
}).then(()=>{
cy.debug()
})
then I have this definiton in my cypress.config.js
...
const fileUtils = require('./Utils/FileUtils.js')
...
setupNodeEvents: async function (on, config) {
on('task', {
myTask() {
fileUtils.checkFiles()
return true
}
})
}
and in my FileUtils.js file:
...
async function checkFiles(){
/*
my code i want to debug line by line
*/
}
module.exports = {
checkFiles:checkFiles
}
then I run cypress using command
npx cypress open
then I select chrome and open Dev Tools by pressing F12. then the debugger kicks in for the line cy.debug()
in my cy.js file. However, from this point forward, I find FileUtils.js in the "Sources" tab of DevTools and put a breakpoint in the line I want, but it never goes into the breakpoint but I verify that the code where I put the breakpoint is actually executed successfully.
So. How can I debug a function defined in a JS file that is invoked from within a cypress cy.js test file?
Cypress debug can't be used inside a task as far as I know.
The test code is what cy.debug()
is designed for and the test code runs in the the browser.
Tasks run in the NodeJs part of Cypress runner. You already have a separate module for checkFiles()
so you should be able to run debug using Node.js debugging in VS Code, running separately from the Cypress tests.
The Visual Studio Code editor has built-in debugging support for the Node.js runtime and can debug JavaScript, TypeScript, and many other languages that are transpiled into JavaScript.
Auto Attach
If the Auto Attach feature is enabled, the Node debugger automatically attaches to certain Node.js processes that have been launched from VS Code's Integrated Terminal.