-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented script to test both rest api, express and fastify
- Loading branch information
1 parent
e1f8b32
commit 9d651d8
Showing
22 changed files
with
383 additions
and
1,262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Tests - example/express-graphql | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test: | ||
name: Testing Simba.js API | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out Git repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16.x | ||
|
||
- name: Install Node.js dependencies | ||
run: npm ci | ||
|
||
- name: Revert changes into the package-lock.json file | ||
run: git checkout -- package-lock.json | ||
|
||
- name: Run test | ||
run: npm run test:ci | ||
env: | ||
MONGO_URI: ${{ secrets.MONGO_URI }} | ||
NODE_ENV: ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { connect, connection } from 'mongoose' | ||
import { HttpLogger } from 'express-pino-logger' | ||
|
||
const ENVIRONMENTS_WITHOUT_RECONNECTION = ['ci', 'local'] | ||
const dbConnection = async ( | ||
logger: HttpLogger['logger'] | ||
): Promise<{ | ||
connect: () => Promise<typeof import('mongoose')> | ||
disconnect: () => Promise<void> | ||
}> => { | ||
const connectionConfig = { | ||
keepAlive: true, | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true | ||
} | ||
|
||
connection.on('connected', () => { | ||
logger.info('Mongo connection established.') | ||
}) | ||
connection.on('reconnected', () => { | ||
logger.info('Mongo connection reestablished') | ||
}) | ||
connection.on('disconnected', () => { | ||
if ( | ||
!ENVIRONMENTS_WITHOUT_RECONNECTION.includes( | ||
process.env.NODE_ENV as string | ||
) | ||
) { | ||
logger.info( | ||
'Mongo connection disconnected. Trying to reconnected to Mongo...' | ||
) | ||
setTimeout(() => { | ||
connect(process.env.MONGO_URI as string, { | ||
...connection, | ||
connectTimeoutMS: 3000, | ||
socketTimeoutMS: 3000 | ||
}) | ||
}, 3000) | ||
} | ||
}) | ||
connection.on('close', () => { | ||
logger.info('Mongo connection closed') | ||
}) | ||
connection.on('error', (e: Error) => { | ||
logger.info('Mongo connection error:') | ||
logger.error(e) | ||
}) | ||
|
||
return { | ||
connect: () => connect(process.env.MONGO_URI as string, connectionConfig), | ||
disconnect: () => connection.close() | ||
} | ||
} | ||
|
||
export { dbConnection } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './models' | ||
export * from './queries' | ||
export * from './connection' |
Oops, something went wrong.