Skip to content

Commit

Permalink
Fix the jest exit issue
Browse files Browse the repository at this point in the history
  • Loading branch information
anjula-sack committed Aug 5, 2023
1 parent c917f97 commit 16634c4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
preset: 'ts-jest',
testEnvironment: 'node'
testEnvironment: 'node',
modulePathIgnorePatterns: ['<rootDir>/dist/']
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"start": "nodemon --watch 'src/**/*.ts' --exec ts-node-dev --respawn src/server.ts",
"build": "tsc",
"test": "jest",
"test": "jest --forceExit",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"format": "prettier --write \"src/**/*.ts\""
Expand Down
1 change: 0 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const startServer = async (): Promise<Express> => {
try {
await dataSource.initialize()
console.log('DB connection is successful')

app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`)
})
Expand Down
10 changes: 7 additions & 3 deletions src/routes/profile/profile.route.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { startServer } from '../../app'
import { startServer } from '../../app'
import type { Express } from "express"
import supertest from 'supertest'
import { dataSource } from '../../configs/dbConfig';

describe('profile', () => {
let server: Express;
describe('Get profile route', () => {
let accessToken: string
const randomString = Math.random().toString(36).substr(2, 5);
const randomString = Math.random().toString(36);

beforeAll(async () => {
server = await startServer();
Expand All @@ -30,7 +31,6 @@ describe('profile', () => {
}, 5000)

it('should return a 401 without a valid access token', async () => {

await supertest(server).get('/api/me/profile').expect(401)
})

Expand All @@ -51,5 +51,9 @@ describe('profile', () => {
expect(response.body).toHaveProperty('type')
expect(response.body).toHaveProperty('uuid')
})

afterAll(async() => {
await dataSource.destroy()
})
})
})
12 changes: 10 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import startServer from "./app";

startServer().then(()=> {console.log("Server started!")
}).catch((err) => { console.log("Something went wrong!", err) })
async function start() : Promise<void>{
try {
await startServer();
console.log("Server started!");
} catch (err) {
console.error("Something went wrong!", err);
}
}

start().catch((err) => {console.error(err)});

0 comments on commit 16634c4

Please # to comment.