Synthetixio / synpress

Synpress is e2e testing framework based on Cypress.io and playwright with support for metamask.
https://synpress.io
MIT License
565 stars 179 forks source link

Not able to add custom task on index.js #608

Open mflorlorenzo opened 1 year ago

mflorlorenzo commented 1 year ago

Is there a way to add custom tasks inside the module exports of the index.js file inside the @synthetixio package? Or create a file where you can extend this and add custom task inside "on ('task')"

(I'm working with gmail-tester Node.js Gmail client to read mails but It's necessary to add a custom task inside "setupNodeModules" to read them).

Thanks

Cianekjr commented 1 year ago

It's only a workaround, but I copied the @synthetixio/synpress/plugins/index.js file to my local tests/e2e/plugins/index.ts and now I'm able to add my custom tasks:

import helpers from "@synthetixio/synpress/helpers";
import playwright from "@synthetixio/synpress/commands/playwright";
import metamask from "@synthetixio/synpress/commands/metamask";
import synthetix from "@synthetixio/synpress/commands/synthetix";
import etherscan from "@synthetixio/synpress/commands/etherscan";

export const setupNodeEvents = (on, config) => {
  on("task", {
    // CUSTOM TASKS
    getEmailMessage: async ({ subject }: { subject: string }) => {
      const emailMessage = await mailerService.watchMailerMessage({
        subject,
      });
      return emailMessage;
    },
    // playwright commands
    initPlaywright: async () => {
      const connected = await playwright.init();
      return connected;
    },
   [...]
  });

  return config;
};

And in synpress.config.ts:

import { defineConfig } from "cypress";

import { setupNodeEvents } from "tests/e2e/plugins";

export default defineConfig({
  e2e: {
    setupNodeEvents,
  },
});
louis-md commented 10 months ago

Duplicate of #408