Skip to content

Commit 46963e4

Browse files
committed
docs: extend documentation around testing
1 parent f1dd55b commit 46963e4

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

test/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Tests
2+
3+
openapi-cop uses Mocha to define tests. Test files are `/test/*.test.ts` and are executed in alphabetical
4+
order.
5+
6+
* 📄 **01.unit.test.ts** -- test ability to read OpenAPI documents.
7+
* 📄 **01.integration.test.ts** -- tests validation of requests/responses with different configurations.
8+
9+
## Adding tests
10+
11+
In the most simple and common scenario, adding a test just means
12+
13+
1. adding one new OpenAPI file to the `/test/schemas/` directory, and
14+
2. adding additional test data to `/test/test-requests/` or `/test/test-responses/`.
15+
16+
In general, do not modify or delete existing tests, schemas or test requests/responses. Add new
17+
tests/schemas/requests/responses instead.
18+
19+
### Adding schemas
20+
21+
When adding a new test OpenAPI file to `schemas/` keep in mind the following:
22+
23+
* Equivalent v2 and v3 OpenAPI documents are provided.
24+
* A ['operationId'](https://spec.openapis.org/oas/v3.1.0#operation-object) is set for every operation. Otherwise, the
25+
mock server is not able to generate mock
26+
responses, nor is a validator created for the given operation.
27+
* Files that are referenced locally (with a JSON-schema reference '$ref') should be placed in the `/schemas/refs/`
28+
folder.
29+
30+
## Debugging tests
31+
32+
When debugging tests, it is helpful to use the script `dev-start-along-mock` to run openapi-cop along with a mock server
33+
that are both based on a given OpenAPI file, e.g.
34+
35+
````bash
36+
npm run dev-start-along-mock -- test/schemas/v3/3-parameters.yaml
37+
````
38+
39+
The mock server uses the "examples" from the OpenAPI document to produce responses.
40+
41+
If you wish to start openapi-cop and a mock server that is based on a different OpenAPI document, you can use
42+
the `dev-start` scripts:
43+
44+
````bash
45+
# From the base directory
46+
npm run dev-start -- some-openapi.yaml # runs on port 8889
47+
(cd mock-server && npm run dev-start -- another-openapi.yaml) # runs on port 9000
48+
````

test/schemas/README.md

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

0 commit comments

Comments
 (0)