feat: Introduce backend test suite with ava

This commit is contained in:
Faruk AYDIN
2023-09-14 11:56:08 +02:00
parent a9c7375534
commit 224965b91e
7 changed files with 398 additions and 183 deletions

View File

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

View File

@@ -9,7 +9,8 @@
"build": "tsc && yarn copy-statics",
"build:watch": "nodemon --watch 'src/**/*.ts' --watch 'bin/**/*.ts' --exec yarn build --ext ts",
"start": "node dist/src/server.js",
"test": "ava",
"pretest": "APP_ENV=test ts-node ./test/setup/create-database.ts",
"test": "APP_ENV=test ava",
"lint": "eslint . --ignore-path ../../.eslintignore",
"db:create": "ts-node ./bin/database/create.ts",
"db:seed:user": "ts-node ./bin/database/seed-user.ts",
@@ -131,23 +132,12 @@
"@types/pino": "^7.0.5",
"@types/pluralize": "^0.0.30",
"@types/showdown": "^2.0.1",
"ava": "^3.15.0",
"ava": "^5.3.1",
"nodemon": "^2.0.13",
"sinon": "^11.1.2",
"ts-node": "^10.2.1",
"ts-node-dev": "^1.1.8"
},
"ava": {
"files": [
"test/**/*"
],
"extensions": [
"ts"
],
"require": [
"ts-node/register"
]
},
"publishConfig": {
"access": "public"
}

View File

@@ -1,6 +1,12 @@
import { URL } from 'node:url';
import * as dotenv from 'dotenv';
dotenv.config();
import path from 'path';
if (process.env.APP_ENV === 'test') {
dotenv.config({ path: path.resolve(__dirname, '../../.env.test') });
} else {
dotenv.config();
}
type AppConfig = {
host: string;

View File

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

View File

@@ -1,7 +0,0 @@
import test from 'ava';
const fn = () => 'foo';
test('fn() returns foo', (t) => {
t.is(fn(), 'foo');
});

View File

@@ -0,0 +1,11 @@
import { createDatabaseAndUser } from '../../bin/database/utils';
import logger from '../../src/helpers/logger';
createDatabaseAndUser()
.then(() => {
process.exit(0);
})
.catch((error) => {
logger.error(error);
process.exit(1);
});