test-utils
raw JSON → 1.1.1 verified Sat Apr 25 auth: no javascript
A Node.js package providing MongoDB test utilities. It requires Node >= 8.9.1, Yarn >= 1.3.2, and mtools >= 1.3.2 (Python). The package has infrequent releases; the last stable version is 1.1.1. It integrates with Python-based mtools for MongoDB testing. Key differentiators include dependency on Python ecosystem and explicit version requirements.
Common errors
error Error: Cannot find module 'mtools' ↓
cause Python mtools package is not installed.
fix
Run: pip install mtools pymongo numpy psutil python-dateutil
error Error: The engine "node" is incompatible with this module. Expected version ">= 8.9.1". Got "x.x.x" ↓
cause Current Node version is below 8.9.1.
fix
Upgrade Node to version 8.9.1 or later.
Warnings
gotcha Requires Python packages (mtools, pymongo, etc.) to be installed via pip. ↓
fix Run: pip install mtools pymongo numpy psutil python-dateutil
gotcha Minimum Node version 8.9.1; not compatible with older Node versions. ↓
fix Upgrade Node to 8.9.1 or later.
gotcha Minimum Yarn version 1.3.2 required; using older Yarn may cause issues. ↓
fix Install Yarn 1.3.2+.
Install
npm install test-utils yarn add test-utils pnpm add test-utils Imports
- defaultExport wrong
const testUtils = require('test-utils')correctimport testUtils from 'test-utils'
Quickstart
import testUtils from 'test-utils';
// Example: create a test MongoDB instance
const mongo = await testUtils.startMongo();
console.log('MongoDB started on port', mongo.port);
// Use the instance
const db = await mongo.db('test');
await db.collection('test').insertOne({ key: 'value' });
const doc = await db.collection('test').findOne({ key: 'value' });
console.log(doc);
// Stop
await mongo.stop();