chore: refactor server test setup (#3976)

* chore: refactor server test setup

* Close dangling redis connections instead of mocking rate limiter
  specific modules
* Segregate pre and post env test setup

* fix: remove mock file
This commit is contained in:
Apoorv Mishra
2022-08-16 09:16:57 +05:30
committed by GitHub
parent 93bb9d067d
commit 7a758f84a0
4 changed files with 21 additions and 45 deletions

14
server/test/env.ts Normal file
View File

@@ -0,0 +1,14 @@
import env from "../env";
// test environment variables
env.SMTP_HOST = "smtp.example.com";
env.ENVIRONMENT = "test";
env.GOOGLE_CLIENT_ID = "123";
env.GOOGLE_CLIENT_SECRET = "123";
env.SLACK_CLIENT_ID = "123";
env.SLACK_CLIENT_SECRET = "123";
env.DEPLOYMENT = undefined;
if (process.env.DATABASE_URL_TEST) {
env.DATABASE_URL = process.env.DATABASE_URL_TEST;
}

View File

@@ -1,25 +1,10 @@
import env from "../env";
import Redis from "@server/redis";
// test environment variables
env.SMTP_HOST = "smtp.example.com";
env.ENVIRONMENT = "test";
env.GOOGLE_CLIENT_ID = "123";
env.GOOGLE_CLIENT_SECRET = "123";
env.SLACK_CLIENT_ID = "123";
env.SLACK_CLIENT_SECRET = "123";
env.DEPLOYMENT = undefined;
if (process.env.DATABASE_URL_TEST) {
env.DATABASE_URL = process.env.DATABASE_URL_TEST;
}
// NOTE: this require must come after the ENV var override above
// NOTE: this require must come after the ENV var override
// so that sequelize uses the test config variables
require("@server/database/sequelize");
jest.mock("bull");
jest.mock("rate-limiter-flexible");
jest.mock("../RateLimiter");
// This is needed for the relative manual mock to be picked up
jest.mock("../queues");
@@ -42,3 +27,5 @@ jest.mock("aws-sdk", () => {
});
jest.mock("@getoutline/y-prosemirror", () => ({}));
afterAll(() => Redis.defaultClient.disconnect());