Skip to content

Commit

Permalink
Merge pull request #121 from AthennaIO/develop
Browse files Browse the repository at this point in the history
chore(exception): add details to hooks
  • Loading branch information
jlenon7 committed Jan 10, 2024
2 parents 483723f + 198a24e commit 2f82ccd
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 54 deletions.
58 changes: 26 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/test",
"version": "4.19.0",
"version": "4.20.0",
"description": "The Athenna test runner. Built on top of Japa.",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down Expand Up @@ -63,7 +63,7 @@
"sinon": "^15.1.0"
},
"devDependencies": {
"@athenna/common": "^4.23.0",
"@athenna/common": "^4.28.0",
"@athenna/tsconfig": "^4.12.0",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
Expand Down
10 changes: 6 additions & 4 deletions src/exceptions/AfterAllHookException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ export class AfterAllHookException extends Exception {

const hook = Color.green.bold('@AfterAll')
const classMethod = Color.yellow.bold(`${className}.${method}`)
const message = `${Color.gray.bold.bgYellow(' MESSAGE ')}\n\n${
error.message ? error.message : JSON.stringify(error, null, 2)
}`

error.message = `An exception has occurred while running the ${hook} hook in ${classMethod} method.\n\n${message}`
if (error.message) {
error.message = `An exception has occurred while running the ${hook} hook in ${classMethod} method:\n\n${error.message}`
} else {
error.message = `An exception has occurred while running the ${hook} hook in ${classMethod} method.`
}

super({
code: 'E_AFTER_ALL_HOOK',
details: error.details,
message: error.message,
help: error.help,
stack: error.stack
Expand Down
10 changes: 6 additions & 4 deletions src/exceptions/AfterEachHookException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ export class AfterEachHookException extends Exception {

const hook = Color.green.bold('@AfterEach')
const classMethod = Color.yellow.bold(`${className}.${method}`)
const message = `${Color.gray.bold.bgYellow(' MESSAGE ')}\n\n${
error.message ? error.message : JSON.stringify(error, null, 2)
}`

error.message = `An exception has occurred while running the ${hook} hook in ${classMethod} method.\n\n${message}`
if (error.message) {
error.message = `An exception has occurred while running the ${hook} hook in ${classMethod} method:\n\n${error.message}`
} else {
error.message = `An exception has occurred while running the ${hook} hook in ${classMethod} method.`
}

super({
code: 'E_AFTER_EACH_HOOK',
details: error.details,
message: error.message,
help: error.help,
stack: error.stack
Expand Down
10 changes: 6 additions & 4 deletions src/exceptions/BeforeAllHookException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ export class BeforeAllHookException extends Exception {

const hook = Color.green.bold('@BeforeAll')
const classMethod = Color.yellow.bold(`${className}.${method}`)
const message = `${Color.gray.bold.bgYellow(' MESSAGE ')}\n\n${
error.message ? error.message : JSON.stringify(error, null, 2)
}`

error.message = `An exception has occurred while running the ${hook} hook in ${classMethod} method.\n\n${message}`
if (error.message) {
error.message = `An exception has occurred while running the ${hook} hook in ${classMethod} method:\n\n${error.message}`
} else {
error.message = `An exception has occurred while running the ${hook} hook in ${classMethod} method.`
}

super({
code: 'E_BEFORE_ALL_HOOK',
details: error.details,
message: error.message,
help: error.help,
stack: error.stack
Expand Down
10 changes: 6 additions & 4 deletions src/exceptions/BeforeEachHookException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ export class BeforeEachHookException extends Exception {

const hook = Color.green.bold('@BeforeEach')
const classMethod = Color.yellow.bold(`${className}.${method}`)
const message = `${Color.gray.bold.bgYellow(' MESSAGE ')}\n\n${
error.message ? error.message : JSON.stringify(error, null, 2)
}`

error.message = `An exception has occurred while running the ${hook} hook in ${classMethod} method.\n\n${message}`
if (error.message) {
error.message = `An exception has occurred while running the ${hook} hook in ${classMethod} method:\n\n${error.message}`
} else {
error.message = `An exception has occurred while running the ${hook} hook in ${classMethod} method.`
}

super({
code: 'E_BEFORE_EACH_HOOK',
details: error.details,
message: error.message,
help: error.help,
stack: error.stack
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/Runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ export class Runner {
}

/**
* Set the `NODE_ENV` and `APP_ENV` environments.
* Set the `APP_ENV` and `NODE_ENV` environments.
*
* @example ```ts
* Runner.setNodeEnv()
* Runner.setNodeEnv('test')
* Runner.setAppEnv()
* Runner.setAppEnv('test')
* ```
*/
public static setNodeEnv(env = 'test'): typeof Runner {
public static setAppEnv(env = 'test'): typeof Runner {
process.env.APP_ENV = env
process.env.NODE_ENV = env

Expand Down

0 comments on commit 2f82ccd

Please sign in to comment.