Skip to content

Commit 3efa2af

Browse files
CyberT33NCyberT33N
CyberT33N
authored and
CyberT33N
committed
feat(CCS-001): fixed some tseslint errors
1 parent 607edef commit 3efa2af

15 files changed

+45
-60
lines changed

README.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ import { errorMiddleware, HttpClientError } from 'error-manager-helper'
1414

1515
const app = express()
1616

17-
// Sample route to trigger custom error HttpClientError with axios
18-
app.get('/httpclient-error', async() => {
17+
app.get('/httpclient-error', () => {
1918
try {
2019
await axios.get('https://anySample.website/notFound')
21-
} catch (err) {
22-
throw new HttpClientError('Test error', err as AxiosError)
20+
} catch (e) {
21+
throw new HttpClientError(errorMessage, e as AxiosError)
2322
}
2423
})
2524

@@ -35,7 +34,7 @@ console.log(`Server is running on port ${port}`)
3534

3635
Response:
3736
```javascript
38-
const res = await axios.get('http://localhost:3000/httpclient-error')
37+
const res = await axios.get('http://127.0.0.1:3000/httpclient-error')
3938
console.log(res.response.data)
4039

4140
{
@@ -249,7 +248,7 @@ _________________________________________
249248
- The example below demonstrates an integration test for an internal service that throws a `BaseError`.
250249
```typescript
251250
import axios, { AxiosError } from 'axios'
252-
import { it, expect, expectTypeOf, assert } from 'vitest'
251+
import { it, expect, assert } from 'vitest'
253252
import { type IBaseError, StatusCodes } from 'error-manager-helper'
254253

255254
it('should return 500 with BaseError details - error passed', async() => {
@@ -260,9 +259,7 @@ it('should return 500 with BaseError details - error passed', async() => {
260259
if (err instanceof AxiosError) {
261260
expect(err.status).to.equal(StatusCodes.INTERNAL_SERVER_ERROR)
262261

263-
const data: IBaseError = err.response?.data
264-
expectTypeOf(data).toEqualTypeOf<IBaseError>()
265-
262+
const data = err.response?.data as IBaseError
266263
expect(data.error).toEqual(`Error: ${errorMessageFromService}`)
267264
expect(data.message).toBe(errorMessage)
268265

@@ -279,12 +276,12 @@ it('should return 500 with BaseError details - error passed', async() => {
279276

280277
## Unit Test
281278
```typescript
282-
import { it, expect, expectTypeOf, assert } from 'vitest'
279+
import { it, expect, assert, describe } from 'vitest'
283280
import { BaseError, type IBaseError } from 'error-manager-helper'
284281

285282
describe('Any test block', () => {
286283
const errMsg = 'Test error'
287-
const errMsgOriginal 'Test error original'
284+
const errMsgOriginal = 'Test error original'
288285
const error = new Error(errMsgOriginal)
289286

290287
const fn = () => {
@@ -299,8 +296,6 @@ describe('Any test block', () => {
299296
if (err instanceof BaseError) {
300297
const typedErr: BaseError = err
301298

302-
expectTypeOf(typedErr).toEqualTypeOf<IBaseError>()
303-
304299
expect(typedErr.error).toEqual(error)
305300
expect(typedErr.message).toBe(errMsg)
306301

eslint.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ export default tseslint.config(
7676
// '@typescript-eslint/no-var-requires': 'off',
7777
// '@typescript-eslint/explicit-module-boundary-types': 'off',
7878
// '@typescript-eslint/no-empty-function ': 'off',
79+
80+
'@typescript-eslint/no-misused-promises': [
81+
'error',
82+
{
83+
'checksVoidReturn': false
84+
}
85+
]
7986
}
8087
}
8188
)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"dist"
1111
],
1212
"scripts": {
13-
"build": "npx eslint src && tsup",
13+
"build": "npx eslint src test && tsup",
1414
"test-only": "bash test-only.sh",
1515
"test": "vitest --typecheck --coverage --disable-console-intercept --watch=false",
1616
"test:watch": "vitest --typecheck --watch",

src/errors/ValidationError.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ export default class ValidationError extends CoreError implements IValidationErr
5050
* @type {StatusCodes.BAD_REQUEST}
5151
*/
5252
httpStatus: StatusCodes.BAD_REQUEST
53-
54-
53+
5554
/**
5655
* Creates a new instance of `ValidationError`
5756
*

test/integration/pretestAll.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ const { PORT, BASE_URL } = ServerDetails
5454
let server: Server
5555
/**
5656
* Sets up the server and defines routes to trigger different types of errors.
57-
* @returns {Promise<void>} A promise that resolves when the server is set up.
57+
* @returns {void} A promise that resolves when the server is set up.
5858
*/
59-
export async function setup(): Promise<void> {
59+
export function setup(): void {
6060
const app = express()
6161

6262
app.get('/found', (req, res) => {
@@ -94,7 +94,7 @@ export async function setup(): Promise<void> {
9494
throw new HttpClientError(errorMessage, e as AxiosError)
9595
}
9696
})
97-
97+
9898
// Sample route to trigger ResourceNotFoundError
9999
app.get('/resource-not-found', req => {
100100
if (req.query.error) {
@@ -119,6 +119,6 @@ export async function setup(): Promise<void> {
119119
/**
120120
* Closes the server.
121121
*/
122-
export async function teardown(): Promise<void> {
122+
export function teardown(): void {
123123
server.close()
124124
}

test/integration/src/errors/BaseError.rest.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
import axios, { AxiosError } from 'axios'
17-
import { describe, it, expect, expectTypeOf, assert } from 'vitest'
17+
import { describe, it, expect, assert } from 'vitest'
1818

1919
import type { IBaseError } from '@/src/errors/BaseError'
2020

@@ -34,9 +34,7 @@ describe('[INTEGRATION] - src/errors/BaseError', () => {
3434
if (err instanceof AxiosError) {
3535
expect(err.status).to.equal(StatusCodes.INTERNAL_SERVER_ERROR)
3636

37-
const data: IBaseError = err.response?.data
38-
expectTypeOf(data).toEqualTypeOf<IBaseError>()
39-
37+
const data = err.response?.data as IBaseError
4038
expect(data.message).to.equal(errorMessage)
4139
expect(data.environment).to.equal(process.env.npm_lifecycle_event)
4240
expect(data.name).to.equal(ErrorType.BASE)
@@ -60,9 +58,7 @@ describe('[INTEGRATION] - src/errors/BaseError', () => {
6058
if (err instanceof AxiosError) {
6159
expect(err.status).to.equal(StatusCodes.INTERNAL_SERVER_ERROR)
6260

63-
const data: IBaseError = err.response?.data
64-
expectTypeOf(data).toEqualTypeOf<IBaseError>()
65-
61+
const data = err.response?.data as IBaseError
6662
expect(data.message).to.equal(errorMessage)
6763
expect(data.environment).to.equal(process.env.npm_lifecycle_event)
6864
expect(data.name).to.equal(ErrorType.BASE)

test/integration/src/errors/HttpClientError.rest.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
import axios, { AxiosError } from 'axios'
17-
import { describe, it, expect, expectTypeOf, assert } from 'vitest'
17+
import { describe, it, expect, assert } from 'vitest'
1818

1919
import type { IHttpClientError } from '@/src/errors/HttpClientError'
2020

@@ -34,8 +34,7 @@ describe('[INTEGRATION] - src/errors/HttpClientError', () => {
3434
if (err instanceof AxiosError) {
3535
expect(err.status).to.equal(StatusCodes.NOT_FOUND)
3636

37-
const data: IHttpClientError = err.response?.data
38-
expectTypeOf(data).toEqualTypeOf<IHttpClientError>()
37+
const data = err.response?.data as IHttpClientError
3938

4039
expect(data.message).toBe(errorMessage)
4140
expect(data.environment).toBe(process.env.npm_lifecycle_event)

test/integration/src/errors/ResourceNotFoundError.rest.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
import axios, { AxiosError } from 'axios'
17-
import { describe, it, expect, expectTypeOf, assert } from 'vitest'
17+
import { describe, it, expect, assert } from 'vitest'
1818

1919
import type { IResourceNotFoundError } from '@/src/errors/ResourceNotFoundError'
2020

@@ -35,8 +35,7 @@ describe('[INTEGRATION] - src/errors/ResourceNotFoundError', () => {
3535
if (err instanceof AxiosError) {
3636
expect(err.status).to.equal(StatusCodes.NOT_FOUND)
3737

38-
const data: IResourceNotFoundError = err.response?.data
39-
expectTypeOf(data).toEqualTypeOf<IResourceNotFoundError>()
38+
const data = err.response?.data as IResourceNotFoundError
4039

4140
expect(data.message).to.equal(errorMessage)
4241
expect(data.environment).to.equal(process.env.npm_lifecycle_event)
@@ -64,8 +63,7 @@ describe('[INTEGRATION] - src/errors/ResourceNotFoundError', () => {
6463
if (err instanceof AxiosError) {
6564
expect(err.status).to.equal(StatusCodes.NOT_FOUND)
6665

67-
const data: IResourceNotFoundError = err.response?.data
68-
expectTypeOf(data).toEqualTypeOf<IResourceNotFoundError>()
66+
const data = err.response?.data as IResourceNotFoundError
6967

7068
expect(data.message).to.equal(errorMessage)
7169
expect(data.environment).to.equal(process.env.npm_lifecycle_event)

test/integration/src/errors/RuntimeError.rest.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
import axios, { AxiosError } from 'axios'
17-
import { describe, it, expect, expectTypeOf, assert } from 'vitest'
17+
import { describe, it, expect, assert } from 'vitest'
1818

1919
import type { IRuntimeError } from '@/src/errors/RuntimeError'
2020

@@ -34,8 +34,7 @@ describe('[INTEGRATION] - src/errors/RuntimeError', () => {
3434
if (err instanceof AxiosError) {
3535
expect(err.status).to.equal(StatusCodes.FORBIDDEN)
3636

37-
const data: IRuntimeError = err.response?.data
38-
expectTypeOf(data).toEqualTypeOf<IRuntimeError>()
37+
const data = err.response?.data as IRuntimeError
3938

4039
expect(data.message).to.equal(errorMessage)
4140
expect(data.environment).to.equal(process.env.npm_lifecycle_event)

test/integration/src/errors/ValidationError.rest.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
import axios, { AxiosError } from 'axios'
17-
import { describe, it, expect, expectTypeOf, assert } from 'vitest'
17+
import { describe, it, expect, assert } from 'vitest'
1818

1919
import type { IValidationError } from '@/src/errors/ValidationError'
2020

@@ -35,8 +35,7 @@ describe('[INTEGRATION] - src/errors/ValidationError', () => {
3535
if (err instanceof AxiosError) {
3636
expect(err.status).to.equal(StatusCodes.BAD_REQUEST)
3737

38-
const data: IValidationError = err.response?.data
39-
expectTypeOf(data).toEqualTypeOf<IValidationError>()
38+
const data = err.response?.data as IValidationError
4039

4140
expect(data.message).to.equal(errorMessage)
4241
expect(data.environment).to.equal(process.env.npm_lifecycle_event)
@@ -62,8 +61,7 @@ describe('[INTEGRATION] - src/errors/ValidationError', () => {
6261
if (err instanceof AxiosError) {
6362
expect(err.status).to.equal(StatusCodes.BAD_REQUEST)
6463

65-
const data: IValidationError = err.response?.data
66-
expectTypeOf(data).toEqualTypeOf<IValidationError>()
64+
const data = err.response?.data as IValidationError
6765

6866
expect(data.message).to.equal(errorMessage)
6967
expect(data.environment).to.equal(process.env.npm_lifecycle_event)

test/integration/src/middleware.rest.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
import axios, { AxiosError } from 'axios'
17-
import { describe, it, expect, assert, expectTypeOf } from 'vitest'
17+
import { describe, it, expect, assert } from 'vitest'
1818

1919
import type { IErrorResponseSanitized } from '@/src/middleware'
2020

@@ -35,8 +35,7 @@ describe('[INTEGRATION] - src/middleware.ts', () => {
3535
expect(err.message).to.equal('Request failed with status code 500')
3636
expect(err.status).to.equal(StatusCodes.INTERNAL_SERVER_ERROR)
3737

38-
const data: IErrorResponseSanitized = err.response?.data
39-
expectTypeOf(data).toEqualTypeOf<IErrorResponseSanitized>()
38+
const data = err.response?.data as IErrorResponseSanitized
4039

4140
expect(data.environment).to.equal(process.env.npm_lifecycle_event)
4241
expect(data.name).to.equal(ErrorType.DEFAULT)

test/unit/src/errors/HttpClientError.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('[UNIT TEST] - src/errors/HttpClientError.ts', () => {
9494
const PORT = 3871
9595
const url = `http://localhost:${PORT}/found`
9696

97-
beforeAll(async() => {
97+
beforeAll(() => {
9898
const app = express()
9999

100100
app.get('/found', () => {

test/unit/src/middleware.test-d.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,12 @@ describe('[TYPE TEST] - src/middleware.ts', () => {
3636
stack: SanitizedMessage.DEFAULT | ICoreError['stack']
3737
}
3838

39-
interface IErrorMiddleware_Test {
40-
(
41-
err: ICoreError,
42-
req: Request,
43-
res: Response,
44-
next: NextFunction
45-
): void
46-
}
39+
type IErrorMiddleware_Test = (
40+
err: ICoreError,
41+
req: Request,
42+
res: Response,
43+
next: NextFunction
44+
) => void
4745

4846
describe('[FUNCTION]', () => {
4947
it('should verify function type', () => {

test/unit/src/middleware.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from 'vitest'
2222

2323
import {
24-
ValidationError, type IValidationError,
24+
ValidationError,
2525
ErrorType
2626
} from '@/src/index'
2727

@@ -50,7 +50,7 @@ describe('[UNIT TEST] - src/middleware.ts', () => {
5050
const errMsgOriginal = 'Test error original'
5151
const errData = { data: 'test' }
5252
const error: Error = new Error(errMsgOriginal)
53-
const validationErr: IValidationError = new ValidationError(errMsg, errData, error)
53+
const validationErr = new ValidationError(errMsg, errData, error)
5454

5555
beforeEach(() => {
5656
jsonStub = sinon.stub()

vitest.config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ export default defineConfig({
2929
setupFiles: 'test/unit/pretestEach.ts',
3030
globalSetup: 'test/integration/pretestAll.ts',
3131
environment: 'node',
32-
typecheck: {
33-
include: ['**/*.{test,spec}.?(c|m)[jt]s?(x)']
34-
},
3532
coverage: {
3633
/**
3734
* Specifies the directories to include for coverage.

0 commit comments

Comments
 (0)