question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gmail:check from within a cypress test timesout Error [ERR_IPC_CHANNEL_CLOSED] [ERR_IPC_CHANNEL_CLOSED]: Channel closed

See original GitHub issue

Using this within cypress trying to check an email, eventually want to extract and click the verify link. When it hits the check mail step it just falls over, error not overly helpful, wonder if you can advise what I might have got wrong. I followed this post: https://levz0r.medium.com/how-to-poll-a-gmail-inbox-in-cypress-io-a4286cfdb888

Oh, in that post the test says “email not found” but I think its suppose to say email found?? Anyways…

Here is my index.js file

const path = require("path");
const gmail = require("gmail-tester");

module.exports = (on, config) => {

  on("task", {
    "gmail:check": async args => {
      const { from, to, subject } = args;
      const email = await gmail.check_inbox(
        path.resolve(__dirname, "credentials.json"), // credentials.json is inside plugins/ directory.
        path.resolve(__dirname, "gmail_token.json"), // gmail_token.json is inside plugins/ directory.
        subject,
        from,
        to,
        30,                                          // Poll interval (in seconds)
        60                                           // Maximum poll interval (in seconds). If reached, return null, indicating the completion of the task().
      );
      console.log('gmail check is working');
      return email;
    }
  });

};

here is my test.js file:

it('link is no longer valid, we can request and new one and the new link works', () => {

  cy.visit('/urlforresetform');

  // Check we get the email and its content is correct.
  const test_id = new Date().getTime();
  const incoming_mailbox = `myemail+${test_id}@gmail.com`;
  const password = 'somepassword';

  cy.get("#edit-name").type(incoming_mailbox);
  cy.get("#edit-submit").click();

  cy
    .task("gmail:check", {
      from: "mysitesemailaddress",
      to: incoming_mailbox,
      subject: "emailtitle"
    })
    .then(email => {

      console.log('we have an email??');
      assert.isNotNull(email, `Email was found!`);
    });

})

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
timrabbettscommented, Sep 14, 2021

The main issue is the check_inbox was getting called with 7 variables, what it actually needs is 3 variables, the 2 json files and then an options variable, that was the main problem solver for me, the code above works so give it a try. Hope this helps.

1reaction
timrabbettscommented, Sep 13, 2021

Was already on latest version. Got it working, the examples are a bit out of date. I wasnt passing the data correctgly to start with.


Cypress.Commands.add('signup', () => {
  cy.visit('/userregpath');

  const test_id = new Date().getTime();
  const incoming_mailbox = 'test007+' + test_id + '@gmail.com';

  cy.get("#email").type(incoming_mailbox);
  cy.get("#submit").click();

  // Check we get the email and its content is correct.
  cy
    .task("gmail:check", {
      from: "My Site <postmaster@mysite.com>",
      to: incoming_mailbox,
      subject: "Please verify your account at bla"
    })
    .then(email => {
      // Extract the verify link url from the email.
      const verify_url = ////.exec(email[0].body.html)[1];

      // Use an alias to store the value, which we can wait for in next step.
      cy.wrap(verify_url).as('verifyUrl');

      // Confirm we got an email.
      assert.isNotNull(email, `Email was found!`);
    });

  // Visit the verify url once we get it from the email, confirm we get the correct form.
  cy.get('@verifyUrl').then((verifyUrl) => {
    cy.visit(verifyUrl);    
  })
})

const path = require("path");
const gmail = require("gmail-tester");

module.exports = (on, config) => {

  on("task", {
    async "gmail:check" (args) {
      const {from, to, subject} = args;

      const options = {
        subject: subject,
        from: '*',
        to: to,
        wait_time_sec: 30,
        max_wait_time_sec: 60,
        include_body: true
      }

      const email = await gmail.check_inbox(
         path.resolve(__dirname, "credentials.json"),
         path.resolve(__dirname, "gmail_token.json"),
         options,
      );

      return email;

    },
  });

};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Random failure [ERR_IPC_CHANNEL_CLOSED]: Channel ...
The last test in my cypress suite randomly fails in CI. It seems to be un-related to the test itself, but some cleanup...
Read more >
cypress-io/cypress - Gitter
We've stopped running your tests because a plugin crashed. Error [ERR_IPC_CHANNEL_CLOSED] [ERR_IPC_CHANNEL_CLOSED]: Channel closed
Read more >
Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed when ...
After lots of hours of debugging the problem was that a custom node dependency required a configuration file that wasn't present in the ......
Read more >
How To Stop Your Cypress Tests Timing Out - Jon D Jones
This will then allow the test to continue rather than to timeout and fail. To blacklist a host within Cypress, within your cypress.json...
Read more >
Boost your Cypress end-to-end Tests - andreybleme
In the previous post I have shared how to configure continuous ... Cypress test taking too much time ... Cypress test timeout error....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found