feat: Introduce backend test suite with ava
This commit is contained in:
5
packages/backend/ava.config.mjs
Normal file
5
packages/backend/ava.config.mjs
Normal file
@@ -0,0 +1,5 @@
|
||||
export default {
|
||||
require: ['ts-node/register', './src/config/app.ts'],
|
||||
files: ['**/*.test.ts'],
|
||||
extensions: ['ts'],
|
||||
};
|
@@ -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"
|
||||
}
|
||||
|
@@ -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;
|
||||
|
8
packages/backend/src/graphql/queries/get-user.test.ts
Normal file
8
packages/backend/src/graphql/queries/get-user.test.ts
Normal 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');
|
||||
});
|
@@ -1,7 +0,0 @@
|
||||
import test from 'ava';
|
||||
|
||||
const fn = () => 'foo';
|
||||
|
||||
test('fn() returns foo', (t) => {
|
||||
t.is(fn(), 'foo');
|
||||
});
|
11
packages/backend/test/setup/create-database.ts
Normal file
11
packages/backend/test/setup/create-database.ts
Normal 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);
|
||||
});
|
Reference in New Issue
Block a user