New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 - npm Package Compare versions

Comparing version 0.0.0 to 1.0.0

db/scenarios/one.yml

1

jest.config.js

@@ -10,2 +10,3 @@ module.exports = {

verbose: true,
preset: "@shelf/jest-mongodb",
}
{
"name": "mongo-scenario",
"version": "0.0.0",
"version": "1.0.0",
"description": "Generate sample data in MongoDB for running integration tests",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": "https://github.com/janders223/mongo-scenario",

@@ -11,7 +12,20 @@ "author": "Jim Anders <jim@janders223.com>",

"devDependencies": {
"@shelf/jest-mongodb": "^1.0.1",
"@types/jest": "^24.0.12",
"@types/js-yaml": "^3.12.1",
"@types/mongodb": "^3.1.26",
"jest": "^24.7.1",
"mongodb": "^3.2.3",
"mongodb-memory-server": "^5.1.0",
"ts-jest": "^24.0.2",
"typescript": "^3.4.5"
},
"scripts": {
"build": "rimraf dist && tsc",
"test": "jest",
"lint": "prettier src/**/*.ts"
},
"dependencies": {
"js-yaml": "^3.13.1"
}
}

@@ -8,1 +8,53 @@ # Mongo Scenario

`yarn add -D mongo-scenario`
`./scenarios/one.yml`
```yaml
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`
```javascript
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](https://github.com/nodkz/mongodb-memory-server#available-options).

2

tsconfig.json

@@ -13,3 +13,3 @@ {

"include": ["src/*.ts"],
"exclude": ["node_modules"]
"exclude": ["node_modules", "src/*.spec.ts"]
}
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