From 6776d052452df683c18201b42f8e3a0694420938 Mon Sep 17 00:00:00 2001 From: Harald Kubota Date: Mon, 19 Jul 2021 17:09:06 +0900 Subject: [PATCH] Remove the need for live MongoDB for test --- package.json | 1 + test/app.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/package.json b/package.json index c3904177..9618c564 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,7 @@ "eslint-plugin-chai-friendly": "^0.6.0", "eslint-plugin-import": "^2.22.1", "mocha": "^8.2.1", + "mongodb-memory-server": "^7.2.1", "nyc": "^15.1.0", "sinon": "^9.2.3", "supertest": "^6.0.1" diff --git a/test/app.js b/test/app.js index 06f62a4c..ca63847e 100644 --- a/test/app.js +++ b/test/app.js @@ -1,4 +1,12 @@ const request = require('supertest'); + +const { MongoMemoryServer } = require('mongodb-memory-server'); + +(async () => { +const mongoServer = await MongoMemoryServer.create(); +const mockMongoDBUri = await mongoServer.getUri(); +process.env.MONGODB_URI=mockMongoDBUri; + const app = require('../app.js'); describe('GET /', () => { @@ -104,3 +112,5 @@ describe('GET /random-url', () => { .expect(404, done); }); }); + +})();