cypress-fail-fast icon indicating copy to clipboard operation
cypress-fail-fast copied to clipboard

Plugin import path in ES6 module syntax

Open anselmbradford opened this issue 1 year ago • 4 comments

Describe the bug

Start a new Cypress project from Cypress 13.x and the config will look like:

import { defineConfig } from "cypress";

export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      // implement node event listeners here
    },
  },
});

If you add require('cypress-fail-fast/plugin')(on, config); to this, per the readme, you'll get the error ReferenceError: require is not defined when attempting to run cypress.

To Reproduce Try adding this plugin to a Cypress ES6 module config file and try running Cypress.

Expected behavior Plugin should be updated to ES6 module syntax.

anselmbradford avatar Dec 19 '23 19:12 anselmbradford

Hi @anselmbradford , have you tried to change the import to ES6 import module syntax?

import cypressFailFast from "cypress-fail-fast/plugin";

export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      cypressFailFast(on, config);
    },
  },
});

I have tried it in a cypress.config.ts file, and it works properly. I also have tried in a cypress.config.mjs file, and, in that case, you should change the import to import cypressFailFast from "cypress-fail-fast/src/plugin.js";

javierbrea avatar Dec 20 '23 18:12 javierbrea

Hi @javierbrea, ahh I tried it with import cypressFailFast from "cypress-fail-fast/plugin"; and it didn't work, but import cypressFailFast from "cypress-fail-fast/src/plugin.js" does! I guess I should have scrutinized the source closer. Thanks! Maybe update the readme for this scenario? Cheers!

anselmbradford avatar Dec 20 '23 19:12 anselmbradford

Thank you @anselmbradford. I will try to use subpaths exports in the exports field in the package.json file in order to avoid this problem, and, in case I can't make it work, I will update the readme.

javierbrea avatar Jan 08 '24 10:01 javierbrea

I have already changed the README file examples to ES6 syntax, and I have added a note about defining the file extension explicitly. Anyway, I'll leave this issue open in order to investigate about adding the subpath exports.

javierbrea avatar Aug 05 '24 04:08 javierbrea