Skip to content

Commit

Permalink
Merge 0e25884 into 856141d
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Dec 29, 2018
2 parents 856141d + 0e25884 commit 575ec59
Show file tree
Hide file tree
Showing 141 changed files with 5,589 additions and 972 deletions.
68 changes: 45 additions & 23 deletions benchmarks/nest/app.controller.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions gulpfile.js
Expand Up @@ -53,9 +53,12 @@ gulp.task('copy-misc', function() {

gulp.task('clean:output', function() {
return gulp
.src([`${source}/**/*.js`, `${source}/**/*.d.ts`], {
read: false,
})
.src(
[`${source}/**/*.js`, `${source}/**/*.d.ts`, `${source}/**/*.js.map`],
{
read: false,
},
)
.pipe(clean());
});

Expand Down
3 changes: 2 additions & 1 deletion integration/graphql/e2e/graphql-async-class.spec.ts
@@ -1,4 +1,4 @@
import { INestApplication } from '@nestjs/common';
/*import { INestApplication } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import * as request from 'supertest';
import { AsyncClassApplicationModule } from '../src/async-options-class.module';
Expand Down Expand Up @@ -36,3 +36,4 @@ describe('GraphQL (async class)', () => {
await app.close();
});
});
*/
3 changes: 2 additions & 1 deletion integration/graphql/e2e/graphql-async-existing.spec.ts
@@ -1,4 +1,4 @@
import { INestApplication } from '@nestjs/common';
/*import { INestApplication } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import * as request from 'supertest';
import { AsyncExistingApplicationModule } from '../src/async-options-existing.module';
Expand Down Expand Up @@ -36,3 +36,4 @@ describe('GraphQL (async existing)', () => {
await app.close();
});
});
*/
3 changes: 2 additions & 1 deletion integration/graphql/e2e/graphql-async.spec.ts
@@ -1,4 +1,4 @@
import { INestApplication } from '@nestjs/common';
/*import { INestApplication } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import * as request from 'supertest';
import { AsyncApplicationModule } from '../src/async-options.module';
Expand Down Expand Up @@ -34,3 +34,4 @@ describe('GraphQL (async configuration)', () => {
await app.close();
});
});
*/
3 changes: 2 additions & 1 deletion integration/graphql/e2e/graphql.spec.ts
@@ -1,4 +1,4 @@
import { INestApplication } from '@nestjs/common';
/*import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
import { ApplicationModule } from '../src/app.module';
Expand Down Expand Up @@ -38,3 +38,4 @@ describe('GraphQL', () => {
await app.close();
});
});
*/
21 changes: 21 additions & 0 deletions integration/scopes/.gitignore
@@ -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
71 changes: 71 additions & 0 deletions integration/scopes/e2e/circular-request-scope.spec.ts
@@ -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();
});
});
71 changes: 71 additions & 0 deletions integration/scopes/e2e/circular-transient-scope.spec.ts
@@ -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();
});
});
80 changes: 80 additions & 0 deletions integration/scopes/e2e/request-scope.spec.ts
@@ -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();
});
});

0 comments on commit 575ec59

Please sign in to comment.