1.1.0 • Published 7 months ago

mongodb-cypress v1.1.0

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
7 months ago

mongodb-cypress

A plugin for Cypress for interacting with Mongodb

Integrate package with Cypress

Cypress 10 and later

Setup your cypress.config.js like:

const mongoCypress = require("mongodb-cypress");

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on("task", mongoCypress.mongoSetup(config.env.mongodb));
    },
  },
  env: {
    mongodb: {
      uri: "<connectio uri>",
      db: "<db>",
      options:{}
    },
  },
});

Setup your support/commands.js like:

const mongoCypress = require("mongodb-cypress");
mongoCypress.mongoFunctions();

Cypress before v10

Setup your plugins/index.js like:

const mongoCypress = require("mongodb-cypress");

module.exports = (on, config) => {
  on("task", mongoCypress.mongoSetup(config.env.mongodb));
};

And add the following to support/commands.js:

const mongoCypress = require("mongodb-cypress");
mongoCypress.mongoFunctions();

Mongodb Connection Options and Usage

In order to custom to your mongo connection, add the connection options to cypress.json under mongodb.options like:

"env": {
  "mongodb":{
      "uri": "<connection uri>",
      "db" : "<db connecting to>",
      "options" : {}
  }
}

Integrated Functionalities

mongoFindMany(
  collection: string,
  filter?: Filter<Document>,
  options?: FindOptions
): Promise<WithId<Document>[]>;
mongoFindOne(
  collection: string,
  filter?: Filter<Document>,
  options?: FindOptions
): Promise<Document | null>;
mongoInsertOne(
  collection: string,
  item: OptionalId<Document>,
  options?: InsertOneOptions
): Promise<InsertOneResult<Document>>;
mongoInsertMany(
  collection: string,
  item: OptionalId<Document>[],
  options?: BulkWriteOptions
): Promise<InsertManyResult<Document>>;
mongoDeleteMany(
  collection: string,
  filter?: Filter<Document>
): Promise<DeleteResult>;
mongoDeleteOne(
  collection: string,
  filter?: Filter<Document>
): Promise<DeleteResult>;
mongoUpdateMany(
  collection: string,
  filter: Filter<Document>,
  update: UpdateFilter<Document>
): Promise<UpdateResult>;
mongoUpdateOne(
  collection: string,
  filter: Filter<Document>,
  update: UpdateFilter<Document>
): Promise<UpdateResult>;

All commands are integrated into the Cypress Chainable interface, so they can be called as: cy.mongoFindMany("categories", { cat: "Llibres" })

1.1.0

7 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

1 year ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago