Skip to content

Commit a68ae57

Browse files
Merge pull request nestjs#2816 from nestjs/6.6.0
chore() minor release [6.6.0]
2 parents aa9dfbb + d01a798 commit a68ae57

208 files changed

Lines changed: 4153 additions & 772 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.circleci/config.yml

Lines changed: 111 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
11
version: 2
2+
3+
aliases:
4+
- &restore-cache
5+
restore_cache:
6+
key: dependency-cache-{{ checksum "package.json" }}
7+
- &install-deps
8+
run:
9+
name: Install dependencies
10+
command: npm ci
11+
- &build-packages
12+
run:
13+
name: Build
14+
command: npm run build
15+
- &run-unit-tests
16+
run:
17+
name: Test
18+
command: npm run test
19+
20+
unit-tests-template: &unit-tests-template
21+
working_directory: ~/nest
22+
steps:
23+
- checkout
24+
- *restore-cache
25+
- *install-deps
26+
- *build-packages
27+
- *run-unit-tests
28+
229
jobs:
330
build:
431
working_directory: ~/nest
@@ -22,47 +49,112 @@ jobs:
2249
name: Build
2350
command: npm run build
2451

25-
test:
52+
test_node_12:
2653
working_directory: ~/nest
2754
docker:
2855
- image: circleci/node:12
2956
steps:
3057
- checkout
31-
- restore_cache:
32-
name: Restore node_modules cache
33-
key: dependency-cache-{{ checksum "package.json" }}
34-
- run:
35-
name: Install dependencies
36-
command: npm ci
58+
- *restore-cache
59+
- *install-deps
60+
- *build-packages
61+
- *run-unit-tests
3762
- run:
38-
name: Build (dev)
39-
command: npm run build
40-
- run:
41-
name: Test
42-
command: npm run test
63+
name: Collect coverage
64+
command: npm run coverage
65+
- store_artifacts:
66+
path: coverage
67+
68+
test_node_10:
69+
<<: *unit-tests-template
70+
docker:
71+
- image: circleci/node:10
72+
73+
test_node_8:
74+
<<: *unit-tests-template
75+
docker:
76+
- image: circleci/node:8
77+
4378
lint:
4479
working_directory: ~/nest
4580
docker:
4681
- image: circleci/node:12
4782
steps:
4883
- checkout
49-
- restore_cache:
50-
name: Restore node_modules cache
51-
key: dependency-cache-{{ checksum "package.json" }}
52-
- run:
53-
name: Install dependencies
54-
command: npm ci
84+
- *restore-cache
85+
- *install-deps
5586
- run:
5687
name: Lint
5788
command: npm run lint
89+
90+
integration_tests:
91+
working_directory: ~/nest
92+
machine: true
93+
steps:
94+
- checkout
95+
- run:
96+
name: Prepare nvm
97+
command: |
98+
echo 'export NVM_DIR="/opt/circleci/.nvm"' >> $BASH_ENV
99+
echo ' [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
100+
- run:
101+
name: Upgrade Node.js
102+
command: |
103+
nvm install v12
104+
node -v
105+
nvm alias default v12
106+
- run:
107+
name: Install Docker Compose
108+
command: |
109+
curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
110+
chmod +x ~/docker-compose
111+
sudo mv ~/docker-compose /usr/local/bin/docker-compose
112+
- *install-deps
113+
- run:
114+
name: Prepare tests
115+
command: |
116+
bash ./scripts/prepare.sh
117+
sleep 10
118+
- run:
119+
name: List containers
120+
command: docker ps
121+
- run:
122+
name: Integration tests
123+
command: npm run integration-test
124+
125+
samples:
126+
working_directory: ~/nest
127+
docker:
128+
- image: circleci/node:12
129+
steps:
130+
- checkout
131+
- *restore-cache
132+
- *install-deps
133+
- run:
134+
name: Build all samples
135+
command: npm run build:samples
136+
58137
workflows:
59138
version: 2
60139
build-and-test:
61140
jobs:
62141
- build
63-
- test:
142+
- test_node_12:
143+
requires:
144+
- build
145+
- test_node_10:
146+
requires:
147+
- build
148+
- test_node_8:
64149
requires:
65150
- build
66151
- lint:
67152
requires:
68153
- build
154+
- integration_tests:
155+
requires:
156+
- build
157+
- samples:
158+
requires:
159+
- build
160+

.travis.yml

Lines changed: 0 additions & 56 deletions
This file was deleted.

Readme.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>
33
</p>
44

5-
[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master
6-
[travis-url]: https://travis-ci.org/nestjs/nest
7-
[linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux
8-
[linux-url]: https://travis-ci.org/nestjs/nest
5+
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
6+
[circleci-url]: https://circleci.com/gh/nestjs/nest
97

108
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
119
<p align="center">
1210
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
1311
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
1412
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a>
15-
<a href="https://travis-ci.org/nestjs/nest" target="_blank"><img src="https://api.travis-ci.org/nestjs/nest.svg?branch=master" alt="Travis" /></a>
16-
<a href="https://travis-ci.org/nestjs/nest" target="_blank"><img src="https://img.shields.io/travis/nestjs/nest/master.svg?label=linux" alt="Linux" /></a>
13+
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
1714
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
1815
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
1916
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { INestApplication, MiddlewareConsumer, Module } from '@nestjs/common';
2+
import { Test } from '@nestjs/testing';
3+
import * as request from 'supertest';
4+
5+
const RETURN_VALUE_A = 'test_A';
6+
const RETURN_VALUE_B = 'test_B';
7+
8+
@Module({
9+
imports: [],
10+
})
11+
class ModuleA {
12+
configure(consumer: MiddlewareConsumer) {
13+
consumer
14+
.apply((req, res, next) => {
15+
res.send(RETURN_VALUE_A);
16+
})
17+
.forRoutes('hello');
18+
}
19+
}
20+
21+
@Module({
22+
imports: [ModuleA],
23+
})
24+
class ModuleB {
25+
configure(consumer: MiddlewareConsumer) {
26+
consumer
27+
.apply((req, res, next) => {
28+
res.send(RETURN_VALUE_B);
29+
})
30+
.forRoutes('hello');
31+
}
32+
}
33+
34+
@Module({
35+
imports: [ModuleB],
36+
})
37+
class TestModule {}
38+
39+
describe('Middleware (execution order)', () => {
40+
let app: INestApplication;
41+
42+
beforeEach(async () => {
43+
app = (await Test.createTestingModule({
44+
imports: [TestModule],
45+
}).compile()).createNestApplication();
46+
47+
await app.init();
48+
});
49+
50+
it(`should execute middleware of dependent modules first `, () => {
51+
return request(app.getHttpServer())
52+
.get('/hello')
53+
.expect(200, RETURN_VALUE_A);
54+
});
55+
56+
afterEach(async () => {
57+
await app.close();
58+
});
59+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Injectable, BeforeApplicationShutdown } from '@nestjs/common';
2+
import { Test } from '@nestjs/testing';
3+
import { expect } from 'chai';
4+
import * as Sinon from 'sinon';
5+
6+
@Injectable()
7+
class TestInjectable implements BeforeApplicationShutdown {
8+
beforeApplicationShutdown = Sinon.spy();
9+
}
10+
11+
describe('BeforeApplicationShutdown', () => {
12+
it('should call `beforeApplicationShutdown` when application closes', async () => {
13+
const module = await Test.createTestingModule({
14+
providers: [TestInjectable],
15+
}).compile();
16+
17+
const app = module.createNestApplication();
18+
await app.close();
19+
const instance = module.get(TestInjectable);
20+
expect(instance.beforeApplicationShutdown.called).to.be.true;
21+
});
22+
23+
it('should not stop the server once beforeApplicationShutdown has been called', async () => {
24+
let resolve;
25+
const promise = new Promise(r => (resolve = r));
26+
const module = await Test.createTestingModule({
27+
providers: [
28+
{
29+
provide: 'Test',
30+
useValue: {
31+
beforeApplicationShutdown: () => promise,
32+
},
33+
},
34+
],
35+
}).compile();
36+
Sinon.stub(module, 'dispose' as any);
37+
const app = module.createNestApplication();
38+
39+
app.close();
40+
41+
expect(((module as any).dispose as Sinon.SinonSpy).called, 'dispose')
42+
.to.be.false;
43+
44+
resolve();
45+
46+
setTimeout(
47+
() =>
48+
expect(
49+
((module as any).dispose as Sinon.SinonSpy).called,
50+
'dispose',
51+
).to.be.true,
52+
0,
53+
);
54+
});
55+
});

0 commit comments

Comments
 (0)