npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cypress-test-email

v1.5.2

Published

Package for testing email receiving in cypress

Downloads

18

Readme

ProxiedMail Cypress Plugin

Official ProxiedMail plugin for email testing with Cypress. This library is using the base NodeJS library of ProxiedMail.

Features

  • Creating a new email address
  • Receiving letter contents that were sent to generated emails
  • Receiving subject, body, html, headers of email

Example

In this example, we're creating the email address and receiving the first mail. Also, we're asserting that the subject and body are correct.

describe('template spec', () => {
  it('testing email', {
    defaultCommandTimeout: 10000,
  }, () => {

    cy.proxiedmail().then((proxiedmail) => {

      cy.visit('https://proxiedmail.com')
      cy.get('.nav_li').contains('Sign up').click()
      cy.url().should('include', '/en/signup')


      cy.then(
          () => {
            return new Promise(resolve => {
              proxiedmail.createProxyEmail(proxyEmail => {
                resolve(proxyEmail)
              })
            })
      }).then((proxyEmail)  => {
        cy.wrap(proxyEmail.getId()).as('proxyEmailId')
        cy.wrap(proxyEmail.getProxyEmail()).as('emailAddress')
      })


      Cypress.on('uncaught:exception', (err, runnable) => {
        // returning false here prevents Cypress from
        // failing the test
        return false
      })


      cy.then(function () {
        global.proxyEmailId = this.proxyEmailId
        cy.get('#login').type(this.emailAddress)
        cy.get('#password').type('123456')
        return cy.get('#proceed').click()
      })



      cy.then(() => {
        return new Promise(resolve => {
              const interval = setInterval(() => {
                proxiedmail.getReceivedEmails(global.proxyEmailId, (resp) => {
                  if (resp.data.length > 0) {
                    resp.data[0].getDetails(function (details) {
                      clearInterval(interval);
                      resolve(details)
                    })
                  }
              })}, 3000);
              return interval;
            })
          },
          {
            timeout: 10000
          }
      ).then(details => {
        expect(details.getSubject()).to.equal('Please confirm your email on ProxiedMail')
        expect(details.getPayloadBodyHtml()).to.have.string(
            'please confirm that you want to receive messages by clicking'
        );
      });
    });
  })
})

Quick links

Install

Ensure you have Cypress installed first then run:

npm install --save-dev cypress-test-email

Then include the plugin in your cypress/support/index.{js,ts} file.

import 'cypress-test-email'

Configuration

It's necessary to specify your API token in PROXIEDMAIL_API_KEY.

You can configure this plugin by putting to env variable PROXIEDMAIL_API_KEY to cypress.config.js

const { defineConfig } = require("cypress");

module.exports = defineConfig({
    "env": {
        "PROXIEDMAIL_API_KEY": "YOUR API KEY"
    },
    e2e: {
        setupNodeEvents(on, config) {
            // implement node event listeners here
        },
    },
});

You can also pass the variable in a command line

PROXIEDMAIL_API_KEY=your-api-key cypress run

Obtaining API key

You can obtain API key by signing up on ProxiedMail. Basic usage of the product is free up to 10 mailboxes + some API limits. If you want to get the best result please think about upgrading your account.

See pricing on ProxiedMail

Timeouts

ProxiedMail requires timeouts in order to get your emails. Please adjust the timings where you have the email testings up to 10s (1000ms).

Usage

The Cypress ProxiedMail plugin provides one simple command attached to the Cypress object: cy.proxiedmail(). This method returns a ProxiedMail client instance that has all the same methods and properties as the official ProxiedMail client. Use the command with the then() method to access the instance:

describe('sign up using disposable email', function () {
    it('can set config', () => {
        //<gen>cy_config_dynamic
        cy.proxiedmail().then((proxiedmail) => {
            // use the proxiedmail instance
        });
    })
});

Common methods

createProxyEmail

        cy.then(
            () => {
                return new Promise(resolve => {
                    proxiedmail.createProxyEmail(proxyEmail => {
                        resolve(proxyEmail)
                    })
                })
    })

getReceivedEmails

        cy.then(() => {
            return new Promise(resolve => {
                const interval = setInterval(() => {
                    proxiedmail.getReceivedEmails(global.proxyEmailId, (resp) => {
                        if (resp.data.length > 0) {
                            resp.data[0].getDetails(function (details) {
                                clearInterval(interval);
                                resolve(details)
                            })
                        }
                    })
                }, 3000);
                return interval;
            })
        },
        {
            timeout: 10000
        }
    ).then(details => {
        expect(details.getSubject()).to.equal('Please confirm your email on ProxiedMail')
        expect(details.getPayloadBodyHtml()).to.have.string(
            'please confirm that you want to receive messages by clicking'
        );
    });

Help

If you have any questions or need help, please contact us on ProxiedMail or you can use [email protected].

Good luck!