Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cypress-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypress-mongodb

Cypress MongoDB plugin

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12K
increased by30.17%
Maintainers
1
Weekly downloads
 
Created
Source

Introduction

Plugin that allows interaction with MongoDB server using Cypress commands.

Installation

run npm install cypress-mongodb
configure (see below)
profit

Usage

cy.createCollection('new_collection', 'new_database'); // creates both collection and database

const oneDocument = {document: 1};
cy.insertOne(oneDocument, 'some_collection', 'some_database').then(res => {
    cy.log(res); // print the id of inserted document
});

const manyDocuments = [{document: 1}, {document: 2}];
cy.insertMany(manyDocuments, 'some_other_collection');

cy.deleteOne(oneDocument, 'new_collection', 'some_database');

cy.deleteMany(manyDocuments); // defaults to collection and database from env variables

const pipeline = []; // any kind of aggregation
cy.aggregate(pipeline).then(res => {
    cy.log(res); // print the result of the aggregation
});

cy.dropCollection('start_new').then(res => {
    cy.log(res);
});

Environment setup

Add the following env properties in your cypress.json file:

  "env": {
    "MONGODB_URI": "mongodb://localhost:27017",
    "MONGODB_DATABASE": "database_name",
    "MONGODB_COLLECTION": "collection_name"
  }

Note: only MONGODB_URI is mandatory, you can always override/set database and collection names in each cypress mongodb command. You can set both local and remote urls.

Plugin configuration - JavaScript

In your cypress/plugins/index.js add the following:

const mongo = require('cypress-mongodb');

module.exports = (on, config) => {
  mongo.setConfig(on);
}

In your cypress/index/index.js add the following:

const mongo = require('cypress-mongodb');
mongo.setupMongoDB();

Plugin configuration - TypeScript

In your cypress/plugins/index.ts add the following:

import * as mongo from 'cypress-mongodb';

/**
 * @type {Cypress.PluginConfig}
 */
export default (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) => {
    getCompareSnapshotsPlugin(on, config);
    mongo.setConfig(on);
}

In your cypress/index/index.ts add the following:

import * as mongo from "cypress-mongodb";
mongo.setupMongoDB();

Future development & support

Update command support.
Support for fixture files planned.
Please create feature requests for things you'd like to see.
Please raise issues for any problems you encounter.

Keywords

FAQs

Package last updated on 09 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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