'Receiving The 'task' event has not been registered in the plugins file. You must register it before using cy.task() when i test cypress gmail-tester

I don't know how to use the task and for which purpose, I have one project and I have got this project for solving errors. and I am getting this error. Any help or suggestions are welcome.

I have this code in my plugins/index.js file.

module.exports = (on, config) => {
on("task", {
      "gmail:get-messages": async args => {
        const messages = await gmail_tester.get_messages(
          path.resolve(__dirname, "credentials.json"),
          path.resolve(__dirname, "token.json"),
          args.options
        );
        console.log(messages);
        return messages;
      }
    });
};

And in my test i have implement like this.

cy.task('gmail:get-messages', {
    options: {
      from: "[email protected]",
      subject: "Join CypressTestProject01 team on RebelBase",
      include_body: true,
    }
  }).then(emails => {
    assert.isAtLeast(
      emails.length,
      1,
      "Expected to find at least one email, but none were found!"
    );
    const body = emails[0].body.html;
    console.log(body)
    cy.log(body);

    assert.isTrue(
      body.indexOf(
        "/auth/sign-up?type=project_invitation&token="
      ) >= 0,
      "Found link!"
    );

    window.token = extractData(body, startStr, endStr);

    cy.visit(
      `auth/sign-up?type=project_invitation&token=${token}&email=${randomEmail}`
    );
  })

I got this below error.

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source