Skip to content

Commit 3c070d4

Browse files
authored
Merge pull request #76 from klerick/setup-e2e-test
ci: Setup e2e test
2 parents 73ce9d8 + a01fb8d commit 3c070d4

File tree

23 files changed

+476
-162
lines changed

23 files changed

+476
-162
lines changed

.e2e.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DB_LOGGING=0

.env

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
DB_HOST=localhost
2+
DB_LOGGING=1
3+
4+
DB_USERNAME="postgres"
5+
DB_PASSWORD="postgres"
6+
DB_NAME="json-api-db"
7+
DB_PORT=5432
8+
DB_TYPE=postgres
9+
10+
#DB_USERNAME="root"
11+
#DB_PASSWORD="password"
12+
#DB_NAME="example_new"
13+
#DB_PORT=3306
14+
#DB_TYPE=mysql

.github/actions/action.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ runs:
1313
with:
1414
path: |
1515
node_modules
16-
.nx
17-
.angular
1816
~/.cache/Cypress # needed for the Cypress binary
1917
key: ${{ runner.os }}-npm-dependencies-${{ hashFiles('package-lock.json') }}
2018
- name: Npm install
21-
if: steps.cache.outputs.cache-hit != 'true'
19+
if: steps.cache-dependencies-restore.outputs.cache-hit != 'true'
2220
run: npm ci
2321
shell: bash
2422
- name: Cache npm dependencies

.github/workflows/bump-version.yml

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,75 @@ jobs:
2323
run: |
2424
echo "GIST_SECRET=${{ secrets.GIST_SECRET }}" >> $GITHUB_ENV
2525
echo "GIST_ID=${{ secrets.GIST_ID }}" >> $GITHUB_ENV
26+
- name: Restore cached .nx
27+
id: cache-nx-restore
28+
uses: actions/cache/restore@v4
29+
with:
30+
path: |
31+
.nx
32+
key: ${{ runner.os }}-nx-master"
2633
- name: Test and build
2734
run: npx nx affected -t test build --parallel=3 --exclude='json-api-front,json-api-server,json-api-server-e2e,json-shared-type,database,@nestjs-json-api/source'
2835
- name: Upload test coverage badge
2936
run: npx nx affected -t upload-badge --parallel=3 --exclude='json-api-front,json-api-server,shared-utils,json-api-server-e2e,json-shared-type,database,@nestjs-json-api/source'
30-
- name: Cache npm dependencies
37+
- name: Save cached .nx
3138
id: cache-dependencies-save
3239
uses: actions/cache/save@v4
3340
with:
3441
path: |
3542
.nx
36-
.angular
37-
key: ${{ runner.os }}-npm-dependencies-${{ hashFiles('package-lock.json') }}
38-
# env:
39-
# GIST_SECRET: ${{ secrets.GIST_SECRET }}
40-
# GIST_ID: ${{ secrets.GIST_ID }}
41-
# - run: npm nx affected -t e2e-ci --parallel=1
42-
# - run: npm nx affected -t deploy --no-agents
43-
43+
key: ${{ steps.cache-nx-restore.outputs.cache-primary-key }}
44+
run-e2e-test:
45+
runs-on: ubuntu-latest
46+
name: Try run e2e test
47+
needs:
48+
- build-and-test
49+
services:
50+
# Label used to access the service container
51+
postgres:
52+
# Docker Hub image
53+
image: postgres
54+
# Provide the password for postgres
55+
env:
56+
POSTGRES_PASSWORD: postgres
57+
POSTGRES_DB: json-api-db
58+
# Set health checks to wait until postgres has started
59+
options: >-
60+
--health-cmd pg_isready
61+
--health-interval 10s
62+
--health-timeout 5s
63+
--health-retries 5
64+
ports:
65+
# Maps tcp port 5432 on service container to the host
66+
- 5432:5432
67+
steps:
68+
- uses: actions/checkout@v4
69+
with:
70+
fetch-depth: 0
71+
- name: Npm install
72+
uses: ./.github/actions
73+
- name: Restore cached .nx
74+
id: cache-nx-restore
75+
uses: actions/cache/restore@v4
76+
with:
77+
path: |
78+
.nx
79+
key: ${{ runner.os }}-nx-master"
80+
- run: git branch --track main origin/master
81+
- run: npm run typeorm migration:run
82+
- run: npm run seed:run
83+
- run: npx nx affected -t e2e --parallel=1
84+
- name: Save cached .nx
85+
id: cache-dependencies-save
86+
uses: actions/cache/save@v4
87+
with:
88+
path: |
89+
.nx
90+
key: ${{ steps.cache-nx-restore.outputs.cache-primary-key }}
4491
bump-version:
4592
name: "Bump version"
4693
needs:
47-
- build-and-test
94+
- run-e2e-test
4895
runs-on: ubuntu-latest
4996
permissions:
5097
contents: "write"

.github/workflows/ci.yml

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,81 @@ on:
88
- synchronize
99
jobs:
1010
run-test:
11+
name: Try build and run unit test
1112
runs-on: ubuntu-latest
1213
steps:
1314
- uses: actions/checkout@v4
1415
with:
1516
fetch-depth: 0
1617
- name: Npm install
1718
uses: ./.github/actions
18-
# This line is needed for nx affected to work when CI is running on a PR
19+
- name: Get branch names.
20+
id: branch-names
21+
uses: tj-actions/branch-names@v8
22+
- name: Restore cached .nx
23+
id: cache-nx-restore
24+
uses: actions/cache/restore@v4
25+
with:
26+
path: |
27+
.nx
28+
key: ${{ runner.os }}-nx-${{ steps.branch-names.outputs.current_branch }}"
1929
- run: git branch --track main origin/master
2030
- name: Test and build
2131
run: npx nx affected -t test build --parallel=3 --exclude='json-api-front,json-api-server,json-api-server-e2e,json-shared-type,database,@nestjs-json-api/source'
22-
- name: Cache npm dependencies
32+
- name: Save cached .nx
33+
id: cache-dependencies-save
34+
uses: actions/cache/save@v4
35+
with:
36+
path: |
37+
.nx
38+
key: ${{ steps.cache-nx-restore.outputs.cache-primary-key }}
39+
run-e2e-test:
40+
runs-on: ubuntu-latest
41+
name: Try run e2e test
42+
needs:
43+
- run-test
44+
services:
45+
# Label used to access the service container
46+
postgres:
47+
# Docker Hub image
48+
image: postgres
49+
# Provide the password for postgres
50+
env:
51+
POSTGRES_PASSWORD: postgres
52+
POSTGRES_DB: json-api-db
53+
# Set health checks to wait until postgres has started
54+
options: >-
55+
--health-cmd pg_isready
56+
--health-interval 10s
57+
--health-timeout 5s
58+
--health-retries 5
59+
ports:
60+
# Maps tcp port 5432 on service container to the host
61+
- 5432:5432
62+
steps:
63+
- uses: actions/checkout@v4
64+
with:
65+
fetch-depth: 0
66+
- name: Npm install
67+
uses: ./.github/actions
68+
- name: Get branch names.
69+
id: branch-names
70+
uses: tj-actions/branch-names@v8
71+
- name: Restore cached .nx
72+
id: cache-nx-restore
73+
uses: actions/cache/restore@v4
74+
with:
75+
path: |
76+
.nx
77+
key: ${{ runner.os }}-nx-${{ steps.branch-names.outputs.current_branch }}"
78+
- run: git branch --track main origin/master
79+
- run: npm run typeorm migration:run
80+
- run: npm run seed:run
81+
- run: npx nx affected -t e2e --parallel=1
82+
- name: Save cached .nx
2383
id: cache-dependencies-save
2484
uses: actions/cache/save@v4
2585
with:
2686
path: |
2787
.nx
28-
.angular
29-
key: ${{ runner.os }}-npm-dependencies-${{ hashFiles('package-lock.json') }}
30-
# - run: npm nx affected -t e2e-ci --parallel=1
31-
# - run: npm nx affected -t deploy --no-agents
88+
key: ${{ steps.cache-nx-restore.outputs.cache-primary-key }}

apps/json-api-server-e2e/jest.config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ export default {
66
globalTeardown: '<rootDir>/src/support/global-teardown.ts',
77
setupFiles: ['<rootDir>/src/support/test-setup.ts'],
88
testEnvironment: 'node',
9+
maxWorkers: 1,
910
transform: {
10-
'^.+\\.[tj]s$': ['ts-jest', {
11-
tsconfig: '<rootDir>/tsconfig.spec.json',
12-
}],
11+
'^.+\\.[tj]s$': [
12+
'ts-jest',
13+
{
14+
tsconfig: '<rootDir>/tsconfig.spec.json',
15+
},
16+
],
1317
},
1418
moduleFileExtensions: ['ts', 'js', 'html'],
1519
coverageDirectory: '../../coverage/json-api-server-e2e',

apps/json-api-server-e2e/src/json-api/json-api-sdk/atomic-sdk.spec.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import {
2-
adapterForAxios,
3-
FilterOperand,
4-
JsonApiJs,
5-
JsonSdkPromise,
6-
} from 'json-api-nestjs-sdk';
7-
import axios from 'axios';
1+
import { INestApplication } from '@nestjs/common';
2+
import { FilterOperand, JsonSdkPromise } from 'json-api-nestjs-sdk';
83
import { Addresses, CommentKind, Comments, Roles, Users } from 'database';
94
import { faker } from '@faker-js/faker';
105
import { getUser } from '../utils/data-utils';
6+
import { run, creatSdk } from '../utils/run-ppplication';
7+
8+
let app: INestApplication;
9+
10+
beforeAll(async () => {
11+
app = await run();
12+
});
13+
14+
afterAll(async () => {
15+
await app.close();
16+
});
1117

1218
describe('Atomic method:', () => {
1319
let jsonSdk: JsonSdkPromise;
@@ -16,18 +22,7 @@ describe('Atomic method:', () => {
1622
let commentsArray: Comments[];
1723
let usersId: number[];
1824
beforeEach(async () => {
19-
const axiosAdapter = adapterForAxios(axios);
20-
21-
jsonSdk = JsonApiJs(
22-
{
23-
adapter: axiosAdapter,
24-
apiHost: 'http://localhost:3000',
25-
apiPrefix: 'api',
26-
dateFields: ['createdAt', 'updatedAt'],
27-
operationUrl: 'operation',
28-
},
29-
true
30-
);
25+
jsonSdk = creatSdk();
3126

3227
const addressesPromise = Array.from(new Array(2)).map(() => {
3328
const address = new Addresses();

apps/json-api-server-e2e/src/json-api/json-api-sdk/check-common-decorator.spec.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
import {
2-
adapterForAxios,
3-
FilterOperand,
4-
JsonApiJs,
5-
JsonSdkPromise,
6-
} from 'json-api-nestjs-sdk';
7-
import axios, { AxiosError } from 'axios';
1+
import { INestApplication } from '@nestjs/common';
2+
import { FilterOperand, JsonSdkPromise } from 'json-api-nestjs-sdk';
3+
import { AxiosError } from 'axios';
84
import { Users } from 'database';
95

6+
import { run, creatSdk } from '../utils/run-ppplication';
7+
8+
let app: INestApplication;
9+
10+
beforeAll(async () => {
11+
app = await run();
12+
});
13+
14+
afterAll(async () => {
15+
await app.close();
16+
});
17+
1018
describe('Check common decorator', () => {
1119
let jsonSdk: JsonSdkPromise;
12-
const axiosAdapter = adapterForAxios(axios);
1320
beforeEach(async () => {
14-
jsonSdk = JsonApiJs(
15-
{
16-
adapter: axiosAdapter,
17-
apiHost: 'http://localhost:3000',
18-
apiPrefix: 'api',
19-
dateFields: ['createdAt', 'updatedAt'],
20-
operationUrl: 'operation',
21-
idIsNumber: false,
22-
},
23-
true
24-
);
21+
jsonSdk = creatSdk();
2522
});
2623

2724
afterEach(async () => {});

apps/json-api-server-e2e/src/json-api/json-api-sdk/check-othe-call.spec.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
import {
2-
adapterForAxios,
3-
FilterOperand,
4-
JsonApiJs,
5-
JsonSdkPromise,
6-
} from 'json-api-nestjs-sdk';
1+
import { INestApplication } from '@nestjs/common';
2+
import { FilterOperand, JsonSdkPromise } from 'json-api-nestjs-sdk';
73
import { BookList, Users } from 'database';
8-
import axios, { AxiosError } from 'axios';
4+
import { AxiosError } from 'axios';
95
import { faker } from '@faker-js/faker';
106
import { lastValueFrom } from 'rxjs';
7+
import { creatSdk, run, axiosAdapter } from '../utils/run-ppplication';
8+
9+
let app: INestApplication;
10+
11+
beforeAll(async () => {
12+
app = await run();
13+
});
14+
15+
afterAll(async () => {
16+
await app.close();
17+
});
1118

1219
describe('Other call type:', () => {
1320
let jsonSdk: JsonSdkPromise;
14-
const axiosAdapter = adapterForAxios(axios);
21+
1522
beforeEach(async () => {
16-
jsonSdk = JsonApiJs(
17-
{
18-
adapter: axiosAdapter,
19-
apiHost: 'http://localhost:3000',
20-
apiPrefix: 'api',
21-
dateFields: ['createdAt', 'updatedAt'],
22-
operationUrl: 'operation',
23-
idIsNumber: false,
24-
},
25-
true
26-
);
23+
jsonSdk = creatSdk({
24+
idIsNumber: false,
25+
});
2726
});
2827

2928
afterEach(async () => {});
@@ -52,7 +51,6 @@ describe('Other call type:', () => {
5251
jsonSdk.jsonApiUtilsService.convertResponseData(newBookSource);
5352

5453
expect(newBook.id).toBeDefined();
55-
5654
const bookResultSource = await lastValueFrom(
5755
axiosAdapter.get<BookList>(`${url}/${newBook.id}`)
5856
);

0 commit comments

Comments
 (0)