-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: create named exceptions and write provider tests
- Loading branch information
1 parent
b38a34b
commit 3fb63ab
Showing
8 changed files
with
174 additions
and
20 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,11 @@ | ||
{ | ||
"E_INVALID_LOGGER_CONFIG": { | ||
"message": "Missing required properties in logger config", | ||
"status": 500, | ||
"code": "E_INVALID_LOGGER_CONFIG", | ||
"help": [ | ||
"The logger config must have \"name\", \"level\" and \"enabled\" properties.", | ||
"Double check the \"config/app\" file to ensure the config is correct." | ||
] | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,20 @@ | ||
/* | ||
* @adonisjs/logger | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { Exception } from '@poppinss/utils' | ||
import exceptions from '../../exceptions.json' | ||
|
||
export class InvalidConfigException extends Exception { | ||
public static invoke(): InvalidConfigException { | ||
const exception = exceptions.E_INVALID_LOGGER_CONFIG | ||
const error = new this(exception.message, exception.status, exception.code) | ||
error.help = exception.help.join('\n') | ||
return error | ||
} | ||
} |
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,51 @@ | ||
/* | ||
* @adonisjs/events | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import test from 'japa' | ||
import { join } from 'path' | ||
import { Registrar, Ioc } from '@adonisjs/fold' | ||
import { Config } from '@adonisjs/config/build/standalone' | ||
|
||
import { Logger } from '../src/Logger' | ||
|
||
test.group('Logger Provider', () => { | ||
test('register event provider', async (assert) => { | ||
const ioc = new Ioc() | ||
ioc.bind('Adonis/Core/Config', () => { | ||
return new Config({ | ||
app: { | ||
logger: { | ||
name: 'adonis', | ||
level: 30, | ||
enabled: true, | ||
}, | ||
}, | ||
}) | ||
}) | ||
|
||
const registrar = new Registrar(ioc, join(__dirname, '..')) | ||
await registrar.useProviders(['./providers/LoggerProvider']).registerAndBoot() | ||
|
||
assert.instanceOf(ioc.use('Adonis/Core/Logger'), Logger) | ||
assert.deepEqual(ioc.use('Adonis/Core/Logger'), ioc.use('Adonis/Core/Logger')) | ||
}) | ||
|
||
test('raise exception when config is invalid', async (assert) => { | ||
const ioc = new Ioc() | ||
ioc.bind('Adonis/Core/Config', () => { | ||
return new Config({}) | ||
}) | ||
|
||
const registrar = new Registrar(ioc, join(__dirname, '..')) | ||
await registrar.useProviders(['./providers/LoggerProvider']).registerAndBoot() | ||
|
||
const fn = () => ioc.use('Adonis/Core/Logger') | ||
assert.throw(fn, 'E_INVALID_LOGGER_CONFIG: Missing required properties in logger config') | ||
}) | ||
}) |
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,3 +1,6 @@ | ||
{ | ||
"extends": "./node_modules/@adonisjs/mrm-preset/_tsconfig" | ||
"extends": "./node_modules/@adonisjs/mrm-preset/_tsconfig", | ||
"compilerOptions": { | ||
"resolveJsonModule": true | ||
} | ||
} |