mongo-scenario
Advanced tools
Comparing version 0.0.0 to 1.0.0
@@ -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). |
@@ -13,3 +13,3 @@ { | ||
"include": ["src/*.ts"], | ||
"exclude": ["node_modules"] | ||
"exclude": ["node_modules", "src/*.spec.ts"] | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
13236
17
246
1
60
1
9
2
1
+ Addedjs-yaml@^3.13.1
+ Addedargparse@1.0.10(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedsprintf-js@1.0.3(transitive)