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-maildev

v1.3.2

Published

An easy-to-use cypress bunch of commands to use Maildev API for tests messages reception !

Downloads

20,278

Readme

Cypress Maildev

Cypress Maildev is a bunch of Cypress commands in order to test your messages (SMS and Emails) by using Maildev REST API.

CI npm version

Installation

npm install cypress-maildev --save-dev
yarn add cypress-maildev --dev

Usage

1. Register the plugin :

// cypress/support/e2e.js

require('cypress-maildev');

2. Specify your maildev address

By default, Maildev API is started at the http://localhost:1080. If you are using default maildev instance, you have nothing to do!

You can also use env vars in your cypress.config.js as below :

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

module.exports = defineConfig({
  env: {
    MAILDEV_PROTOCOL: "http",
    MAILDEV_HOST: "localhost",
    MAILDEV_SMTP_PORT: "1025",
    MAILDEV_API_PORT: "1080",
  },
});

For example, by using like this project a docker compose with cypress and maildev containers, you have to configure your cypress.config.js like this:

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

module.exports = defineConfig({
  env: {
    MAILDEV_PROTOCOL: "http",
    MAILDEV_HOST: "127.0.0.1",
    MAILDEV_SMTP_PORT: "1025",
    MAILDEV_API_PORT: "1080",
  },
});

Check the Maildev REST API documentation for what you can expect in responses.

Commands

Usage

All of theses commands use directly cy.request() which return a Cypress Promise like. Check the doc !

Using one of this commands must be like this example :

  cy.maildevGetLastMessage().then((email) => {
    expect(email.subject).to.equal("I'm the last email sent !");
  });

For more examples you can check directly the test file.

Documentation

Get all messages received in the Maildev instance.

cy.maildevGetAllMessages()

Get the last message received.

cy.maildevGetLastMessage()

Each messages got an internal ID. If you know it, you can find it directly.

cy.maildevGetMessageById(id: String)

You can also directly access to the HTML of your email by calling.

cy.maildevVisitMessageById(id: String)

And you can use Cypress promise to manipulate or assert the DOM of your email :

  cy.maildevVisitMessageById(id: String);
  cy.get('body h1').should('have.text', 'Email incoming !');
  cy.get('body a').should('exist').and('have.text', 'click on this link');

You must have to specify "chromeWebSecurity": false, because you will access to another domain than your app. Unfortunately, Cypress can't deactivate the cross-origin requests for Firefox actually.


Get all messages and find one by containing a specific subject. It's a simple string detection case-sensitive.

cy.maildevGetMessageBySubject(subject: String)

Get all messages and find the last containing a sent to address. Use a strict string comparison.

cy.maildevGetMessageBySentTo()

Delete a message by giving the ID. In can be useful if you to only keep message that you haven't read yet.

cy.maildevDeleteMessageById()

Delete all message in order to flush your mailbox !

cy.maildevDeleteAllMessages()

Get an OTP code from a string. It can be used outside of maildev box because it doesn't use maildev API but generally OTP code are sent by messages. This function find in a string a specific amount of digits (default 6).

cy.maildevGetOTPCode(string, digits = 6)

Or use with another maildev command

  cy.maildevGetMessageBySubject("Your code").then(message => {
    cy.maildevGetOTPCode(message.text).then(code => {
      // Do something with the code
    });
  });

Simple test command that return true if Maildev is opened.

cy.maildevHealthcheck()

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

  • Clone the repo

  • Install dependencies: make install

  • Start maildev: make start

Please make sure to update tests as appropriate and run make test command

License

MIT