api: приложение NestJS и e2e-тесты

Каркас api: NestJS со сборкой через webpack, health-контроллер с версией
и статусом БД,
Dockerfile, тесты Vitest и e2e-тесты на Jest.
This commit is contained in:
arswarog committed 2026-10-27 10:43:43 +03:00
1 parent 94e5e09218
commit 94f9b06527
27 files changed
+791

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
{
"jsc": {
"target": "es2017",
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true
},
"keepClassNames": true,
"externalHelpers": true,
"loose": true
},
"module": {
"type": "es6"
},
"sourceMaps": true,
"exclude": []
}
+3
View File
@@ -0,0 +1,3 @@
import baseConfig from '../../eslint.config.mjs';
export default [...baseConfig];
+21
View File
@@ -0,0 +1,21 @@
import { readFileSync } from 'fs';
// Reading the SWC compilation config for the spec files
const swcJestConfig = JSON.parse(readFileSync(`${__dirname}/.spec.swcrc`, 'utf-8'));
// Disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves
swcJestConfig.swcrc = false;
export default {
displayName: 'api-e2e',
preset: '../../jest.preset.js',
globalSetup: '<rootDir>/src/support/global-setup.ts',
globalTeardown: '<rootDir>/src/support/global-teardown.ts',
setupFiles: ['<rootDir>/src/support/test-setup.ts'],
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['@swc/jest', swcJestConfig],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: 'test-output/jest/coverage',
};
+5
View File
@@ -0,0 +1,5 @@
{
"name": "@geo-platform/api-e2e",
"version": "0.0.1",
"private": true
}
+53
View File
@@ -0,0 +1,53 @@
{
"name": "api-e2e",
"implicitDependencies": [
"api"
],
"targets": {
"lint": {
"executor": "@nx/eslint:lint",
"options": {
"lintFilePatterns": [
"{projectRoot}/**/*.ts"
],
"eslintConfig": "{projectRoot}/eslint.config.mjs",
"fix": true
}
},
"lint-check": {
"executor": "@nx/eslint:lint",
"options": {
"lintFilePatterns": [
"{projectRoot}/**/*.ts"
],
"eslintConfig": "{projectRoot}/eslint.config.mjs"
}
},
"format": {
"executor": "nx:run-commands",
"options": {
"command": "prettier --write {projectRoot}"
}
},
"format-check": {
"executor": "nx:run-commands",
"options": {
"command": "prettier --check {projectRoot}"
}
},
"e2e": {
"executor": "@nx/jest:jest",
"outputs": [
"{projectRoot}/test-output/jest/coverage"
],
"options": {
"jestConfig": "apps/api-e2e/jest.config.cts",
"passWithNoTests": true
},
"dependsOn": [
"api:build",
"api:serve"
]
}
}
}
+11
View File
@@ -0,0 +1,11 @@
import axios from 'axios';
import { describe, it } from 'vitest';
describe.skip('GET /api', () => {
it('should return a message', async () => {
const res = await axios.get(`/api`);
expect(res.status).toBe(200);
expect(res.data).toEqual({ message: 'Hello API' });
});
});
+16
View File
@@ -0,0 +1,16 @@
import { waitForPortOpen } from '@nx/node/utils';
/* eslint-disable */
var __TEARDOWN_MESSAGE__: string;
module.exports = async function () {
// Start services that that the app needs to run (e.g. database, docker-compose, etc.).
console.log('\nSetting up...\n');
const host = process.env.HOST ?? 'localhost';
const port = process.env.PORT ? Number(process.env.PORT) : 5000;
await waitForPortOpen(port, { host });
// Hint: Use `globalThis` to pass variables to global teardown.
globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n';
};
@@ -0,0 +1,9 @@
import { killPort } from '@nx/node/utils';
module.exports = async function () {
// Put clean up logic here (e.g. stopping services, docker-compose, etc.).
// Hint: `globalThis` is shared between setup and teardown.
const port = process.env.PORT ? Number(process.env.PORT) : 5000;
await killPort(port);
console.log(globalThis.__TEARDOWN_MESSAGE__);
};
+8
View File
@@ -0,0 +1,8 @@
import axios from 'axios';
module.exports = async function () {
// Configure axios for tests to use.
const host = process.env.HOST ?? 'localhost';
const port = process.env.PORT ?? '5000';
axios.defaults.baseURL = `http://${host}:${port}`;
};
+14
View File
@@ -0,0 +1,14 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "out-tsc/@geo-platform/api-e2e",
"esModuleInterop": true,
"noUnusedLocals": false,
"noImplicitAny": false
},
"include": [
"jest.config.ts",
"src/**/*.ts"
],
"references": []
}