Huge News!Announcing our $40M Series B led by Abstract Ventures.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.7.0 to 1.9.0

45

dist/cypress-mailslurp.cjs.development.js

@@ -5,26 +5,33 @@ 'use strict';

/// <reference types="./">
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function register(Cypress) {
//<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 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
var mailslurp = new mailslurpClient.MailSlurp({
apiKey: 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', function () {
Cypress.Commands.add('mailslurp', function (config) {
var _config$apiKey;
// read the API Key from environment variable (see the API Key section of README)
var apiKey = (_config$apiKey = config == null ? void 0 : config.apiKey) != null ? _config$apiKey : Cypress.env('MAILSLURP_API_KEY');
if (!apiKey) {
throw new Error('Error no MailSlurp API Key. Please either pass the mailslurp command a valid Config object or 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 mailslurp = new mailslurpClient.MailSlurp(_extends({}, config, {
apiKey: apiKey,
basePath: 'https://cypress.api.mailslurp.com'
}));
return Promise.resolve(mailslurp);
}); //</gen>
});
}
register(Cypress);
//# sourceMappingURL=cypress-mailslurp.cjs.development.js.map

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

"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);
"use strict";var e=require("mailslurp-client");function r(){return(r=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var a=arguments[r];for(var t in a)Object.prototype.hasOwnProperty.call(a,t)&&(e[t]=a[t])}return e}).apply(this,arguments)}!function(a){a.Commands.add("mailslurp",(function(t){var i,n=null!=(i=null==t?void 0:t.apiKey)?i:a.env("MAILSLURP_API_KEY");if(!n)throw new Error("Error no MailSlurp API Key. Please either pass the mailslurp command a valid Config object or 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 o=new e.MailSlurp(r({},t,{apiKey:n,basePath:"https://cypress.api.mailslurp.com"}));return Promise.resolve(o)}))}(Cypress);
//# sourceMappingURL=cypress-mailslurp.cjs.production.min.js.map
import { MailSlurp } from 'mailslurp-client';
/// <reference types="./">
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function register(Cypress) {
//<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 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
var mailslurp = new MailSlurp({
apiKey: 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', function () {
Cypress.Commands.add('mailslurp', function (config) {
var _config$apiKey;
// read the API Key from environment variable (see the API Key section of README)
var apiKey = (_config$apiKey = config == null ? void 0 : config.apiKey) != null ? _config$apiKey : Cypress.env('MAILSLURP_API_KEY');
if (!apiKey) {
throw new Error('Error no MailSlurp API Key. Please either pass the mailslurp command a valid Config object or 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 mailslurp = new MailSlurp(_extends({}, config, {
apiKey: apiKey,
basePath: 'https://cypress.api.mailslurp.com'
}));
return Promise.resolve(mailslurp);
}); //</gen>
});
}
register(Cypress);
//# sourceMappingURL=cypress-mailslurp.esm.js.map
/// <reference types="cypress" />
import { MailSlurp } from "mailslurp-client";
import { MailSlurp, Config } from "mailslurp-client";

@@ -7,5 +7,5 @@ declare global {

interface Chainable {
mailslurp: () => Promise<MailSlurp>;
mailslurp: (config?: Config) => Promise<MailSlurp>;
}
}
}
{
"name": "cypress-mailslurp",
"author": "mailslurp",
"description": "Cypress email plugin for MailSlurp. Create test email accounts to send and receive emails in Cypress tests",
"version": "1.7.0",
"description": "Cypress email and SMS plugin for MailSlurp. Create test email accounts to send and receive emails in Cypress tests. Read SMS and TXT messages too and test against fake mailservers.",
"version": "1.9.0",
"license": "MIT",

@@ -19,3 +19,2 @@ "main": "dist/index.js",

"build": "tsdx build",
"test": "tsdx test --testPathPattern=test/.+",
"lint": "tsdx lint --fix src test cypress",

@@ -34,5 +33,6 @@ "cypress": "cypress run",

"devDependencies": {
"cypress": "^12.8.1",
"cypress": "^13.6.2",
"eslint-plugin-chai-friendly": "^0.6.0",
"eslint-plugin-cypress": "^2.11.2",
"eslint-plugin-cypress": "^2.15.1",
"fast-glob": "^3.3.2",
"jest-diff": "^29.5.0",

@@ -44,4 +44,4 @@ "tsdx": "^0.14.1",

"dependencies": {
"mailslurp-client": "^15.17.0"
"mailslurp-client": "^15.17.4"
}
}
# 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).
Official MailSlurp email plugin for Cypress JS. Create real test email accounts. Send and receive emails, SMS, and attachments in Cypress tests. For examples and usage see the standard [MailSlurp library](https://www.npmjs.com/package/mailslurp-client).
## 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)
## Test email and SMS/TXT messages in Cypress
With MailSlurp and Cypress you can:
- create unlimited, disposable email addresses for testing
- send and receive emails in tests
- send and receive SMS messages in tests
- capture outbound emails with fake mailservers
- extract email verification codes and OTP magic links
### Example
## 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
},
})
it('can sign up using throwaway mailbox', function () {
// create a mailslurp instance
cy.mailslurp().then(function (mailslurp) {
// visit the demo application
cy.visit('/');
// create an email address and store it on this
cy.then(() => mailslurp.createInbox())
.then((inbox) => {
// save inbox id and email address to this
cy.wrap(inbox.id).as('inboxId');
cy.wrap(inbox.emailAddress).as('emailAddress');
})
// fill user details on app
cy.get('[data-test=sign-in-create-account-link]').click()
cy.then(function () {
// access stored email on this, make sure you use Function and not () => {} syntax for correct scope
cy.get('[name=email]').type(this.emailAddress)
cy.get('[name=password]').type('test-password')
return cy.get('[data-test=sign-up-create-account-button]').click();
})
// now wait for confirmation mail
cy.then({
// add timeout to the step to allow email to arrive
timeout: 60_000
}, function () {
return mailslurp
// wait for the email to arrive in the inbox
.waitForLatestEmail(this.inboxId, 60_000, true)
// extract the code with a pattern
.then(email => mailslurp.emailController.getEmailContentMatch({
emailId: email.id,
contentMatchOptions: {
// regex pattern to extract verification code
pattern: 'Your Demo verification code is ([0-9]{6})'
}
}))
// save the verification code to this
.then(({matches}) => cy.wrap(matches[1]).as('verificationCode'))
});
// confirm the user with the verification code
cy.then(function () {
cy.get('[name=code]').type(this.verificationCode)
cy.get('[data-test=confirm-sign-up-confirm-button]').click()
// use the email address and a test password
cy.get('[data-test=username-input]').type(this.emailAddress)
cy.get('[data-test=sign-in-password-input]').type('test-password')
// click the submit button
return cy.get('[data-test=sign-in-sign-in-button]').click();
})
cy.get('h1').should('contain', 'Welcome');
});
});
```
## 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.
### Quick links
- [API documentation](https://docs.mailslurp.com/js/)
- [JSDocs](https://js.mailslurp.com/)
- [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)
- [Test email verification](https://www.mailslurp.com/examples/cypress-js/)
### 1) Cypress MailSlurp Plugin
## Install
Ensure you have Cypress installed first then run:

@@ -56,45 +87,13 @@ ```sh

```typescript
import {MailSlurp} from "mailslurp-client";
import 'cypress-mailslurp';
```
> **NOTE** you must import the MailSlurp plugin in `cypress/support/e2e.ts`
> [!IMPORTANT]
> You must import/require `cypress-mailslurp` in your support file `cypress/support/e2e.ts` or `cypress/support/index.{js,ts}`
### Configuration
See the [example project](https://github.com/mailslurp/examples/tree/master/javascript-cypress-mailslurp-plugin) for example code.
### 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
### API Key
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
Set the environment variable `CYPRESS_MAILSLURP_API_KEY` or use the `cypress.json` file `env` property:

@@ -127,5 +126,12 @@

#### Timeouts
MailSlurp requires timeouts to wait for inbound emails. Set timeouts in `cypress.json`:
#### Configure dynamically
You can also pass the `cy.mailslurp()` function a config containing an `apiKey` like so:
```typescript
cy.mailslurp({ apiKey: 'YOUR_KEY' })
```
### Timeouts
MailSlurp requires timeouts to wait for inbound emails. You can set global timeouts in `cypress.json`:
```json

@@ -139,2 +145,8 @@ {

Or you can set timeouts on a per-method basis using the first argument as a timeout config:
```typescript
cy.then({ timeout: 60_000 }, () => { /* use mailslurp */ })
```
#### Typescript support

@@ -171,27 +183,7 @@ MailSlurp adds the `mailslurp` command to the Cypress `cy` object. Include the type definition reference comment in your test file or support index.ts:

```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');
});
describe('sign up using disposable email', function () {
it('can set config', () => {
//<gen>cy_config_dynamic
cy.mailslurp({ apiKey: 'YOUR_KEY' })
```

@@ -208,24 +200,41 @@

```typescript
cy.mailslurp()
.then(mailslurp => mailslurp.createInbox())
.then(inbox => expect(inbox.emailAddress).to.contain("@mailslurp"));
await cy.mailslurp()
.then((mailslurp: MailSlurp) => mailslurp.createInboxWithOptions({}))
.then(inbox => {
expect(inbox.emailAddress).to.contain("@mailslurp")
// save the inbox values for access in other tests
cy.wrap(inbox.id).as('inboxId')
cy.wrap(inbox.emailAddress).as('emailAddress')
})
```
#### Receive emails in tests
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.
#### Send emails
To send emails in Cypress tests first create an inbox then use the `sendEmail` method.
```typescript
cy.mailslurp()
.then(mailslurp => mailslurp.waitForLatestEmail(undefined,undefined,inboxId,undefined,undefined, 30000, true))
.then(email => expect(email.subject).to.contain("My email"))
await cy.mailslurp()
.then((mailslurp: MailSlurp) => mailslurp.sendEmail(this.inboxId, {
to: [this.emailAddress ],
subject: 'Email confirmation',
body: 'Your code is: ABC-123',
}))
```
#### Send emails
To send emails in Cypress tests first create an inbox then use the `sendEmail` method.
#### Receive emails in tests
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
cy.mailslurp()
.then(mailslurp => mailslurp.sendEmail(inboxId, { to: ['test@example.com'], subject: 'test', body: '<html></html>', isHTML: true }))
cy.log("Waiting for email")
await cy.mailslurp().then({
// set a long timeout when waiting for an email to arrive
timeout: 60_000,
}, (mailslurp: MailSlurp) => mailslurp.waitForLatestEmail(this.inboxId, 60_000, true))
.then(email => {
expect(email.subject).toContain('Email confirmation')
const code = email.body.match(/Your code is: (\w+-\d+)/)[1]
expect(code).toEqual('ABC-1223')
})
```
#### Accessing more methods

@@ -262,3 +271,4 @@ To access all the MailSlurp methods available in the [REST API](https://api.mailslurp.com/swagger-ui.html) and [Javascript Client](https://www.mailslurp.com/docs/js/) use the controllers on the mailslurp instance.

> **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.
> [!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.

@@ -265,0 +275,0 @@ ## Example test

/// <reference types="cypress" />
import { MailSlurp } from "mailslurp-client";
import { MailSlurp, Config } from "mailslurp-client";

@@ -7,5 +7,5 @@ declare global {

interface Chainable {
mailslurp: () => Promise<MailSlurp>;
mailslurp: (config?: Config) => Promise<MailSlurp>;
}
}
}
/// <reference types="./">
//<gen>cy_import_mailslurp
import {MailSlurp} from "mailslurp-client";
//</gen>
import {Config, MailSlurp} from "mailslurp-client";
function register(Cypress: Cypress.Cypress) {
//<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 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, () => {
Cypress.Commands.add('mailslurp' as any, ((config?: Config) => {
// read the API Key from environment variable (see the API Key section of README)
const apiKey = config?.apiKey ?? Cypress.env('MAILSLURP_API_KEY');
if (!apiKey) {
throw new Error(
'Error no MailSlurp API Key. Please either pass the mailslurp command a valid Config object or 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.'
);
}
const mailslurp = new MailSlurp({ ...config, apiKey, basePath: 'https://cypress.api.mailslurp.com' });
return Promise.resolve(mailslurp);
});
//</gen>
}) as any);
}
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