I am trying to save Cypress screenshots into a report using a support file as recommended in the documentation. However, I keep encountering an error:
Your supportFile is missing or invalid: support/e2e.js
The supportFile must be a .js, .ts, .coffee file or be supported by your preprocessor plugin (if configured).
Fix your support file, or set supportFile to false if a support file is not necessary for your project.
If you have just renamed the extension of your supportFile, restart Cypress.
https://on.cypress.io/support-file-missing-or-invalid
The relevant code snippet is:
import addContext from "mochawesome/addContext"
Cypress.on("test:after:run", (test, runnable) => {
if (test.state === "failed") {
const screenshot =`assets/${Cypress.spec.name}/${runnable.parent.title} -- ${test.title} (failed) (attempt 2).png`;
addContext({ test }, screenshot);
}
});
The support file name is support/e2e.js and it is included in cypress.config.ts
const { defineConfig } = require('cypress')
module.exports = defineConfig({
e2e: {
baseUrl: 'http://oft-dev.ep-dev.prom.local',
browser: 'chrome', // Set the browser here
supportFile: 'support/e2e.js',
},
experimentalStudio: true,
reporter: 'cypress-multi-reporters',
//reporter: 'junit', // Set the reporter here
reporterOptions: {
configFile: 'reporter.config.json',
},
});
My tests are in Typescript. Do I also need to create the support file in Typescript? If so, what would be the syntax for it? I am confused.