Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xen-HendryZheng committed Jul 17, 2023
1 parent 2c2897c commit e687fab
Show file tree
Hide file tree
Showing 12 changed files with 7,038 additions and 1,566 deletions.
2 changes: 2 additions & 0 deletions backend/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* eslint-disable */
import 'jest-extended';
27 changes: 27 additions & 0 deletions backend/jest-global-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint no-process-env: "off" */
/* eslint import/no-extraneous-dependencies: "off" */
/* eslint @typescript-eslint/no-var-requires: "off" */

// Why this file is .js and not .ts
// https://github.com/kulshekhar/ts-jest/issues/411

const dotenv = require('dotenv');
const path = require('path');

dotenv.config({ path: path.resolve(__dirname, '.env.test') });

module.exports = async () => {
const db = process.env.PGDATABASE;

if (db && db !== 'test') {
// eslint-disable-next-line
console.error(`
> jest-global-setup.js
Running test on a non 'test' db will wipe out your entire db!
PGDATABASE is specified as '${db}' and not 'test'. Aborting...
`);
throw new Error();
}
};
23 changes: 23 additions & 0 deletions backend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { resolve } = require('path'); // eslint-disable-line @typescript-eslint/no-var-requires

module.exports = {
transform: {
'^.+\\.ts$': 'ts-jest'
},
testMatch: ['**/tests/**/*.test.ts'],
moduleNameMapper: {
'^src/(.*)$': resolve(__dirname, './src/$1')
},
moduleFileExtensions: ['ts', 'js', 'json'],
moduleDirectories: ['node_modules'],
modulePathIgnorePatterns: ['directoryNameToIgnore'],
collectCoverage: false, // only collect coverage on full test suite run (see package.json script)
collectCoverageFrom: ['!src/**/index.ts', '!src/routes.ts', 'src/**/*.ts'],
coveragePathIgnorePatterns: ['/node_modules/', 'build/'],
coverageReporters: ['json', 'json-summary', 'lcov', 'text', 'text-summary', 'html'],
testEnvironment: 'node',
verbose: true,
setupFiles: ['./jest.setup.ts'],
setupFilesAfterEnv: ['jest-extended'],
globalSetup: './jest-global-setup.js'
};
3 changes: 3 additions & 0 deletions backend/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'reflect-metadata';

jest.setTimeout(3000);
Loading

0 comments on commit e687fab

Please sign in to comment.