-
Notifications
You must be signed in to change notification settings - Fork 71
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
Jest not exiting due to Redis hanging after compilation error with createTestingModule #340
Comments
You can use the unit testing: https://docs.nestjs.com/fundamentals/testing#testing-utilities |
@liaoliaots Thanks for those details, how could the Redis connection be closed manually if we did want to test against the real thing instead of mocking? |
Below is a simple example: // `RedisModule` configurations
import { Module } from '@nestjs/common';
import { RedisModule } from '@liaoliaots/nestjs-redis';
@Module({
imports: [
RedisModule.forRoot({
closeClient: false, // disable the built-in automatic close
readyLog: true,
config: {
host: 'localhost',
port: 6379,
password: 'authpassword'
}
})
]
})
export class AppModule {} // e2e testing, with `fastify`
describe('description', () => {
let app: NestFastifyApplication;
let client: Redis;
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [AppModule]
}).compile();
client = module.get<Redis>(getRedisToken(DEFAULT_REDIS_NAMESPACE));
app = module.createNestApplication<NestFastifyApplication>(new FastifyAdapter());
await app.init();
await (app.getHttpAdapter().getInstance() as FastifyInstance).ready();
});
afterAll(async () => {
await client.quit(); // close manually
await app.close();
});
}); |
Hi @liaoliaots, I'm still unable to get this to work. When the tests close, I get this error:
I've followed your instructions and this is how my tests are set up.
My
I'm really lost with this. Any help is appreciated? On a side node, would you be able to explain if there is a reason why the module doesn't tear down the Redis automatically? I would be happy to contribute a pull-request if needed. |
hi @mridang, did you find a workaround for this? Currently facing this issue too.. |
Hi @liaoliaots , thank you for all your hard work for this library
Expected Behavior
For a Jest test, Redis should close after test module (@nestjs/testing) encounters error during compilation.
Current Behavior
Redis hangs after encountering error during test module compilation.
testingModule
is undefined when error is encounteredWhen there's no error, it is closed properly via afterAll() and everything is fine.
Possible Solution
Saw a similar issue raised but its solution (setting
closeClient
to true) did not workSteps to Reproduce (for bugs)
Create testing module via createTestingModule (@nestjs/testing) and leave out required entity import
Context
Trying to ensure Jest exits properly after test run completion
Your Environment
The text was updated successfully, but these errors were encountered: