Registry / testing / mongodb-cypress

mongodb-cypress

JSON →
library1.2.0jsnpmunverified

A plugin for Cypress that provides MongoDB interaction capabilities directly within Cypress tests. Version 1.2.0 includes TypeScript definitions and integrates with Cypress 10 and later via setupNodeEvents. It offers CRUD operations as Cypress chainable commands (e.g., cy.mongoFindMany) and task-based execution. Compared to alternatives like cypress-mongodb, it supports connection options and is maintained on GitHub.

npm install mongodb-cypress
INSTALL
IMPORT
SIG · MONGODB-CYPRESS
M
mongodb-cypress
testingjavascriptv1.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

mongoSetup
const { mongoSetup } = require('mongodb-cypress');
import { mongoSetup } from 'mongodb-cypress';
CommonJS required by Cypress config files; ESM not supported for task registration.
mongoFunctions
const { mongoFunctions } = require('mongodb-cypress'); mongoFunctions();
cy.mongoFunctions()
This is a setup function, not a Cypress chainable; call it in support/commands.js to register all commands.
cy.mongoFindMany
cy.mongoFindMany('collection', { field: 'value' })
cy.task('mongoFindMany', ...)
Directly available as chainable after mongoFunctions() call.

Sets up mongodb-cypress with Cypress 10+ config and registers commands, then uses cy.mongoInsertOne and cy.mongoFindMany in a test.

// cypress.config.js const { defineConfig } = require('cypress'); const { mongoSetup } = require('mongodb-cypress'); module.exports = defineConfig({ e2e: { setupNodeEvents(on, config) { on('task', mongoSetup(config.env.mongodb)); }, }, env: { mongodb: { uri: process.env.MONGO_URI ?? 'mongodb://localhost:27017', db: 'test', options: {} }, }, }); // cypress/support/commands.js const { mongoFunctions } = require('mongodb-cypress'); mongoFunctions(); // Then in a test: cy.mongoInsertOne('users', { name: 'Alice' }); cy.mongoFindMany('users', { name: 'Alice' }).then(docs => { expect(docs).to.have.length(1); });
Debug
Known issues
gotchaTask names (e.g., mongoFindMany) are registered automatically but may conflict with other plugins using the same task names.
fix
Prefix your own task names or avoid using same names as those exposed by mongoFunctions.
affects: >=1.0.0
breakingCypress v10 changed plugin configuration from plugins/index.js to cypress.config.js setupNodeEvents.
fix
Use the Cypress 10+ configuration pattern shown in the README.
affects: >=10.0.0
gotchaConnection options are required in Cypress env under mongodb key; missing env will cause errors.
fix
Ensure cypress.env.json or config env includes mongodb with uri and db fields.
affects: >=1.0.0
Errors
Common errors & fixes
cy.mongoFindMany is not a function
mongoFunctions() not called in support/commands.js.
fix
Add mongoFunctions() call in cypress/support/commands.js after require.
TypeError: Cannot read properties of undefined (reading 'uri')
Missing or misconfigured env.mongodb in Cypress config
fix
Set env.mongodb.uri and env.mongodb.db in cypress.config.js or cypress.env.json.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
mongodbrequiredMongoDB driver for database operations
Agent activity
9 hits · last 30 days
node
8
Resources
mongodb-cypress — npm install mongodb-cypress · libregistry