Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redisStore is not ending when tests finishes #58

Open
ejose19 opened this issue Sep 7, 2019 · 1 comment
Open

redisStore is not ending when tests finishes #58

ejose19 opened this issue Sep 7, 2019 · 1 comment

Comments

@ejose19
Copy link

ejose19 commented Sep 7, 2019

A very simplified code to view the problem:

app.ts

import * as Koa from "koa";
import * as redisStore from "koa-redis";

const app = new Koa();
const store = redisStore({});
export default app;

app.test.ts

import * as supertest from "supertest";
import app from "../src/app";

const request = supertest(app.callback());

describe("test", () => {
  test("route GET /", async () => {
    const response = await request.get("/");
    expect(response.status).toEqual(404);
  });
});

Jest complains that "there are asynchronous operations that weren't stopped in your tests", if I comment out
const store = redisStore({});

then it closes as expected, so I figured the issue is caused by this library. Anything I need to implement in code/tests or this is a bug?

@ejose19
Copy link
Author

ejose19 commented Sep 7, 2019

As a workaround, I'm doing this:

on app.ts

const store: any = redisStore({});
app.on("close", () => {
  store.client.disconnect();
});

app.test.ts

afterAll(() => {
  app.emit("close");
});

Had to use :any to the store as it's not detecting client without it, honestly this seems a bit ugly and a better solution is expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant