-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(all): fixes OgmaCoreModule not configured
Due to how static class members are created in JavaScript and ran at import time rather than call time `OgmaCoreModule.Deferred` was immediately calling `OgmaCoreModule.externallyConfigured(OgmaCoreModule, 0)` which was causing Jest and the Node REPL to throw an error on import of `@ogma/nestjs-module`. This has been remedied and verified by unit tests, integration tests, and manual tests with imports from the REPL itself. fix #106
- Loading branch information
Showing
5 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { OgmaModule } from '../src'; | ||
import { AppService } from './app.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
OgmaModule.forRoot({ | ||
interceptor: false, | ||
}), | ||
OgmaModule.forFeature(AppService), | ||
], | ||
providers: [AppService], | ||
}) | ||
export class AppModule {} |
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,36 @@ | ||
import { AppService } from './app.service'; | ||
import { Test } from '@nestjs/testing'; | ||
|
||
describe('AppService', () => { | ||
let service: AppService; | ||
let logger: { log: jest.Mock }; | ||
|
||
beforeEach(async () => { | ||
const modRef = await Test.createTestingModule({ | ||
providers: [ | ||
AppService, | ||
{ | ||
provide: 'OGMA_SERVICE:AppService', | ||
useValue: { | ||
log: jest.fn(), | ||
}, | ||
}, | ||
], | ||
}).compile(); | ||
service = modRef.get(AppService); | ||
logger = modRef.get<{ log: jest.Mock }>('OGMA_SERVICE:AppService'); | ||
}); | ||
|
||
it('should be truthy', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should return { hello: world }', () => { | ||
expect(service.getHello()).toEqual({ hello: 'world' }); | ||
expect(logger.log).toHaveBeenCalledWith('Say Hello'); | ||
}); | ||
}); | ||
|
||
process.on('unhandledRejection', (err) => { | ||
throw new Error(err as any); | ||
}); |
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 { Injectable } from '@nestjs/common'; | ||
import { OgmaLogger, OgmaService } from '../src'; | ||
|
||
@Injectable() | ||
export class AppService { | ||
constructor(@OgmaLogger(AppService) private readonly logger: OgmaService) {} | ||
|
||
getHello() { | ||
this.logger.log('Say Hello'); | ||
return { hello: 'world' }; | ||
} | ||
} |