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

mongo-scenario

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongo-scenario

Generate sample data in MongoDB for running integration tests

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

Mongo Scenario

Quickly and accurately create test data in a MongoDB for repeatable and reliable integration tests.

Quick Start

yarn add -D mongo-scenario

./scenarios/one.yml

description: A basic test scenario
data:
    - users:
      - one:
        _id: 1
        name: John
        email: john@foo.bar
      - two:
        _id: 2
        name: Jane
        email: jane@foo.bar
    - tasks:
      - three:
        name: Take out trash
        user: 2
      - four:
        name: Grocery shopping
        user: 1

foo.spec.js

import Scenario from 'mongo-scenario'

const db = connectToMongo()

const scenario = new Scenario(db)

describe('my test', () => {
  before(() => {
    scenario.load('one')
  })
  after(() => {
    scenario.unloadAll()
  })
  
  it('has the data', () => {
    assert(users.list.length, 2)
  })
})

In the trivial example above, we describe our scenario in terms of the data that we want loaded into our MongoDB. In the setup code of our test, we then load up a new database connection and pass it to the mongo-scenario constructor. In the before block we load the specified scenario that we want to run tests against. The final step in the after block is to unload the scenario, in this case we unload all scenarios that may be loaded.

Overview

At it's heart, mongo-scenario is nothing more than a YAML to JavaScript parser that inserts and deletes specific records into a running MongoDB instance. Which MongoDB instance does it use? Any one that give it. It could be a seven shard atlas cluster, a local test database or even in memory.

FAQs

Package last updated on 06 May 2019

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