Merge pull request #1310 from automatisch/test-setup

feat: Introduce jest for backend tests
This commit is contained in:
Ömer Faruk Aydın
2023-09-30 15:02:01 +02:00
committed by GitHub
5 changed files with 3050 additions and 2800 deletions

View File

@@ -1,5 +0,0 @@
export default {
require: ['ts-node/register', './src/config/app.ts'],
files: ['**/*.test.ts'],
extensions: ['ts'],
};

View File

@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};

View File

@@ -10,7 +10,7 @@
"build:watch": "nodemon --watch 'src/**/*.ts' --watch 'bin/**/*.ts' --exec yarn build --ext ts", "build:watch": "nodemon --watch 'src/**/*.ts' --watch 'bin/**/*.ts' --exec yarn build --ext ts",
"start": "node dist/src/server.js", "start": "node dist/src/server.js",
"pretest": "APP_ENV=test ts-node ./test/setup/prepare-test-env.ts", "pretest": "APP_ENV=test ts-node ./test/setup/prepare-test-env.ts",
"test": "APP_ENV=test ava", "test": "APP_ENV=test jest",
"lint": "eslint . --ignore-path ../../.eslintignore", "lint": "eslint . --ignore-path ../../.eslintignore",
"db:create": "ts-node ./bin/database/create.ts", "db:create": "ts-node ./bin/database/create.ts",
"db:seed:user": "ts-node ./bin/database/seed-user.ts", "db:seed:user": "ts-node ./bin/database/seed-user.ts",
@@ -121,6 +121,7 @@
"@types/crypto-js": "^4.0.2", "@types/crypto-js": "^4.0.2",
"@types/express": "^4.17.15", "@types/express": "^4.17.15",
"@types/http-errors": "^1.8.1", "@types/http-errors": "^1.8.1",
"@types/jest": "^29.5.5",
"@types/jsonwebtoken": "^8.5.8", "@types/jsonwebtoken": "^8.5.8",
"@types/lodash.get": "^4.4.6", "@types/lodash.get": "^4.4.6",
"@types/memory-cache": "^0.2.2", "@types/memory-cache": "^0.2.2",
@@ -132,9 +133,10 @@
"@types/pino": "^7.0.5", "@types/pino": "^7.0.5",
"@types/pluralize": "^0.0.30", "@types/pluralize": "^0.0.30",
"@types/showdown": "^2.0.1", "@types/showdown": "^2.0.1",
"ava": "^5.3.1", "jest": "^29.7.0",
"nodemon": "^2.0.13", "nodemon": "^2.0.13",
"sinon": "^11.1.2", "sinon": "^11.1.2",
"ts-jest": "^29.1.1",
"ts-node": "^10.2.1", "ts-node": "^10.2.1",
"ts-node-dev": "^1.1.8" "ts-node-dev": "^1.1.8"
}, },

View File

@@ -1,8 +1,3 @@
import test from 'ava'; test('adds 1 + 2 to equal 3', () => {
expect(1 + 2).toBe(3);
const fn = () => 'foo';
test('getUser graphQL query', (t) => {
// TODO: Write a test for getUser graphQL query
t.is(fn(), 'foo');
}); });

5825
yarn.lock

File diff suppressed because it is too large Load Diff