New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cypress-mailslurp

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypress-mailslurp - npm Package Compare versions

Comparing version 1.6.0 to 1.7.0

13

dist/cypress-mailslurp.cjs.development.js

@@ -8,8 +8,9 @@ 'use strict';

function register(Cypress) {
// check API Key
//<gen>cy_add_plugin
// read the API Key from environment variable (see the API Key section of README)
var apiKey = Cypress.env('MAILSLURP_API_KEY');
if (!apiKey) {
throw new Error('Error no MailSlurp API Key. Please set the CYPRESS_MAILSLURP_API_KEY ' + 'environment variable to your MailSlurp API Key to use the MailSlurp Cypress plugin. ' + 'Create a free account at https://app.mailslurp.com/sign-up/');
} // create instance
throw new Error('Error no MailSlurp API Key. Please set the `CYPRESS_MAILSLURP_API_KEY` ' + 'environment variable to the value of your MailSlurp API Key to use the MailSlurp Cypress plugin. ' + 'Create a free account at https://app.mailslurp.com/sign-up/. See https://docs.cypress.io/guides/guides/environment-variables#Option-3-CYPRESS_ for more information.');
} // create an instance of mailslurp-client

@@ -20,6 +21,8 @@

basePath: 'https://cypress.api.mailslurp.com'
});
}); // register MailSlurp with cypress under "mailslurp" command
// afterwards you can access it in tests using `cy.mailslurp().then(mailslurp => /* do stuff */)`
Cypress.Commands.add('mailslurp', function () {
return Promise.resolve(mailslurp);
});
}); //</gen>
}

@@ -26,0 +29,0 @@

@@ -1,2 +0,2 @@

"use strict";var r=require("mailslurp-client");!function(e){var a=e.env("MAILSLURP_API_KEY");if(!a)throw new Error("Error no MailSlurp API Key. Please set the CYPRESS_MAILSLURP_API_KEY environment variable to your MailSlurp API Key to use the MailSlurp Cypress plugin. Create a free account at https://app.mailslurp.com/sign-up/");var s=new r.MailSlurp({apiKey:a,basePath:"https://cypress.api.mailslurp.com"});e.Commands.add("mailslurp",(function(){return Promise.resolve(s)}))}(Cypress);
"use strict";var e=require("mailslurp-client");!function(r){var a=r.env("MAILSLURP_API_KEY");if(!a)throw new Error("Error no MailSlurp API Key. Please set the `CYPRESS_MAILSLURP_API_KEY` environment variable to the value of your MailSlurp API Key to use the MailSlurp Cypress plugin. Create a free account at https://app.mailslurp.com/sign-up/. See https://docs.cypress.io/guides/guides/environment-variables#Option-3-CYPRESS_ for more information.");var i=new e.MailSlurp({apiKey:a,basePath:"https://cypress.api.mailslurp.com"});r.Commands.add("mailslurp",(function(){return Promise.resolve(i)}))}(Cypress);
//# sourceMappingURL=cypress-mailslurp.cjs.production.min.js.map

@@ -6,8 +6,9 @@ import { MailSlurp } from 'mailslurp-client';

function register(Cypress) {
// check API Key
//<gen>cy_add_plugin
// read the API Key from environment variable (see the API Key section of README)
var apiKey = Cypress.env('MAILSLURP_API_KEY');
if (!apiKey) {
throw new Error('Error no MailSlurp API Key. Please set the CYPRESS_MAILSLURP_API_KEY ' + 'environment variable to your MailSlurp API Key to use the MailSlurp Cypress plugin. ' + 'Create a free account at https://app.mailslurp.com/sign-up/');
} // create instance
throw new Error('Error no MailSlurp API Key. Please set the `CYPRESS_MAILSLURP_API_KEY` ' + 'environment variable to the value of your MailSlurp API Key to use the MailSlurp Cypress plugin. ' + 'Create a free account at https://app.mailslurp.com/sign-up/. See https://docs.cypress.io/guides/guides/environment-variables#Option-3-CYPRESS_ for more information.');
} // create an instance of mailslurp-client

@@ -18,6 +19,8 @@

basePath: 'https://cypress.api.mailslurp.com'
});
}); // register MailSlurp with cypress under "mailslurp" command
// afterwards you can access it in tests using `cy.mailslurp().then(mailslurp => /* do stuff */)`
Cypress.Commands.add('mailslurp', function () {
return Promise.resolve(mailslurp);
});
}); //</gen>
}

@@ -24,0 +27,0 @@

@@ -5,3 +5,3 @@ {

"description": "Cypress email plugin for MailSlurp. Create test email accounts to send and receive emails in Cypress tests",
"version": "1.6.0",
"version": "1.7.0",
"license": "MIT",

@@ -23,3 +23,4 @@ "main": "dist/index.js",

"cypress": "cypress run",
"cypress-open": "cypress open"
"cypress-open": "cypress open",
"readme": "node scripts/readme.js"
},

@@ -34,5 +35,6 @@ "prettier": {

"devDependencies": {
"cypress": "^10.5.0",
"cypress": "^12.8.1",
"eslint-plugin-chai-friendly": "^0.6.0",
"eslint-plugin-cypress": "^2.11.2",
"jest-diff": "^29.5.0",
"tsdx": "^0.14.1",

@@ -43,4 +45,4 @@ "tslib": "^2.2.0",

"dependencies": {
"mailslurp-client": "^15.16.1"
"mailslurp-client": "^15.17.0"
}
}
# MailSlurp Cypress Plugin
Official MailSlurp email plugin for Cypress JS. Create real test email accounts. Send and receive emails and attachments in Cypress tests. For more advanced usage see the standard [MailSlurp library](https://www.npmjs.com/package/mailslurp-client).
## Install
## Quick links
- [Example project](https://github.com/mailslurp/examples/tree/master/javascript-cypress-mailslurp-plugin)
- [Use without plugin](https://github.com/mailslurp/examples/tree/master/javascript-cypress-js)
- [SMS testing](https://github.com/mailslurp/examples/tree/master/javascript-cypress-sms-testing)
`npm install --save-dev cypress-mailslurp`
## Install Cypress
First install and initialize Cypress:
```
npm install --save-dev cypress
```
Set command timeouts in your `cypress.config.js`
```typescript
import { defineConfig } from 'cypress'
export default defineConfig({
// set timeouts so MailSlurp can wait for emails and sms
defaultCommandTimeout: 30000,
responseTimeout: 30000,
requestTimeout: 30000,
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
// examples run against the playground app
baseUrl: 'https://playground.mailslurp.com',
// these examples require no test isolation
testIsolation: false
},
})
```
## Install MailSlurp
Next we add MailSlurp to our Cypress tests. There are **two ways** to use MailSlurp with Cypress:
- either with the `cypress-mailslurp` plugin
- or by adding a command to register the `mailslurp-client` within your `cypress/support/commands.js` file.
### 1) Cypress MailSlurp Plugin
```sh
npm install --save-dev cypress-mailslurp
```
Then include the plugin in your `cypress/support/index.{js,ts}` file.
```typescript
import "cypress-mailslurp";
import {MailSlurp} from "mailslurp-client";
```
See the [example project](https://github.com/mailslurp/examples/tree/master/javascript-cypress-mailslurp-plugin) for setup help. Or run the example integration tests with `CYPRESS_MAILSLURP_API_KEY=your-api-key npm run cypress`.
> **NOTE** you must import the MailSlurp plugin in `cypress/support/e2e.ts`
### 2) Standalone MailSlurp client
Install the [MailSlurp Javascript library](https://n) and then add MailSlurp as a [custom cypress command](https://docs.cypress.io/api/cypress-api/custom-commands).
Install package from npm:
```sh
npm install --save-dev mailslurp-client
```
Edit one of the [custom commands files](https://docs.cypress.io/api/cypress-api/custom-commands) `cypress/support/commands.{ts,js}` or `cypress/support/e2e.{ts,js}` and register the MailSlurp command:
```typescript
// read the API Key from environment variable (see the API Key section of README)
const apiKey = Cypress.env('MAILSLURP_API_KEY');
if (!apiKey) {
throw new Error(
'Error no MailSlurp API Key. Please set the `CYPRESS_MAILSLURP_API_KEY` ' +
'environment variable to the value of your MailSlurp API Key to use the MailSlurp Cypress plugin. ' +
'Create a free account at https://app.mailslurp.com/sign-up/. See https://docs.cypress.io/guides/guides/environment-variables#Option-3-CYPRESS_ for more information.'
);
}
// create an instance of mailslurp-client
const mailslurp = new MailSlurp({ apiKey, basePath: 'https://cypress.api.mailslurp.com' });
// register MailSlurp with cypress under "mailslurp" command
// afterwards you can access it in tests using `cy.mailslurp().then(mailslurp => /* do stuff */)`
Cypress.Commands.add('mailslurp' as any, () => {
return Promise.resolve(mailslurp);
});
```
## Setup
MailSlurp is free but requires an API Key. Get yours by [creating a free account](https://www.mailslurp.com/sign-up/).
See the [example project](https://github.com/mailslurp/examples/tree/master/javascript-cypress-mailslurp-plugin) for setup help.
### API Key

@@ -86,2 +165,32 @@ Set the environment variable `CYPRESS_MAILSLURP_API_KEY` or use the `cypress.json` file `env` property:

You can test that you have setup MailSlurp correctly in a test like so:
```typescript
describe('basic usage', function () {
it('can load the plugin', async function () {
// test we can connect to mailslurp
const mailslurp = await cy.mailslurp();
const userInfo = await mailslurp.userController.getUserInfo();
expect(userInfo.id).to.exist
})
});
describe('store values', function () {
//<gen>cy_store_values
before(function() {
return cy
.mailslurp()
.then(mailslurp => mailslurp.createInbox())
.then(inbox => {
// save inbox id and email address to this (make sure you use function and not arrow syntax)
cy.wrap(inbox.id).as('inboxId');
cy.wrap(inbox.emailAddress).as('emailAddress');
});
});
it('can access values on this', function() {
// get wrapped email address and assert contains a mailslurp email address
expect(this.emailAddress).to.contain('@mailslurp');
});
```
### Common methods

@@ -103,2 +212,3 @@ The client chained by the `cy.mailslurp()` has all the same methods and properties as the official MailSlurp client. See the [Javascript documentation](https://www.mailslurp.com/docs/js/) for a full [API reference](https://www.mailslurp.com/docs/js/docs/) or see the examples below.

Use the `waitFor` methods to wait for emails for an inbox. See the [email object docs](https://www.mailslurp.com/docs/js/docs/interfaces/email/) for full properties.
```typescript

@@ -133,21 +243,19 @@ cy.mailslurp()

```typescript
before(function () {
return cy.mailslurp()
.then(mailslurp => mailslurp.createInbox())
.then(inbox => {
// save inbox id and email address to this (make sure you use function and not arrow syntax)
cy.wrap(inbox.id).as('inboxId')
cy.wrap(inbox.emailAddress).as('emailAddress')
})
before(function() {
return cy
.mailslurp()
.then(mailslurp => mailslurp.createInbox())
.then(inbox => {
// save inbox id and email address to this (make sure you use function and not arrow syntax)
cy.wrap(inbox.id).as('inboxId');
cy.wrap(inbox.emailAddress).as('emailAddress');
});
});
it("01 - can load the demo application", function () {
// get wrapped email address and assert contains a mailslurp email address
expect(this.emailAddress).to.contain("@mailslurp");
// visit the demo application
cy.visit("https://playground.mailslurp.com")
cy.title().should('contain', 'React App');
it('can access values on this', function() {
// get wrapped email address and assert contains a mailslurp email address
expect(this.emailAddress).to.contain('@mailslurp');
});
```
> **Note:** using `wrap` to store values accross test methods requires you to use `function` syntax instead of `() =>` arrow syntax. This ensure that `this` is dynamically scoped and includes the aliased variables.
> **Note:** using `wrap` to store values across test methods requires you to use `function` syntax instead of `() =>` arrow syntax. This ensure that `this` is dynamically scoped and includes the aliased variables.

@@ -161,57 +269,69 @@ ## Example test

```typescript
/// <reference types="cypress-mailslurp" />
describe("user sign up test with mailslurp plugin", function () {
// use cypress-mailslurp plugin to create an email address before test
before(function () {
return cy.mailslurp()
.then(mailslurp => mailslurp.createInbox())
.then(inbox => {
// save inbox id and email address to this (make sure you use function and not arrow syntax)
cy.wrap(inbox.id).as('inboxId')
cy.wrap(inbox.emailAddress).as('emailAddress')
})
});
it("01 - can load the demo application", function () {
// get wrapped email address and assert contains a mailslurp email address
expect(this.emailAddress).to.contain("@mailslurp");
// visit the demo application
cy.visit("https://playground.mailslurp.com")
cy.title().should('contain', 'React App');
});
// use function instead of arrow syntax to access aliased values on this
it("02 - can sign up using email address", function () {
// click sign up and fill out the form
cy.get("[data-test=sign-in-create-account-link]").click()
// use the email address and a test password
cy.get("[name=email]").type(this.emailAddress).trigger('change');
cy.get("[name=password]").type('test-password').trigger('change');
// click the submit button
cy.get("[data-test=sign-up-create-account-button]").click();
});
it("03 - can receive confirmation code by email", function () {
// app will send user an email containing a code, use mailslurp to wait for the latest email
cy.mailslurp()
// use inbox id and a timeout of 30 seconds
.then(mailslurp => mailslurp.waitForLatestEmail(undefined,undefined,this.inboxId,undefined,undefined,30000, true))
// extract the confirmation code from the email body
.then(email => /.*verification code is (\d{6}).*/.exec(email.body!!)!![1])
// fill out the confirmation form and submit
.then(code => {
cy.get("[name=code]").type(code).trigger('change');
cy.get("[data-test=confirm-sign-up-confirm-button]").click();
})
});
// fill out sign in form
it("04 - can sign in with confirmed account", function () {
// use the email address and a test password
cy.get("[data-test=username-input]").type(this.emailAddress).trigger('change');
cy.get("[data-test=sign-in-password-input]").type('test-password').trigger('change');
// click the submit button
cy.get("[data-test=sign-in-sign-in-button]").click();
});
// can see authorized welcome screen
it("05 - can see welcome screen", function () {
// click sign up and fill out the form
cy.get("h1").should("contain", "Welcome");
});
describe('user sign up test with mailslurp plugin', function() {
// use cypress-mailslurp plugin to create an email address before test
before(function() {
return cy
.mailslurp()
.then(mailslurp => mailslurp.createInbox())
.then(inbox => {
// save inbox id and email address to this (make sure you use function and not arrow syntax)
cy.wrap(inbox.id).as('inboxId');
cy.wrap(inbox.emailAddress).as('emailAddress');
});
});
it('01 - can load the demo application', function() {
// get wrapped email address and assert contains a mailslurp email address
expect(this.emailAddress).to.contain('@mailslurp');
// visit the demo application
cy.visit('/');
cy.title().should('contain', 'React App');
});
// use function instead of arrow syntax to access aliased values on this
it('02 - can sign up using email address', function() {
// click sign up and fill out the form
cy.get('[data-test=sign-in-create-account-link]').click();
// use the email address and a test password
cy.get('[name=email]')
.type(this.emailAddress)
.trigger('change');
cy.get('[name=password]')
.type('test-password')
.trigger('change');
// click the submit button
cy.get('[data-test=sign-up-create-account-button]').click();
});
it('03 - can receive confirmation code by email', function() {
// app will send user an email containing a code, use mailslurp to wait for the latest email
cy.mailslurp()
// use inbox id and a timeout of 30 seconds
.then(mailslurp =>
mailslurp.waitForLatestEmail(this.inboxId, 30000, true)
)
// extract the confirmation code from the email body
.then(email => /.*verification code is (\d{6}).*/.exec(email.body!!)!![1])
// fill out the confirmation form and submit
.then(code => {
cy.get('[name=code]')
.type(code)
.trigger('change');
cy.get('[data-test=confirm-sign-up-confirm-button]').click();
});
});
// fill out sign in form
it('04 - can sign in with confirmed account', function() {
// use the email address and a test password
cy.get('[data-test=username-input]')
.type(this.emailAddress)
.trigger('change');
cy.get('[data-test=sign-in-password-input]')
.type('test-password')
.trigger('change');
// click the submit button
cy.get('[data-test=sign-in-sign-in-button]').click();
});
// can see authorized welcome screen
it('05 - can see welcome screen', function() {
// click sign up and fill out the form
cy.get('h1').should('contain', 'Welcome');
});
});

@@ -218,0 +338,0 @@ ```

/// <reference types="./">
//<gen>cy_import_mailslurp
import {MailSlurp} from "mailslurp-client";
//</gen>
function register(Cypress: Cypress.Cypress) {
// check API Key
//<gen>cy_add_plugin
// read the API Key from environment variable (see the API Key section of README)
const apiKey = Cypress.env('MAILSLURP_API_KEY');
if (!apiKey) {
throw new Error(
'Error no MailSlurp API Key. Please set the CYPRESS_MAILSLURP_API_KEY ' +
'environment variable to your MailSlurp API Key to use the MailSlurp Cypress plugin. ' +
'Create a free account at https://app.mailslurp.com/sign-up/'
'Error no MailSlurp API Key. Please set the `CYPRESS_MAILSLURP_API_KEY` ' +
'environment variable to the value of your MailSlurp API Key to use the MailSlurp Cypress plugin. ' +
'Create a free account at https://app.mailslurp.com/sign-up/. See https://docs.cypress.io/guides/guides/environment-variables#Option-3-CYPRESS_ for more information.'
);
}
// create instance
// create an instance of mailslurp-client
const mailslurp = new MailSlurp({ apiKey, basePath: 'https://cypress.api.mailslurp.com' });
// register MailSlurp with cypress under "mailslurp" command
// afterwards you can access it in tests using `cy.mailslurp().then(mailslurp => /* do stuff */)`
Cypress.Commands.add('mailslurp' as any, () => {
return Promise.resolve(mailslurp);
});
//</gen>
}
register(Cypress);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc