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

Add init() to the application context interface #1592

Closed
ghost opened this issue Feb 26, 2019 · 3 comments
Closed

Add init() to the application context interface #1592

ghost opened this issue Feb 26, 2019 · 3 comments

Comments

@ghost
Copy link

ghost commented Feb 26, 2019

Hi guys,

for purpose of unit testing & integration testing, is there any way of having lifecycle events executed with TestingModule without calling createApplication? It would be great if you wouldn't have to start express server for each unit test and would have Init and Destroy lifecycle events properly executed after compilation of a testing module, or after calling some kind of init().


[ ] Regression 
[ ] Bug report
[x ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Lifecycle events not being executed within TestModule without creating express application.

Expected behavior

Lifecycle events get executed within TestModule after compilation or after calling some kind of init() or createApplicationContext().

Minimal reproduction of the problem with instructions

  beforeEach(async () => {
    const module = await Test.createTestingModule({
        imports: [CommonModule],
        providers: [CatsService],
      }).compile();

    catsService = module.get<CatsService>(CatsService);
  });

In this example, if CommonModule has lots of services which need proper initialisation and cleanup in OnModuleInit & OnModuleDestroy handlers, we are not able to init() the module without calling createApplication which will start express server.

What is the motivation / use case for changing the behavior?

Environment


Nest version: 5.7.1

 
For Tooling issues:
- Node version: 10.14.0
- Platform:  Mac

Others:

Many thanks

@kamilmysliwiec kamilmysliwiec changed the title TestingModule lifecycle events Add init() to the application context interface Feb 28, 2019
@kamilmysliwiec
Copy link
Member

close() should be available. We need to add init() though

@kamilmysliwiec
Copy link
Member

Published as 6.3.0

@lock
Copy link

lock bot commented Sep 23, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant