Skip to content

Commit 44c9250

Browse files
docs: v10 changes
1 parent 4530635 commit 44c9250

File tree

5 files changed

+47
-118
lines changed

5 files changed

+47
-118
lines changed

content/first-steps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ We'll mostly use TypeScript in the examples we provide, but you can always **swi
1010

1111
#### Prerequisites
1212

13-
Please make sure that [Node.js](https://nodejs.org) (version >= 12, except for v13) is installed on your operating system.
13+
Please make sure that [Node.js](https://nodejs.org) (version >= 16) is installed on your operating system.
1414

1515
#### Setup
1616

content/fundamentals/unit-testing.md

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,19 @@ describe('CatsController', () => {
177177
const moduleRef = await Test.createTestingModule({
178178
controllers: [CatsController],
179179
})
180-
.useMocker((token) => {
181-
const results = ['test1', 'test2'];
182-
if (token === CatsService) {
183-
return { findAll: jest.fn().mockResolvedValue(results) };
184-
}
185-
if (typeof token === 'function') {
186-
const mockMetadata = moduleMocker.getMetadata(token) as MockFunctionMetadata<any, any>;
187-
const Mock = moduleMocker.generateFromMetadata(mockMetadata);
188-
return new Mock();
189-
}
190-
})
191-
.compile();
192-
180+
.useMocker((token) => {
181+
const results = ['test1', 'test2'];
182+
if (token === CatsService) {
183+
return { findAll: jest.fn().mockResolvedValue(results) };
184+
}
185+
if (typeof token === 'function') {
186+
const mockMetadata = moduleMocker.getMetadata(token) as MockFunctionMetadata<any, any>;
187+
const Mock = moduleMocker.generateFromMetadata(mockMetadata);
188+
return new Mock();
189+
}
190+
})
191+
.compile();
192+
193193
controller = moduleRef.get(CatsController);
194194
});
195195
});
@@ -286,9 +286,7 @@ describe('Cats', () => {
286286
> let app: NestFastifyApplication;
287287
>
288288
> beforeAll(async () => {
289-
> app = moduleRef.createNestApplication<NestFastifyApplication>(
290-
> new FastifyAdapter(),
291-
> );
289+
> app = moduleRef.createNestApplication<NestFastifyApplication>(new FastifyAdapter());
292290
>
293291
> await app.init();
294292
> await app.getHttpAdapter().getInstance().ready();
@@ -315,18 +313,29 @@ In this example, we build on some of the concepts described earlier. In addition
315313
316314
We simulate HTTP tests using the `request()` function from Supertest. We want these HTTP requests to route to our running Nest app, so we pass the `request()` function a reference to the HTTP listener that underlies Nest (which, in turn, may be provided by the Express platform). Hence the construction `request(app.getHttpServer())`. The call to `request()` hands us a wrapped HTTP Server, now connected to the Nest app, which exposes methods to simulate an actual HTTP request. For example, using `request(...).get('/cats')` will initiate a request to the Nest app that is identical to an **actual** HTTP request like `get '/cats'` coming in over the network.
317315
318-
In this example, we also provide an alternate (test-double) implementation of the `CatsService` which simply returns a hard-coded value that we can test for. Use `overrideProvider()` to provide such an alternate implementation. Similarly, Nest provides methods to override guards, interceptors, filters and pipes with the`overrideGuard()`, `overrideInterceptor()`, `overrideFilter()`, and `overridePipe()` methods respectively.
316+
In this example, we also provide an alternate (test-double) implementation of the `CatsService` which simply returns a hard-coded value that we can test for. Use `overrideProvider()` to provide such an alternate implementation. Similarly, Nest provides methods to override modules, guards, interceptors, filters and pipes with the `overrideModule()`, `overrideGuard()`, `overrideInterceptor()`, `overrideFilter()`, and `overridePipe()` methods respectively.
319317
320-
Each of the override methods returns an object with 3 different methods that mirror those described for [custom providers](https://docs.nestjs.com/fundamentals/custom-providers):
318+
Each of the override methods (except for `overrideModule()`) returns an object with 3 different methods that mirror those described for [custom providers](https://docs.nestjs.com/fundamentals/custom-providers):
321319
322320
- `useClass`: you supply a class that will be instantiated to provide the instance to override the object (provider, guard, etc.).
323321
- `useValue`: you supply an instance that will override the object.
324322
- `useFactory`: you supply a function that returns an instance that will override the object.
325323
324+
On the other hand, `overrideModule()` returns an object with the `useModule()` method, which you can use to supply a module that will override the original module, as follows:
325+
326+
```typescript
327+
const moduleRef = await Test.createTestingModule({
328+
imports: [AppModule],
329+
})
330+
.overrideModule(CatsModule)
331+
.useModule(AlternateCatsModule)
332+
.compile();
333+
```
334+
326335
Each of the override method types, in turn, returns the `TestingModule` instance, and can thus be chained with other methods in the [fluent style](https://en.wikipedia.org/wiki/Fluent_interface). You should use `compile()` at the end of such a chain to cause Nest to instantiate and initialize the module.
327336

328337
Also, sometimes you may want to provide a custom logger e.g. when the tests are run (for example, on a CI server). Use the `setLogger()` method and pass an object that fulfills the `LoggerService` interface to instruct the `TestModuleBuilder` how to log during tests (by default, only "error" logs will be logged to the console).
329-
338+
330339
> warning **Warning** The `@nestjs/core` package exposes unique provider tokens with the `APP_` prefix to help on define global enhancers. Those tokens cannot be overridden since they can represent multiple providers. Thus you can't use `.overrideProvider(APP_GUARD)` (and so on). If you want to override some global enhancer, follow [this workaround](https://github.com/nestjs/nest/issues/4053#issuecomment-585612462).
331340
332341
The compiled module has several useful methods, as described in the following table:
@@ -430,9 +439,7 @@ To accomplish this, use `jest.spyOn()` on the `ContextIdFactory`:
430439

431440
```typescript
432441
const contextId = ContextIdFactory.create();
433-
jest
434-
.spyOn(ContextIdFactory, 'getByRequest')
435-
.mockImplementation(() => contextId);
442+
jest.spyOn(ContextIdFactory, 'getByRequest').mockImplementation(() => contextId);
436443
```
437444

438445
Now we can use the `contextId` to access a single generated DI container sub-tree for any subsequent request.

content/microservices/redis.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ The `options` property is specific to the chosen transporter. The <strong>Redis<
5858
<td><code>retryDelay</code></td>
5959
<td>Delay between message retry attempts (ms) (default: <code>0</code>)</td>
6060
</tr>
61+
<tr>
62+
<td><code>wildcards</code></td>
63+
<td>Enables Redis wilcard subscriptions, instructing transporter to use <code>psubscribe</code>/<code>pmessage</code> under the hood. (default: <code>false</code>)</td>
64+
</tr>
6165
</table>
6266

6367
All the properties supported by the official [ioredis](https://luin.github.io/ioredis/index.html#RedisOptions) client are also supported by this transporter.

content/migration.md

Lines changed: 13 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,25 @@
11
### Migration guide
22

3-
This article provides a set of guidelines for migrating from Nest version 8 to version 9.
4-
To learn more about the new features we've added in v9, check out this [link](https://github.com/nestjs/nest/pull/9588).
3+
This article provides a set of guidelines for migrating from Nest version 9 to version 10.
4+
To learn more about the new features we've added in v10, check out this [article](https://trilon.io/blog/nestjs-10-is-now-available).
5+
There were some very minor breaking changes that shouldn't affect most users - you can find the full list of them [here](https://github.com/nestjs/nest/pull/11517).
56

6-
#### Redis strategy (microservices)
7+
### Cache module
78

8-
[Redis](/microservices/redis) strategy uses the [ioredis](https://github.com/luin/ioredis) driver instead of `redis` now.
9+
The `CacheModule` has been removed from the `@nestjs/common` package and is now available as a standalone package - `@nestjs/cache-manager`. This change was made to avoid unnecessary dependencies in the `@nestjs/common` package. You can learn more about the `@nestjs/cache-manager` package [here](https://docs.nestjs.com/techniques/caching).
910

10-
```typescript
11-
// Before
12-
const app = await NestFactory.createMicroservice<MicroserviceOptions>(
13-
AppModule,
14-
{
15-
transport: Transport.REDIS,
16-
options: {
17-
url: 'redis://localhost:6379',
18-
},
19-
},
20-
);
21-
22-
// Now
23-
const app = await NestFactory.createMicroservice<MicroserviceOptions>(
24-
AppModule,
25-
{
26-
transport: Transport.REDIS,
27-
options: {
28-
host: 'localhost',
29-
port: 6379,
30-
},
31-
},
32-
);
33-
```
34-
35-
Also, make sure to install the `ioredis` package:
36-
37-
```bash
38-
$ npm i ioredis
39-
```
40-
41-
#### gRPC client interceptors
42-
43-
In the previous version, the `interceptors` configuration property was exposed in the wrong location. In v9, make sure to pass `interceptors` as part of the `channelOptions` object, see example [here](https://github.com/nestjs/nest/issues/9079#issuecomment-1078744758).
44-
45-
#### Testing module
46-
47-
Previously, if you wanted to supply the configuration object to the `TestingModule#createNestApplication` method, and if you were using the default HTTP driver (express), you had to do this as follows:
48-
49-
```typescript
50-
app = moduleFixture.createNestApplication<NestExpressApplication>(undefined, {
51-
rawBody: true,
52-
});
53-
```
54-
55-
In v9, you can skip the first argument (`undefined`):
56-
57-
```typescript
58-
app = moduleFixture.createNestApplication<NestExpressApplication>({
59-
rawBody: true,
60-
});
61-
```
62-
63-
#### Kafka message/event handlers
64-
65-
Previously, Kafka message and event handlers were receiving payloads as wrapped Kafka messages with `key`, `value`, `headers`, and a few other properties. In v9, those payloads are automatically unwrapped and your handlers will only receive the `value` attribute's value. To retrieve the original Kafka message, you can use the `KafkaContext` object (read more [here](/microservices/kafka#context)).
66-
67-
```typescript
68-
// Before
69-
@MessagePattern('hero.kill.dragon')
70-
killDragon(@Payload() message: KillDragonMessage, @Ctx() context: KafkaContext) {
71-
console.log(`Dragon ID: ${message.value.dragonId}`);
72-
}
73-
74-
// Now
75-
@MessagePattern('hero.kill.dragon')
76-
killDragon(@Payload() message: KillDragonMessage, @Ctx() context: KafkaContext) {
77-
console.log(`Dragon ID: ${message.dragonId}`);
78-
// Original message: "context.getMessage()"
79-
}
80-
```
81-
82-
#### Kafka retriable errors
83-
84-
In v9, we introduced the **[Retriable exceptions](/microservices/kafka#retriable-exceptions)** feature. Note: for event handlers (**event-based communication**) all unhandled exceptions become "retriable exceptions" by default, and so they will be auto-delivered.
85-
86-
#### Fastify
87-
88-
Fastify has been upgraded to v4. Also, all of the core Fastify plugins that were prefixed with `fastify-` are now renamed and published under the `@fastify` scope (for example, `fastify-cookie` becomes `@fastify/cookie`, `fastify-helmet` becomes `@fastify/helmet`, etc.). Read more [here](https://github.com/fastify/fastify/issues/3856).
89-
90-
#### `@nestjs/swagger` package
11+
#### Deprecations
9112

92-
There are a few minor breaking changes in the `@nestjs/swagger` package (`swagger-ui-express` and `fastify-swagger` packages are no longer required). See this [PR](https://github.com/nestjs/swagger/pull/1886) for more details.
13+
All deprecated methods & modules have been removed.
9314

94-
#### Deprecations
15+
### CLI Plugins and TypeScript >= 4.8
9516

96-
All deprecated methods & modules have been removed (e.g., the deprecated `listenAsync()` method).
17+
NestJS CLI Plugins (available for `@nestjs/swagger` and `@nestjs/graphql` packages) will now require TypeScript >= v4.8 and so older versions of TypeScript will no longer be supported. The reason for this change is that in [TypeScript v4.8 introduced several breaking changes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-8.html#decorators-are-placed-on-modifiers-on-typescripts-syntax-trees) in its Abstract Syntax Tree (AST) which we use to auto-generate OpenAPI and GraphQL schemas.
9718

98-
#### Node.js
19+
### Dropping support for Node.js v12
9920

100-
This release drops support for Node v10. We strongly recommend using the latest LTS version.
21+
As of NestJS 10, we no longer support Node.js v12, as [v12 went EOL](https://twitter.com/nodejs/status/1524081123579596800) on April 30, 2022. This means that NestJS 10 requires Node.js v16 or higher. This decision was made to allow us to finally set target to `ES2021` in our TypeScript configuration, instead of shipping polyfills as we did in the past.
10122

102-
#### CLI
23+
From now on, every official NestJS package will be compiled to `ES2021` by default, which should result in a smaller library size and sometimes even (slightly) better performance.
10324

104-
Due to stability issues, the command `update` was removed in the v9 of `@nestjs/cli`.
105-
You can use dedicated tools like [`ncu`](https://www.npmjs.com/package/npm-check-updates), `npm update`, [`yarn upgrade-interactive`](https://classic.yarnpkg.com/en/docs/cli/upgrade-interactive), etc., if you want to upgrade your dependencies.
25+
We also strongly recommend using the latest LTS version.

content/techniques/configuration.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,6 @@ To use Joi, we must install Joi package:
342342
$ npm install --save joi
343343
```
344344

345-
> warning **Notice** The latest version of `joi` requires you to be running Node v12 or later. For older versions of node, please install `v16.1.8`. This is mainly after the release of `v17.0.2` which causes errors during build time. For more information, please refer to [their 17.0.0 release notes](https://github.com/sideway/joi/issues/2262).
346-
347345
Now we can define a Joi validation schema and pass it via the `validationSchema` property of the `forRoot()` method's options object, as shown below:
348346

349347
```typescript

0 commit comments

Comments
 (0)