-
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.
With our plugin we make an instance of GlobalNotifierLib available for use anywhere in the app. Because we're adding a global variable we have to let labrc. It has checks to help stop global variables being inadvertently created.
- Loading branch information
1 parent
0e36451
commit 67aa036
Showing
4 changed files
with
54 additions
and
1 deletion.
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,17 @@ | ||
'use strict' | ||
|
||
/** | ||
* Plugin to add a globally available notifier for logging and sending exceptions to Errbit | ||
* @module GlobalNotifierPlugin | ||
*/ | ||
|
||
const GlobalNotifierLib = require('../lib/global-notifier.lib.js') | ||
|
||
const GlobalNotifierPlugin = { | ||
name: 'global-notifier', | ||
register: (server, _options) => { | ||
global.GlobalNotifier = new GlobalNotifierLib(server.logger, server.app.airbrake) | ||
} | ||
} | ||
|
||
module.exports = GlobalNotifierPlugin |
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,31 @@ | ||
'use strict' | ||
|
||
// Test framework dependencies | ||
const Lab = require('@hapi/lab') | ||
const Code = require('@hapi/code') | ||
|
||
const { describe, it, beforeEach } = exports.lab = Lab.script() | ||
const { expect } = Code | ||
|
||
// Test helpers | ||
const GlobalNotifierLib = require('../../app/lib/global-notifier.lib.js') | ||
|
||
// For running our service | ||
const { init } = require('../../app/server.js') | ||
|
||
describe('Global Notifier plugin', () => { | ||
beforeEach(async () => { | ||
// Create server before each test | ||
await init() | ||
}) | ||
|
||
describe('Global Notifier Plugin', () => { | ||
describe('when the server is initialised', () => { | ||
it('makes an instance of GlobalNotifierLib available globally', async () => { | ||
const result = global.GlobalNotifier | ||
|
||
expect(result).to.be.an.instanceOf(GlobalNotifierLib) | ||
}) | ||
}) | ||
}) | ||
}) |