Skip to content

Commit 56f7f36

Browse files
author
Patrick Acioli
authored
Merge branch 'master' into fix-bull-config-names
2 parents f074b56 + 65b5bce commit 56f7f36

File tree

11 files changed

+411
-299
lines changed

11 files changed

+411
-299
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18.15.0
1+
18.16.0

content/cli/usages.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ $ nest build <name> [options]
107107

108108
##### Options
109109

110-
| Option | Description |
111-
| ----------------- | ------------------------------------------------------ |
112-
| `--path [path]` | Path to `tsconfig` file. <br/>Alias `-p` |
113-
| `--config [path]` | Path to `nest-cli` configuration file. <br/>Alias `-c` |
114-
| `--watch` | Run in watch mode (live-reload) <br/>Alias `-w` |
115-
| `--webpack` | Use webpack for compilation. |
116-
| `--webpackPath` | Path to webpack configuration. |
117-
| `--tsc` | Force use `tsc` for compilation. |
110+
| Option | Description |
111+
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
112+
| `--path [path]` | Path to `tsconfig` file. <br/>Alias `-p` |
113+
| `--config [path]` | Path to `nest-cli` configuration file. <br/>Alias `-c` |
114+
| `--watch` | Run in watch mode (live-reload). If you're using `tsc` for compilation, you can type `rs` to restart the application. <br/>Alias `-w` |
115+
| `--webpack` | Use webpack for compilation. |
116+
| `--webpackPath` | Path to webpack configuration. |
117+
| `--tsc` | Force use `tsc` for compilation. |
118118

119119
#### nest start
120120

content/cli/workspaces.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Nest has two modes for organizing code:
55
- **standard mode**: useful for building individual project-focused applications that have their own dependencies and settings, and don't need to optimize for sharing modules, or optimizing complex builds. This is the default mode.
66
- **monorepo mode**: this mode treats code artifacts as part of a lightweight **monorepo**, and may be more appropriate for teams of developers and/or multi-project environments. It automates parts of the build process to make it easy to create and compose modular components, promotes code re-use, makes integration testing easier, makes it easy to share project-wide artifacts like `eslint` rules and other configuration policies, and is easier to use than alternatives like github submodules. Monorepo mode employs the concept of a **workspace**, represented in the `nest-cli.json` file, to coordinate the relationship between the components of the monorepo.
77

8-
It's important to note that virtually all of Nest's features are independent of your code organization mode. The **only** affect of this choice is how your projects are composed and how build artifacts are generated. All other functionality, from the CLI to core modules to add-on modules work the same in either mode.
8+
It's important to note that virtually all of Nest's features are independent of your code organization mode. The **only** effect of this choice is how your projects are composed and how build artifacts are generated. All other functionality, from the CLI to core modules to add-on modules work the same in either mode.
99

1010
Also, you can easily switch from **standard mode** to **monorepo mode** at any time, so you can delay this decision until the benefits of one or the other approach become more clear.
1111

content/controllers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ Routes with static paths won't work when you need to accept **dynamic data** as
273273
```typescript
274274
@@filename()
275275
@Get(':id')
276-
findOne(@Param() params): string {
276+
findOne(@Param() params: any): string {
277277
console.log(params.id);
278278
return `This action returns a #${params.id} cat`;
279279
}

content/discover/who-uses.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@
277277
"https://evershop.io",
278278
"https://e-design.ca",
279279
"https://growthmill.com",
280-
"https://tarken.com.br"
280+
"https://tarken.com.br",
281+
"https://remato.com"
281282
]
282283
}

content/recipes/async-local-storage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class AppModule implements NestModule {
5555
const store = {
5656
userId: req.headers['x-user-id'],
5757
};
58-
// and and pass the "next" function as callback
58+
// and pass the "next" function as callback
5959
// to the "als.run" method together with the store.
6060
als.run(store, () => next());
6161
})
@@ -85,7 +85,7 @@ export class AppModule {
8585
const store = {
8686
userId: req.headers['x-user-id'],
8787
};
88-
// and and pass the "next" function as callback
88+
// and pass the "next" function as callback
8989
// to the "als.run" method together with the store.
9090
als.run(store, () => next());
9191
})

content/recipes/swc.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,99 @@ If your ORM does not provide a similar workaround, you can define the wrapper ty
9595
*/
9696
export type WrapperType<T> = T; // WrapperType === Relation
9797
```
98+
99+
### Vitest
100+
101+
[Vitest](https://vitest.dev/) is a fast and lightweight test runner designed to work with Vite. It provides a modern, fast, and easy-to-use testing solution that can be integrated with NestJS projects.
102+
103+
#### Installation
104+
105+
To get started, first install the required packages:
106+
107+
```bash
108+
$ npm i --save-dev vitest unplugin-swc @swc/core @vitest/coverage-c8
109+
```
110+
111+
#### Configuration
112+
113+
Create a `vitest.config.ts` file in the root directory of your application with the following content:
114+
115+
```ts
116+
import swc from 'unplugin-swc';
117+
import { defineConfig } from 'vitest/config';
118+
119+
export default defineConfig({
120+
test: {
121+
globals: true,
122+
root: './',
123+
},
124+
plugins: [swc.vite()], // This is required to build the test files with SWC
125+
});
126+
```
127+
128+
This configuration file sets up the Vitest environment, root directory, and SWC plugin. You should also create a separate configuration
129+
file for e2e tests, with an additional `include` field that specifies the test path regex:
130+
131+
```ts
132+
import swc from 'unplugin-swc';
133+
import { defineConfig } from 'vitest/config';
134+
135+
export default defineConfig({
136+
test: {
137+
include: ['**/*.e2e-spec.ts'],
138+
globals: true,
139+
root: './',
140+
},
141+
plugins: [swc.vite()],
142+
});
143+
```
144+
145+
Additionally, you can set the `alias` options to support TypeScript paths in your tests:
146+
147+
```ts
148+
import swc from 'unplugin-swc';
149+
import { defineConfig } from 'vitest/config';
150+
151+
export default defineConfig({
152+
test: {
153+
include: ['**/*.e2e-spec.ts'],
154+
globals: true,
155+
alias: {
156+
'@src': './src',
157+
'@test': './test',
158+
},
159+
root: './',
160+
},
161+
resolve: {
162+
alias: {
163+
'@src': './src',
164+
'@test': './test',
165+
},
166+
},
167+
plugins: [swc.vite()],
168+
});
169+
```
170+
171+
#### Update imports in E2E tests
172+
173+
Change any E2E test imports using `import * as request from 'supertest'` to `import request from 'supertest'`. This is necessary because Vitest, when bundled with Vite, expects a default import for supertest. Using a namespace import may cause issues in this specific setup.
174+
175+
Lastly, update the test scripts in your package.json file to the following:
176+
177+
```json
178+
{
179+
"scripts": {
180+
"test": "vitest run",
181+
"test:watch": "vitest",
182+
"test:cov": "vitest run --coverage",
183+
"test:debug": "vitest --inspect-brk --inspect --logHeapUsage --threads=false",
184+
"test:e2e": "vitest run --config ./vitest.config.e2e.ts"
185+
}
186+
}
187+
```
188+
189+
These scripts configure Vitest for running tests, watching for changes, generating code coverage reports, and debugging. The test:e2e script is specifically for running E2E tests with a custom configuration file.
190+
191+
With this setup, you can now enjoy the benefits of using Vitest in your NestJS project, including faster test execution and a more modern testing experience.
192+
193+
> info **Hint** You can check out a working example in this [repository](https://github.com/TrilonIO/nest-vitest)

content/security/helmet.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ import helmet from 'helmet';
2020
app.use(helmet());
2121
```
2222

23+
> warning **Warning** When using `helmet`, `@apollo/server` (4.x), and the [Apollo Sandbox](https://docs.nestjs.com/graphql/quick-start#apollo-sandbox), there may be a problem with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) on the Apollo Sandbox. To solve this issue configure the CSP as shown below:
24+
>
25+
> ```typescript
26+
> app.use(helmet({
27+
> crossOriginEmbedderPolicy: false,
28+
> contentSecurityPolicy: {
29+
> directives: {
30+
> imgSrc: [`'self'`, 'data:', 'apollo-server-landing-page.cdn.apollographql.com'],
31+
> scriptSrc: [`'self'`, `https: 'unsafe-inline'`],
32+
> manifestSrc: [`'self'`, 'apollo-server-landing-page.cdn.apollographql.com'],
33+
> frameSrc: [`'self'`, 'sandbox.embed.apollographql.com'],
34+
> },
35+
> },
36+
> }));
37+
2338
#### Use with Fastify
2439
2540
If you are using the `FastifyAdapter`, install the [@fastify/helmet](https://github.com/fastify/fastify-helmet) package:

content/techniques/queues.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ With this in place, you can now point to this configuration in the `registerQueu
9999

100100
```typescript
101101
BullModule.registerQueue({
102-
configKey: 'alternative-config'
103-
name: 'video',
102+
configKey: 'alternative-config',
103+
name: 'video'
104104
});
105105
```
106106

@@ -428,7 +428,7 @@ BullModule.forRootAsync({
428428
useFactory: async (configService: ConfigService) => ({
429429
redis: {
430430
host: configService.get('QUEUE_HOST'),
431-
port: +configService.get('QUEUE_PORT'),
431+
port: configService.get('QUEUE_PORT'),
432432
},
433433
}),
434434
inject: [ConfigService],

0 commit comments

Comments
 (0)