Skip to content

Commit fb060c6

Browse files
committed
refactor: migrate jest to vitest (#1998)
1 parent 2e92830 commit fb060c6

File tree

357 files changed

+6638
-9695
lines changed

Some content is hidden

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

357 files changed

+6638
-9695
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,7 @@ jobs:
5656
with:
5757
node-version: 20
5858
cache: 'npm'
59-
- name: Coverage Report
60-
uses: artiomtr/[email protected]
61-
continue-on-error: true
62-
with:
63-
skip-step: none
64-
annotations: none
65-
test-script: npm run jest
59+
# FIXME: add vitest coverage report
6660

6761
code-style-check:
6862
runs-on: ubuntu-latest

.husky/pre-commit

100644100755
File mode changed.

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ packages/core/src/rules/__tests__/fixtures/invalid-yaml.yaml
66
packages/respect-core/src/modules/runtime-expressions/abnf-parser.js
77
benchmark/api-definitions/
88
LICENSE.md
9+
__tests__/**/*snapshot*.js

CONTRIBUTING.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Before submitting a pull request, please make sure the following is done:
3737

3838
## Development setup
3939

40-
[Node.js](http://nodejs.org) at v18.17.0+ and NPM v10.8.2+ are required.
40+
[Node.js](http://nodejs.org) at v22.13.0+ and NPM v10.9.2+ are required.
4141

4242
After forking the repo, run:
4343

@@ -47,7 +47,7 @@ npm install # or npm i
4747

4848
### Commonly used NPM scripts
4949

50-
To compile the code, run `npm run compile`. To do that on the fly, run `npm run watch` in a separate thread.
50+
To compile the code, run `npm run compile`.
5151

5252
To run a specific CLI command, use `npm run cli`, e.g. `npm run cli -- lint resources/museum.yaml --format=stylish`.
5353
Please notice that the extra `--` is required to pass arguments to the CLI rather than to NPM itself.
@@ -170,18 +170,18 @@ The application maintains the following exit codes.
170170

171171
## Tests
172172

173-
When running tests, make sure the code is compiled (`npm run compile` or `npm run watch`).
173+
When running tests, make sure the code is compiled (`npm run compile`).
174174
Having `redocly.yaml` in the root of the project affects the unit tests, and console logs affect the e2e tests, so make sure to get rid of both before running tests.
175+
Run `npm test` to start both unit and e2e tests (and additionally typecheck the code).
175176

176177
### Unit tests
177178

178179
Run unit tests with this command: `npm run unit`.
179180

180181
Unit tests in the **cli** package are sensitive to top-level configuration file (**redocly.yaml**).
181182

183+
To run tests from a single file, run: `npm run unit -- <path/to/your/file.test.ts>`
182184
To run a specific test, use this command: `npm run unit -- -t 'Test name'`.
183-
To run tests in watch mode, run: `npm run unit:watch`
184-
To run single file in watch mode, run: `npm run unit:watch -- <path/to/your/file.test.ts>`
185185
To update snapshots, run `npm run unit -- -u`.
186186

187187
To get coverage per package run `npm run coverage:cli` or `npm run coverage:core`.
@@ -196,6 +196,16 @@ To update snapshots, run `npm run e2e -- -u`.
196196

197197
If you made any changes, make sure to compile the code before running the tests.
198198

199+
The e2e tests are written and run with [Vitest](https://vitest.dev/).
200+
Most of them are encapsulated inside the `commands.test.ts` file.
201+
However, when adding new e2e tests, it's best to follow the approach of the `respect` command tests.
202+
203+
### Smoke tests
204+
205+
Smokes are for testing the CLI in different environments.
206+
207+
To run them locally, please follow the steps described in the smoke GitHub actions: [smoke](.github/workflows/smoke.yaml), [smoke-plugins](.github/workflows/smoke-plugins.yaml), [smoke-rebilly](.github/workflows/smoke-rebilly.yaml).
208+
199209
### Performance benchmark
200210

201211
To run the performance benchmark locally, you should have `hyperfine` (v1.16.1+) installed on your machine.
@@ -209,19 +219,18 @@ You might need to adjust the CLI versions that need to be tested in the `benchma
209219

210220
## Project structure
211221

212-
- **`__mocks__`**: contains basic mocks for e2e tests.
222+
- **`__tests__`**: contains e2e and smoke tests.
213223

214-
- **`__tests__`**: contains e2e tests. The e2e tests are written and run with [Jest](https://jestjs.io/).
224+
- **`benchmark`**: contains the performance benchmark. <!-- TODO: move it under the __tests__ folder -->
215225

216226
- **`docs`**: contains the documentation source files. When changes to the documentation are merged, they automatically get published on the [Redocly docs website](https://redocly.com/docs/cli/).
217227

218-
- **`packages`**: contains the source code. Сonsists of two packages - CLI and core. The codebase is written in Typescript.
228+
- **`packages`**: contains the source code. It consists of three packages - CLI, core, and respect-core. The codebase is written in Typescript.
219229

220230
- **`packages/cli`**: contains Redocly CLI commands and utils. More details [here](../packages/cli/README.md).
221231

222232
- **`packages/cli/src`**: contains CLI package source code.
223233

224-
- **`packages/cli/src/__mocks__`**: contains basic mocks for unit tests.
225234
- **`packages/cli/src/__tests__`**: contains unit tests.
226235
- **`packages/cli/src/commands`**: contains CLI commands functions.
227236

@@ -231,12 +240,10 @@ You might need to adjust the CLI versions that need to be tested in the `benchma
231240
- **`packages/cli/core`**: contains core package source code.
232241

233242
- **`packages/core/src/__tests__`**: contains unit tests.
234-
- **`packages/core/src/benchmark`**: contains basic perf benchmark. Not fully ready yet.
235243
- **`packages/core/src/config`**: contains the base configuration options.
236244
- **`packages/core/src/decorators`**: contains the built-in [decorators](../docs/resources/built-in-decorators.md) code.
237245
- **`packages/core/src/format`**: contains the format options.
238246
- **`packages/core/src/js-yaml`**: contains the [JS-YAML](https://www.npmjs.com/package/js-yaml) based functions.
239-
<!-- - **`packages/core/src/redocly`**: contains the Redocly API registry integration setup. FIXME: update the structure description -->
240247
- **`packages/core/src/rules`**: contains the built-in [rules](../docs/resources/built-in-rules.md) code.
241248
- **`packages/core/src/types`**: contains the common types for several OpenAPI versions.
242249
- **`packages/core/src/typings`**: contains the common Typescript typings.
@@ -266,7 +273,7 @@ Merge the PR and cut a release according to the [Release flow](#release-flow).
266273
To release an experimental version to the **NPM** registry, follow these steps:
267274

268275
1. Create a new PR to **main**.
269-
2. Add the `snapshot` label to the PR. This creates a new PR with to the `snapshot` branch (which is a copy of the `main` branch).
270-
3. Merging the second PR triggers release to the **NPM** registry under the `snapshot` tag.
276+
2. Add the `snapshot` label to the PR.
277+
This triggers a release of the current branch changes to the **NPM** registry under the `snapshot` tag.
271278

272279
The released version can be installed with `npm install @redocly/cli@snapshot`.
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
2-
3-
exports[`E2E build-docs build docs with config option 1`] = `
41
Found nested/redocly.yaml and using theme.openapi options
52
Prerendering docs
63

74
🎉 bundled successfully in: nested/redoc-static.html (36 KiB) [ <test>ms].
85

9-
10-
`;
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
2-
3-
exports[`E2E build-docs simple build-docs 1`] = `
41
Found undefined and using theme.openapi options
52
Prerendering docs
63

74
🎉 bundled successfully in: redoc-static.html (330 KiB) [ <test>ms].
85

9-
10-
`;

__tests__/bundle/async3/snapshot.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
2-
3-
exports[`E2E bundle async3 1`] = `
41
info:
52
title: Account Service
63
version: 1.0.0
@@ -56,5 +53,3 @@ operations:
5653

5754
bundling simple.yml...
5855
📦 Created a bundle for simple.yml at stdout <test>ms.
59-
60-
`;

__tests__/bundle/bundle-anchor/snapshot.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
2-
3-
exports[`E2E bundle bundle-anchor 1`] = `
41
openapi: 3.1.0
52
paths:
63
/test-api:
@@ -30,5 +27,3 @@ components: {}
3027

3128
bundling test.yaml...
3229
📦 Created a bundle for test.yaml at stdout <test>ms.
33-
34-
`;

__tests__/bundle/bundle-arazzo-valid-test-description/snapshot.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
2-
3-
exports[`E2E bundle bundle-arazzo-valid-test-description 1`] = `
41
info:
52
title: Redocly Museum API Tickets
63
description: A part of imaginary, but delightful Museum API for interacting with museum services and information. Built with love by Redocly.
@@ -36,5 +33,3 @@ workflows:
3633

3734
bundling museum.yaml...
3835
📦 Created a bundle for museum.yaml at stdout <test>ms.
39-
40-
`;
Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
2-
3-
exports[`E2E bundle bundle-description-dereferenced 1`] = `
41
openapi: 3.1.0
52
security: []
63
paths:
@@ -38,47 +35,3 @@ components:
3835

3936
bundling test.yaml...
4037
📦 Created a bundle for test.yaml at stdout <test>ms.
41-
42-
`;
43-
44-
exports[`E2E bundle with option: dereferenced description should not be from $ref 1`] = `
45-
openapi: 3.1.0
46-
security: []
47-
paths:
48-
/users:
49-
post:
50-
summary: user
51-
description: User.
52-
operationId: createUser
53-
responses:
54-
'200':
55-
description: OK
56-
requestBody:
57-
description: Updated user object
58-
content:
59-
application/json:
60-
schema:
61-
description: Names (specific)
62-
type: object
63-
properties: &ref_0
64-
oneName:
65-
description: One name (specific).
66-
type: string
67-
otherName:
68-
description: Other name (specific).
69-
type: string
70-
required: true
71-
components:
72-
schemas:
73-
Name:
74-
type: string
75-
description: Generic Name.
76-
Names:
77-
type: object
78-
description: names description
79-
properties: *ref_0
80-
81-
bundling test.yaml...
82-
📦 Created a bundle for test.yaml at stdout <test>ms.
83-
84-
`;

0 commit comments

Comments
 (0)