Skip to content

Commit

Permalink
feat: add e2e app and configure jest
Browse files Browse the repository at this point in the history
  • Loading branch information
temarusanov committed Jun 16, 2023
1 parent e4d1d3b commit 6531f8f
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 40 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Checkout documentation: https://temarusanov.github.io/nx/

## TODO:

- [ ] Jest coverage bug [#13576](https://github.com/jestjs/jest/issues/13576)

## Installing

### Install Ansible
Expand Down
10 changes: 10 additions & 0 deletions apps/api-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
}
]
}
18 changes: 18 additions & 0 deletions apps/api-e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable */
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$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
},
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
}
22 changes: 22 additions & 0 deletions apps/api-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "api-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"implicitDependencies": ["api"],
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{e2eProjectRoot}"],
"options": {
"jestConfig": "apps/api-e2e/jest.config.ts",
"passWithNoTests": true
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/api-e2e/**/*.{js,ts}"]
}
}
}
}
10 changes: 10 additions & 0 deletions apps/api-e2e/src/api/api.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import axios from 'axios'

describe('GET /health', () => {
it('should be healthy', async () => {
const res = await axios.get(`/health`)

expect(res.status).toBe(200)
expect(res.data.healthy).toEqual(true)
})
})
8 changes: 8 additions & 0 deletions apps/api-e2e/src/support/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* 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.).
// Hint: Use `globalThis` to pass variables to global teardown.
// globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n'
}
7 changes: 7 additions & 0 deletions apps/api-e2e/src/support/global-teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable */

module.exports = async function () {
// Put clean up logic here (e.g. stopping services, docker-compose, etc.).
// Hint: `globalThis` is shared between setup and teardown.
//console.log(globalThis.__TEARDOWN_MESSAGE__)
}
10 changes: 10 additions & 0 deletions apps/api-e2e/src/support/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */

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 ?? '3000'
axios.defaults.baseURL = `http://${host}:${port}`
}
13 changes: 13 additions & 0 deletions apps/api-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"esModuleInterop": true
}
}
9 changes: 9 additions & 0 deletions apps/api-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "src/**/*.ts"]
}
1 change: 0 additions & 1 deletion apps/api/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ export default {
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/api',
}
6 changes: 6 additions & 0 deletions jest.preset.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const nxPreset = require('@nx/jest/preset').default;

const globalConf = {
collectCoverage: true,
coverageDirectory: `${process.env.NX_WORKSPACE_ROOT}/coverage/${process.env['NX_TASK_TARGET_PROJECT']}`,
};

module.exports = {
...nxPreset,
...globalConf,
};
71 changes: 32 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@nestjs/platform-express": "9.4.3",
"@nestjs/testing": "9.4.3",
"@prisma/client": "^4.15.0",
"axios": "^1.4.0",
"bcrypt": "^5.1.0",
"clsx": "^1.2.1",
"env-var": "^7.3.1",
Expand Down

0 comments on commit 6531f8f

Please sign in to comment.