-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12035 from nestjs/fix/globals-in-lazy-modules
fix(core): allow importing providers from global modules in lazy modules
- Loading branch information
Showing
14 changed files
with
195 additions
and
46 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
integration/lazy-modules/e2e/lazy-import-global-modules.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
import * as chai from 'chai'; | ||
import { expect } from 'chai'; | ||
import chaiAsPromised = require('chai-as-promised'); | ||
import { AppModule } from '../src/app.module'; | ||
chai.use(chaiAsPromised); | ||
|
||
describe('Lazy imports', () => { | ||
let server; | ||
let app: INestApplication; | ||
|
||
beforeEach(async () => { | ||
const module = await Test.createTestingModule({ | ||
imports: [AppModule], | ||
}).compile(); | ||
|
||
app = module.createNestApplication(); | ||
server = app.getHttpAdapter().getInstance(); | ||
}); | ||
|
||
it(`should allow imports of global modules`, async () => { | ||
await expect(app.init()).to.eventually.be.fulfilled; | ||
}); | ||
|
||
afterEach(async () => { | ||
await app.close(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { LazyModuleLoader } from '@nestjs/core'; | ||
import { EagerModule } from './eager.module'; | ||
import { GlobalModule } from './global.module'; | ||
import { LazyModule } from './lazy.module'; | ||
|
||
@Module({ | ||
imports: [GlobalModule, EagerModule], | ||
}) | ||
export class AppModule { | ||
constructor(public loader: LazyModuleLoader) {} | ||
|
||
async onApplicationBootstrap() { | ||
await this.loader.load(() => LazyModule); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Module, Injectable } from '@nestjs/common'; | ||
import { GlobalService } from './global.module'; | ||
|
||
@Injectable() | ||
export class EagerService { | ||
constructor(public globalService: GlobalService) {} | ||
} | ||
|
||
@Module({ | ||
providers: [EagerService], | ||
}) | ||
export class EagerModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module, Injectable, Global } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class GlobalService { | ||
constructor() {} | ||
} | ||
|
||
@Global() | ||
@Module({ | ||
providers: [GlobalService], | ||
exports: [GlobalService], | ||
}) | ||
export class GlobalModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Module, Injectable } from '@nestjs/common'; | ||
import { GlobalService } from './global.module'; | ||
|
||
@Injectable() | ||
export class LazyService { | ||
constructor(public globalService: GlobalService) {} | ||
} | ||
|
||
@Module({ | ||
providers: [LazyService], | ||
}) | ||
export class LazyModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app.module'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
await app.listen(3000); | ||
} | ||
bootstrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.