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

cymap

v1.0.3

Published

Plugin for E2E email testing with cypress

Downloads

982

Readme

cymap cypress version test

Cypress plugin for accessing mail from email servers.

The purpose of this plugin is to use existing email servers instead of deploying your. Cymap leverages the capabilities of IMAP protocol.

By using cymap:

  • you are not dependant on an email server nor its REST API
  • you have no need to deploy your own email server, you can use gmail or any other similar service
  • if you have your own email server it will work with it to since IMAP is standardized
  • you can access mail from multiple clients

Install

npm i cymap

Import cymap tasks in cypress.config.js. and put cymapTasks object in on task.

const { defineConfig } = require("cypress");
const cymapTasks = require("cymap/src/cymapTasks")
module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on("task",{
        ...cymapTasks
      })
      // implement node event listeners here
    },
  },
});

Import cymap index in e2e.js

// Import commands.js using ES2015 syntax:
import './commands'
import "cymap/src/index"

Gmail setup

Gmail IMAP can be used only with the app password. There are a few steps you need to do to generate the app password. It is required by google for security reasons.

Steps

  1. Go to your inbox
  2. In the upper right corner click the settings icon
  3. Then click "See all settings"
  4. Click on "Forwarding and POP/IMAP"
  5. Scroll down and click "Enable IMAP"
  6. Go to https://myaccount.google.com/u/2/security
  7. Click on 2-step verification and turn it on
    • Chose any of the given methods and implement it
  8. At the bottom og the 2-step verification screen "App passwords" article should be shown.
  9. Go to App passwords screen and create a new password
  10. Remember that password That password along with your email will be used to access emails programmatically

Use

Functions

Set configuration data

cy.setConnectionConfig( {
  password:"socadscjfa",
  user:"[email protected]",
  host:'imap.gmail.com',
  port:993,
  tls:true,
  tlsOptions: { rejectUnauthorized: false }
})

Ideally called in before each.

Fetch all mail

cy.getAllMail()

Fetches all mail from the INBOX

Delete all mail

cy.deleteAllMail()

Deletes all mail from the INBOX. For gmail the mail is moved to Waste box

Get email by index

cy.getEmailByIndex(1)

Fetches email by index top down. Top email in the INBOX is under index 1.

Delete email by index

cy.deleteEmailByIndex(1)

Deletes email by index top down. Top email in the INBOX is under index 1.

cy.pasteHtml(html)

Pastes HTML to the DOM

Email

Email body example:

{
    "attachments": [],
    "headers": {},
    "headerLines": [...],
    "html": "<p>Hello World </p>",
    "text": "Hello World",
    "textAsHtml": "<p>Hello World</p>",
    "subject": "Hello World",
    "date": "2024-04-30T16:15:16.000Z",
    "to": {
        "value": [
            {
                "address": "[email protected]",
                "name": ""
            }
        ],
        "html": "<span class=\"mp_address_group\"><a href=\"mailto:[email protected]\" class=\"mp_address_email\">[email protected]</a></span>",
        "text": "[email protected]"
    },
    "from": {
        "value": [
            {
                "address": "[email protected]",
                "name": ""
            }
        ],
        "html": "<span class=\"mp_address_group\"><a href=\"mailto:[email protected]\" class=\"mp_address_email\">[email protected]</a></span>",
        "text": "[email protected]"
    },
    "messageId": "<[email protected]>"
}

Examples

Fetch all mail

describe('tests getAllMail function', () => {
  before("Set configs and add mail", ()=>{
    cy.setConnectionConfig(config)
  })

  it('returns parsed body', ()=>{
    cy.getAllMail().then(mail=>{
      expect(mail.length).to.eq(4)
      mail.forEach(email=>{
        expect(email[0].subject).to.contain("Hello World")
      })
    })
  })
})

Fetch an email and paste it to dom

 before("Set configs and add mail", ()=>{
    cy.setConnectionConfig(config)
  })

  it('returns parsed body', ()=>{
    cy.getEmailByIndex(1).then(email=>{
        cy.pasteHtml(email.html)
        cy.contains("Hello World").should("be.visible")
    })
  })

Delete all mail

before("Set configs and add mail", ()=>{
    cy.setConnectionConfig(config)
})

it('returns parsed body', ()=>{
    cy.deleteAllMail().then(isDeleted=>{
       cy.expect(isDeleted).to.eq(true)
    })
})

Delete email by index

before("Set configs and add mail", ()=>{
    cy.setConnectionConfig(config)
})

it('returns parsed body', ()=>{
    cy.deleteEmailByIndex(1).then(isDeleted=>{
       cy.expect(isDeleted).to.eq(true)
    })
})

Contributors

Filip Cica

TODO

Add waitForEmailWithSubject()

Add getEmailBySubject()

Add methods for parsing various attachments

Add waitForEmail()