Targeted Version: 5.1.6
This will update the document on every call. Not the best option however it is atomic.
Ref: findOneAndUpdate
// product.test.js | |
const axios = require('axios') | |
const driver = require('../src/store/driver') | |
const httpSetup = require('./setup/http-setup') | |
const log = require('../src/logger') | |
let listener | |
beforeAll(async function () { | |
await driver.connect(global.__MONGO_URI__) |
// mongo-environment.js | |
const NodeEnvironment = require('jest-environment-node') | |
const path = require('path') | |
const fs = require('fs') | |
const globalConfigPath = path.join(__dirname, 'globalConfig.json') | |
const log = require('../../src/logger') | |
class MongoEnvironment extends NodeEnvironment { | |
constructor (config) { | |
super(config) |
// db-setup.js | |
const path = require('path') | |
const fs = require('fs') | |
const { MongoMemoryServer } = require('mongodb-memory-server') | |
const driver = require('../../src/store/driver') | |
const initializeDb = require('../initialize-db') | |
const globalConfigPath = path.join(__dirname, 'globalConfig.json') | |
const mongod = new MongoMemoryServer({ |
// global-setup.js | |
const dbSetup = require('./db-setup') | |
module.exports = async function () { | |
await dbSetup() | |
} |
//app.js | |
// Constants | |
const MAX_CONTENT_LENGTH_ACCEPTED = 102400000 | |
const COOKIESIGNSECRET = process.env.COOKIESIGNSECRET | |
// Core Modules | |
const express = require('express') | |
const bodyParser = require('body-parser') | |
const cookieParser = require('cookie-parser') |
// package.json <= JSON does not support comments. Remove this line. | |
{ | |
"name": "example", | |
"version": "1.0.0", | |
"description": "Example for test script", | |
"main": "index.js", | |
"scripts": { | |
"test": "LOGENABLED=true LOGLEVEL=error DBCONNECTIONPOOLMAX=10 DBCONNECTIONPOOLIDLE=50 jest --watch" | |
}, | |
"author": "", |
// jest.config.js | |
module.exports = { | |
clearMocks: true, | |
globalSetup: '<rootDir>/tests/setup/global-setup.js', | |
globalTeardown: '<rootDir>/tests/setup/global-teardown.js', | |
testEnvironment: '<rootDir>/tests/setup/mongo-environment.js' | |
} |
{ | |
"workbench.colorTheme": "Solarized Light", | |
"workbench.editor.closeEmptyGroups": false, | |
"explorer.openEditors.visible": 0, | |
"explorer.autoReveal": false, | |
"editor.tabSize": 2, | |
"gitlens.advanced.messages": { | |
"suppressCommitHasNoPreviousCommitWarning": false, | |
"suppressCommitNotFoundWarning": false, | |
"suppressFileNotUnderSourceControlWarning": false, |
Targeted Version: 5.1.6
This will update the document on every call. Not the best option however it is atomic.
Ref: findOneAndUpdate
I hereby claim:
To claim this, I am signing this object: