-
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.
ch: Setup CI workflow for testing, coverage reporting, building and l…
…inting
- Loading branch information
Showing
9 changed files
with
100 additions
and
69 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
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,33 @@ | ||
name: knights-ecomm-be CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build-lint-test-coverage: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.x' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run ESLint and Prettier | ||
run: npm run lint | ||
|
||
- name: Build project | ||
run: npm run build --if-present | ||
|
||
- name: Run tests | ||
run: npm test | ||
|
||
- name: Upload coverage report to Coveralls | ||
uses: coverallsapp/[email protected] | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} |
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
export default { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
testMatch: ["**/**/*.test.ts"], | ||
verbose: true, | ||
forceExit: true, | ||
clearMocks: true, | ||
resetMocks: true, | ||
restoreMocks: true, | ||
collectCoverageFrom: [ | ||
"src/**/*.{ts,tsx}", // Include all JavaScript/JSX files in the src directory | ||
], | ||
coveragePathIgnorePatterns: [ | ||
"/node_modules/", // Exclude the node_modules directory | ||
"/__tests__/", // Exclude the tests directory | ||
], | ||
}; | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testMatch: ['**/**/*.test.ts'], | ||
verbose: true, | ||
forceExit: true, | ||
clearMocks: true, | ||
resetMocks: true, | ||
restoreMocks: true, | ||
collectCoverageFrom: [ | ||
'src/**/*.{ts,tsx}', // Include all JavaScript/JSX files in the src directory | ||
], | ||
coveragePathIgnorePatterns: [ | ||
'/node_modules/', // Exclude the node_modules directory | ||
'/__tests__/', // Exclude the tests directory | ||
], | ||
}; |
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,14 +1,12 @@ | ||
import request from 'supertest'; | ||
import {app, server} from '../index'; // update this with the path to your app file | ||
import { app, server } from '../index'; // update this with the path to your app file | ||
|
||
describe('GET /', () => { | ||
afterAll(done => { | ||
server.close(done); | ||
}); | ||
afterAll(done => { | ||
server.close(done); | ||
}); | ||
|
||
it('responds with "Knights Ecommerce API"', done => { | ||
request(app) | ||
.get('/') | ||
.expect(200, 'Knights Ecommerce API', done); | ||
request(app).get('/').expect(200, 'Knights Ecommerce API', done); | ||
}); | ||
}); |
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,5 +1,5 @@ | ||
// export all controllers | ||
function myFunction () { | ||
function myFunction (): void { | ||
console.log('Hello'); | ||
} | ||
myFunction(); |
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 |
---|---|---|
@@ -1,30 +1,25 @@ | ||
import { Request, Response } from 'express'; | ||
|
||
class CustomError extends Error { | ||
statusCode: number; | ||
status: string; | ||
statusCode: number; | ||
status: string; | ||
|
||
constructor (message: string, statusCode: number) { | ||
super(message); | ||
this.statusCode = statusCode; | ||
this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error'; | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
constructor (message: string, statusCode: number) { | ||
super(message); | ||
this.statusCode = statusCode; | ||
this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error'; | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
} | ||
|
||
const errorHandler = ( | ||
err: CustomError, | ||
req: Request, | ||
res: Response, | ||
|
||
) => { | ||
err.statusCode = err.statusCode || 500; | ||
err.status = err.status || 'error'; | ||
res.status(err.statusCode).json({ | ||
status: err.statusCode, | ||
message: err.message | ||
}); | ||
console.error(err.stack); | ||
const errorHandler = (err: CustomError, req: Request, res: Response) => { | ||
Check warning on line 15 in src/middlewares/errorHandler.ts GitHub Actions / build-lint-test-coverage
Check warning on line 15 in src/middlewares/errorHandler.ts GitHub Actions / build-lint-test-coverage
Check warning on line 15 in src/middlewares/errorHandler.ts GitHub Actions / build-lint-test-coverage
|
||
err.statusCode = err.statusCode || 500; | ||
err.status = err.status || 'error'; | ||
res.status(err.statusCode).json({ | ||
status: err.statusCode, | ||
message: err.message, | ||
}); | ||
console.error(err.stack); | ||
}; | ||
|
||
export { CustomError, errorHandler }; |
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