Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
141 changed files
with
5,589 additions
and
972 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# dependencies | ||
/node_modules | ||
|
||
# IDE | ||
/.idea | ||
/.awcache | ||
/.vscode | ||
|
||
# misc | ||
npm-debug.log | ||
|
||
# example | ||
/quick-start | ||
|
||
# tests | ||
/test | ||
/coverage | ||
/.nyc_output | ||
|
||
# dist | ||
/dist |
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,71 @@ | ||
import { INestApplication, Scope } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
import { expect } from 'chai'; | ||
import * as request from 'supertest'; | ||
import { HelloController } from '../src/circular-hello/hello.controller'; | ||
import { HelloModule } from '../src/circular-hello/hello.module'; | ||
import { HelloService } from '../src/circular-hello/hello.service'; | ||
import { UsersService } from '../src/circular-hello/users/users.service'; | ||
|
||
class Meta { | ||
static COUNTER = 0; | ||
constructor(private readonly helloService: HelloService) { | ||
Meta.COUNTER++; | ||
} | ||
} | ||
|
||
describe('Circular request scope', () => { | ||
let server; | ||
let app: INestApplication; | ||
|
||
before(async () => { | ||
const module = await Test.createTestingModule({ | ||
imports: [ | ||
HelloModule.forRoot({ | ||
provide: 'META', | ||
useClass: Meta, | ||
scope: Scope.REQUEST, | ||
}), | ||
], | ||
}).compile(); | ||
|
||
app = module.createNestApplication(); | ||
server = app.getHttpServer(); | ||
await app.init(); | ||
}); | ||
|
||
describe('when one service is request scoped', () => { | ||
before(async () => { | ||
const performHttpCall = end => | ||
request(server) | ||
.get('/hello') | ||
.end((err, res) => { | ||
if (err) return end(err); | ||
end(); | ||
}); | ||
await new Promise(resolve => performHttpCall(resolve)); | ||
await new Promise(resolve => performHttpCall(resolve)); | ||
await new Promise(resolve => performHttpCall(resolve)); | ||
}); | ||
|
||
it(`should create controller for each request`, async () => { | ||
expect(HelloController.COUNTER).to.be.eql(3); | ||
}); | ||
|
||
it(`should create service for each request`, async () => { | ||
expect(UsersService.COUNTER).to.be.eql(3); | ||
}); | ||
|
||
it(`should create service for each request`, async () => { | ||
expect(HelloService.COUNTER).to.be.eql(3); | ||
}); | ||
|
||
it(`should create provider for each inquirer`, async () => { | ||
expect(Meta.COUNTER).to.be.eql(3); | ||
}); | ||
}); | ||
|
||
after(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,71 @@ | ||
import { INestApplication, Scope } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
import { expect } from 'chai'; | ||
import * as request from 'supertest'; | ||
import { HelloController } from '../src/circular-transient/hello.controller'; | ||
import { HelloModule } from '../src/circular-transient/hello.module'; | ||
import { HelloService } from '../src/circular-transient/hello.service'; | ||
import { UsersService } from '../src/circular-transient/users/users.service'; | ||
|
||
class Meta { | ||
static COUNTER = 0; | ||
constructor(private readonly helloService: HelloService) { | ||
Meta.COUNTER++; | ||
} | ||
} | ||
|
||
describe('Circular transient scope', () => { | ||
let server; | ||
let app: INestApplication; | ||
|
||
before(async () => { | ||
const module = await Test.createTestingModule({ | ||
imports: [ | ||
HelloModule.forRoot({ | ||
provide: 'META', | ||
useClass: Meta, | ||
scope: Scope.TRANSIENT, | ||
}), | ||
], | ||
}).compile(); | ||
|
||
app = module.createNestApplication(); | ||
server = app.getHttpServer(); | ||
await app.init(); | ||
}); | ||
|
||
describe('when one service is request scoped', () => { | ||
before(async () => { | ||
const performHttpCall = end => | ||
request(server) | ||
.get('/hello') | ||
.end((err, res) => { | ||
if (err) return end(err); | ||
end(); | ||
}); | ||
await new Promise(resolve => performHttpCall(resolve)); | ||
await new Promise(resolve => performHttpCall(resolve)); | ||
await new Promise(resolve => performHttpCall(resolve)); | ||
}); | ||
|
||
it(`should create controller for each request`, async () => { | ||
expect(HelloController.COUNTER).to.be.eql(3); | ||
}); | ||
|
||
it(`should create service for each request`, async () => { | ||
expect(UsersService.COUNTER).to.be.eql(3); | ||
}); | ||
|
||
it(`should create service for each request`, async () => { | ||
expect(HelloService.COUNTER).to.be.eql(3); | ||
}); | ||
|
||
it(`should create provider for each inquirer`, async () => { | ||
expect(Meta.COUNTER).to.be.eql(7); | ||
}); | ||
}); | ||
|
||
after(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,80 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
import { expect } from 'chai'; | ||
import * as request from 'supertest'; | ||
import { Guard } from '../src/hello/guards/request-scoped.guard'; | ||
import { HelloController } from '../src/hello/hello.controller'; | ||
import { HelloModule } from '../src/hello/hello.module'; | ||
import { Interceptor } from '../src/hello/interceptors/logging.interceptor'; | ||
import { UserByIdPipe } from '../src/hello/users/user-by-id.pipe'; | ||
import { UsersService } from '../src/hello/users/users.service'; | ||
|
||
class Meta { | ||
static COUNTER = 0; | ||
constructor() { | ||
Meta.COUNTER++; | ||
} | ||
} | ||
|
||
describe('Request scope', () => { | ||
let server; | ||
let app: INestApplication; | ||
|
||
before(async () => { | ||
const module = await Test.createTestingModule({ | ||
imports: [ | ||
HelloModule.forRoot({ | ||
provide: 'META', | ||
useClass: Meta, | ||
}), | ||
], | ||
}).compile(); | ||
|
||
app = module.createNestApplication(); | ||
server = app.getHttpServer(); | ||
await app.init(); | ||
}); | ||
|
||
describe('when one service is request scoped', () => { | ||
before(async () => { | ||
const performHttpCall = end => | ||
request(server) | ||
.get('/hello') | ||
.end((err, res) => { | ||
if (err) return end(err); | ||
end(); | ||
}); | ||
await new Promise(resolve => performHttpCall(resolve)); | ||
await new Promise(resolve => performHttpCall(resolve)); | ||
await new Promise(resolve => performHttpCall(resolve)); | ||
}); | ||
|
||
it(`should create controller for each request`, async () => { | ||
expect(HelloController.COUNTER).to.be.eql(3); | ||
}); | ||
|
||
it(`should create service for each request`, async () => { | ||
expect(UsersService.COUNTER).to.be.eql(3); | ||
}); | ||
|
||
it(`should share static provider across requests`, async () => { | ||
expect(Meta.COUNTER).to.be.eql(1); | ||
}); | ||
|
||
it(`should create request scoped pipe for each request`, async () => { | ||
expect(UserByIdPipe.COUNTER).to.be.eql(3); | ||
}); | ||
|
||
it(`should create request scoped interceptor for each request`, async () => { | ||
expect(Interceptor.COUNTER).to.be.eql(3); | ||
}); | ||
|
||
it(`should create request scoped guard for each request`, async () => { | ||
expect(Guard.COUNTER).to.be.eql(3); | ||
}); | ||
}); | ||
|
||
after(async () => { | ||
await app.close(); | ||
}); | ||
}); |
Oops, something went wrong.