Skip to content

Commit 9209a3f

Browse files
authored
feat: add e2e test suite (#235)
Until now, whilst some of the unit tests execute specific pieces of generated code using the `node:vm` module, and the integration tests check that typescript is happy to build the code, we haven't had very comprehensive end-to-end tests in the repo. This has meant manually checking changes in other (mostly private) projects, which is a bit of a pain and not very transparent. This PR aims to add end to end tests that actually run a koa service, and make calls to it using a generated client. Coverage will be relatively low to begin with and iteratively improved on over time. It will hopefully also serve as a decent sample of what a service using this project might look like.
1 parent 3ace597 commit 9209a3f

File tree

21 files changed

+507
-3
lines changed

21 files changed

+507
-3
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
packages/openapi-code-generater/src/core/schemas/openapi-3.0-specification-validator.js binary
44
packages/openapi-code-generater/src/core/schemas/openapi-3.1-specification-validator.js binary
55
integration-tests/*/src/generated/** linguist-generated=true
6+
e2e/src/generated/** linguist-generated=true
67
integration-tests-definitions/** linguist-vendored=true
78
yarn.lock linguist-generated=true

.github/workflows/ci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
strategy:
1919
matrix:
20-
node-version: [20.x]
20+
node-version: [20.x, 22.x]
2121
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2222

2323
steps:
@@ -51,6 +51,11 @@ jobs:
5151
- run: yarn integration:generate
5252
- run: yarn integration:validate
5353

54+
- run: yarn workspace e2e clean
55+
- run: yarn workspace e2e generate
56+
- run: yarn workspace e2e build
57+
- run: yarn workspace e2e test
58+
5459
- name: Check for uncommitted changes
5560
run: ./scripts/assert-clean-working-directory.sh
5661

biome.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"ignore": [
1313
"integration-tests/**/*",
1414
"integration-tests-definitions/**/*",
15+
"e2e/src/generated/**/*",
1516
"schemas/*.json",
1617
"packages/*/package.json",
1718
"package.json"
@@ -42,6 +43,7 @@
4243
"packages/openapi-code-generator/src/core/schemas/openapi-3.1-specification-validator.js",
4344
"integration-tests/**/*",
4445
"integration-tests-definitions/**/*",
46+
"e2e/src/generated/**/*",
4547
"schemas/*.json",
4648
"packages/*/package.json",
4749
"package.json"

e2e/jest.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const base = require("../jest.base")
2+
const {name: displayName} = require("./package.json")
3+
4+
/**
5+
* @type { import('@jest/types').Config.ProjectConfig }
6+
*/
7+
const config = {
8+
...base,
9+
displayName,
10+
}
11+
12+
module.exports = config

e2e/openapi.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
openapi: "3.0.0"
2+
info:
3+
title: E2E Tests for @nahkies/openapi-code-generator
4+
version: "0.0.1"
5+
tags:
6+
- name: validation
7+
paths:
8+
/validation/numbers/random-number:
9+
get:
10+
tags:
11+
- validation
12+
parameters:
13+
- name: max
14+
in: query
15+
schema:
16+
type: number
17+
minimum: 1
18+
default: 10
19+
- name: min
20+
in: query
21+
schema:
22+
type: number
23+
minimum: 0
24+
default: 0
25+
- name: forbidden
26+
in: query
27+
schema:
28+
type: array
29+
items:
30+
type: number
31+
format: int
32+
responses:
33+
200:
34+
description: success
35+
content:
36+
application/json:
37+
schema:
38+
$ref: '#/components/schemas/RandomNumber'
39+
40+
components:
41+
schemas:
42+
RandomNumber:
43+
type: object
44+
properties:
45+
result:
46+
type: number
47+
params:
48+
type: object
49+
properties:
50+
min:
51+
type: number
52+
max:
53+
type: number
54+
forbidden:
55+
type: array
56+
items:
57+
type: number

e2e/package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "e2e",
3+
"version": "0.0.1",
4+
"main": "./dist/index.js",
5+
"author": "Michael Nahkies",
6+
"license": "MIT",
7+
"private": true,
8+
"scripts": {
9+
"clean": "rm -rf ./dist && rm -rf ./src/generated",
10+
"generate": "./scripts/generate.sh",
11+
"build": "tsc -p ./tsconfig.json",
12+
"test": "jest",
13+
"start": "node ./dist/index.js"
14+
},
15+
"dependencies": {
16+
"@koa/router": "^12.0.1",
17+
"@nahkies/typescript-koa-runtime": "*",
18+
"koa": "^2.15.3",
19+
"zod": "^3.23.8"
20+
},
21+
"devDependencies": {
22+
"@nahkies/openapi-code-generator": "*",
23+
"@types/koa": "^2.15.0",
24+
"@types/koa__router": "^12.0.4",
25+
"jest": "^30.0.0-alpha.6",
26+
"typescript": "~5.5.4"
27+
}
28+
}

e2e/scripts/generate.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
echo $PWD
4+
5+
yarn openapi-code-generator \
6+
--input ./openapi.yaml \
7+
--output ./src/generated \
8+
--template typescript-koa \
9+
--schema-builder zod \
10+
--extract-inline-schemas \
11+
--grouping-strategy first-tag
12+
13+
yarn openapi-code-generator \
14+
--input ./openapi.yaml \
15+
--output ./src/generated/client \
16+
--template typescript-fetch \
17+
--schema-builder zod \
18+
--extract-inline-schemas \
19+
--grouping-strategy first-tag \

e2e/src/generated/client/client.ts

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/src/generated/client/models.ts

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/src/generated/index.ts

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)