diff --git a/.npmignore b/.npmignore
deleted file mode 100644
index b3d60fb..0000000
--- a/.npmignore
+++ /dev/null
@@ -1,3 +0,0 @@
-*
-!lib/**
-!.npmignore
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index d3d2573..baf8fe9 100755
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,16 +1,8 @@
-language: node_js
+version: ~> 1.0
-node_js:
- - "8"
- - "10"
- - "12"
- - "node"
-sudo: false
-
-install:
- - "npm install"
- - "npm install @hapi/hapi@$HAPI_VERSION"
-
-env:
- - HAPI_VERSION="18"
+import:
+ - hapijs/ci-config-travis:node_js.yml@main
+ - hapijs/ci-config-travis:install_plugin.yml@main
+ - hapijs/ci-config-travis:os.yml@main
+ - hapijs/ci-config-travis:env.yml@main
diff --git a/API.md b/API.md
index 72a4ea0..8fa2c19 100644
--- a/API.md
+++ b/API.md
@@ -1,11 +1,242 @@
+## Introduction
-## good
-
-**good** is a process monitor that listens for one or more of the below 'event types'. All of these events, _except_ 'ops' map to a hapi event documented [here](https://github.com/hapijs/hapi/blob/master/API.md#server-events).
+**good** is a hapi plugin process monitor that listens for one or more of the below 'event types'. All of these events, _except_ 'ops' map to a hapi event documented [here](https://github.com/hapijs/hapi/blob/master/API.md#server-events).
Applications with multiple server instances, each with its own monitor should only include one _log_ subscription per destination
as general events are a process-wide facility and will result in duplicated log events.
+Note: this module is being deprecated on December 1st, 2019 due to lack to available support resources. Please consider using [another logging plugin](https://hapi.dev/plugins/#logging).
+
+## Example Usage
+
+### Log to Console
+
+```js
+const Hapi = require('@hapi/hapi');
+
+
+const start = async function () {
+
+ const server = Hapi.server();
+
+ const handler = function (request, h) {
+
+ request.server.log(['a', 'b', 'c'], 'some message');
+ return 'ok';
+ };
+
+ server.route({ path: '/', method: 'GET', handler })
+
+ await server.register({
+ plugin: require('@hapi/good'),
+ options: {
+ ops: {
+ interval: 1000
+ },
+ reporters: {
+ myConsoleReporter: [
+ {
+ module: '@hapi/good-squeeze',
+ name: 'Squeeze',
+ args: [{ log: '*', response: '*', ops: '*' }]
+ },
+ {
+ module: '@hapi/good-console'
+ },
+ 'stdout'
+ ]
+ }
+ }
+ });
+
+ await server.start();
+ console.info(`Server started at ${server.info.uri}`);
+ await server.inject('/');
+};
+
+start();
+```
+
+This reporter spec logs ops statistics, request responses, and server log events to the console. It should log to the console something like:
+```
+Server started at http://localhost:41759
+190921/234014.495, [log,a,b,c] data: some message
+190921/234014.494, (1569109214494:localhost:3616:k0u742ki:10000) [response] http://localhost:41759: get / {} 200 (6ms)
+190921/234015.494, [ops] memory: 52Mb, uptime (seconds): 1.148846148, load: [0.02734375,0.0302734375,0]
+190921/234016.493, [ops] memory: 52Mb, uptime (seconds): 2.149207332, load: [0.02734375,0.0302734375,0]
+190921/234017.494, [ops] memory: 52Mb, uptime (seconds): 3.149818512, load: [0.02734375,0.0302734375,0]
+```
+
+It uses `@hapi/good-squeeze` to select only log and response events.
+
+Events that pass the filter stream to `@hapi/good-console` for formatting. See the `good console` [constructor docs](https://github.com/hapijs/good-console#new-goodconsoleconfig) for details on `args` values.
+
+Formatted events stream to `process.stdout` for display.
+
+### Log to file
+
+Create a basic write stream class and use with good:
+
+```js
+const Fs = require('fs-extra');
+const Hapi = require('@hapi/hapi');
+
+
+class GoodFile extends Fs.WriteStream {
+
+ constructor(path, options) {
+
+ const defaults = {
+ encoding: 'utf8',
+ flags: 'a',
+ mode: 0o666
+ };
+
+ const settings = Object.assign({}, defaults, options);
+ settings.fd = -1; // Prevent open from being called in `super`
+
+ super(path, settings);
+ this.open();
+ }
+
+ open() {
+
+ this.fd = null;
+ Fs.ensureFile(this.path, (err) => {
+
+ if (err) {
+ this.destroy();
+ this.emit('error', err);
+ return;
+ }
+
+ super.open();
+ });
+ }
+}
+
+
+const start = async function () {
+
+ const server = Hapi.server();
+
+ const handler = function (request, h) {
+
+ request.server.log(['a', 'b', 'c'], 'some message');
+ return 'ok';
+ };
+
+ server.route({ path: '/', method: 'GET', handler })
+
+ await server.register({
+ plugin: require('@hapi/good'),
+ options: {
+ ops: {
+ interval: 1000
+ },
+ reporters: {
+ myReporter: [
+ {
+ module: '@hapi/good-squeeze', // Transform payload into a safe string
+ name: 'SafeJson'
+ },
+ {
+ module: GoodFile,
+ args: ['./log.json']
+ }
+ ]
+ }
+ }
+ });
+
+ await server.start();
+ server.log(['log'], 'Server Started');
+ await server.inject('/');
+};
+
+start();
+```
+
+This will create or append a file `./log.json` with the following:
+```json
+{"event":"log","timestamp":1569109412144,"tags":["log"],"data":"Server Started","pid":3630}
+{"event":"log","timestamp":1569109412148,"tags":["a","b","c"],"data":"some message","pid":3630}
+{"event":"response","timestamp":1569109412146,"id":"1569109412146:localhost:3630:k0u78b2x:10000","instance":"http://localhost:44883","method":"get","path":"/","query":{},"responseTime":5,"statusCode":200,"pid":3630,"httpVersion":"1.1","route":"/","log":[],"source":{"remoteAddress":"127.0.0.1","userAgent":"shot"},"config":{}}
+{"event":"ops","timestamp":1569109413146,"host":"localhost","pid":3630,"os":{"load":[0.0029296875,0.02001953125,0],"mem":{"total":16682434560,"free":6650597376},"uptime":851831},"proc":{"uptime":1.160361771,"mem":{"rss":54652928,"heapTotal":18948096,"heapUsed":8310912,"external":1271839},"delay":0.9361389875411987},"load":{"requests":{"44883":{"total":1,"disconnects":0,"statusCodes":{"200":1}}},"responseTimes":{"44883":{"avg":5,"max":5}},"sockets":{"http":{"total":0},"https":{"total":0}}}}
+{"event":"ops","timestamp":1569109414145,"host":"localhost","pid":3630,"os":{"load":[0.0029296875,0.02001953125,0],"mem":{"total":16682434560,"free":6650597376},"uptime":851832},"proc":{"uptime":2.160405932,"mem":{"rss":54652928,"heapTotal":18948096,"heapUsed":8358032,"external":1271887},"delay":0.29865598678588867},"load":{"requests":{"44883":{"total":0,"disconnects":0,"statusCodes":{}}},"responseTimes":{"44883":{"avg":null,"max":0}},"sockets":{"http":{"total":0},"https":{"total":0}}}}
+```
+
+### Add custom transform stream
+
+```js
+const Stream = require('stream');
+const Hapi = require('@hapi/hapi');
+
+
+class LogDateTransform extends Stream.Transform {
+
+ constructor() {
+
+ super({ objectMode: true });
+ }
+
+ _transform(data, enc, next) {
+
+ const date = new Date(Date.now()).toLocaleString('en-US');
+
+ if (data.data) {
+ return next(null, `${data.event}: ${date}: ${data.data}\n`);
+ }
+
+ next(null);
+ }
+}
+
+
+const start = async function () {
+
+ const server = Hapi.server();
+
+ const handler = function (request, h) {
+
+ request.server.log(['a', 'b', 'c'], 'some message');
+ return 'ok';
+ };
+
+ server.route({ path: '/', method: 'GET', handler })
+
+ await server.register({
+ plugin: require('@hapi/good'),
+ options: {
+ ops: {
+ interval: 1000
+ },
+ reporters: {
+ myReporter: [
+ new LogDateTransform(),
+ 'stdout'
+ ]
+ }
+ }
+ });
+
+ await server.start();
+ server.log('info', 'Server is running...');
+ await server.inject('/');
+};
+
+start();
+```
+
+This reporter logs data with a date time, writing to the console something like:
+
+```
+log: 9 / 21 / 2019, 4: 47: 25 PM: Server is running...
+log: 9 / 21 / 2019, 4: 47: 25 PM: some message
+```
+
+## Usage
+
### Options
- `[includes]` - optional configuration object
- `[request]` - array of extra hapi request object fields to supply to reporters on "request", "response", and "error" events. Valid values ['headers', 'payload']. Defaults to `[]`.
@@ -243,3 +474,10 @@ Because the extension payloads from hapi can vary from one version to another an
- `event` - the event name.
- `timestamp` - the time the event occurred.
- `payload` - array of arguments hapi passed to our event handler function
+
+## Existing streams
+
+The following streams are maintained by the hapi community and are known to work with good. Any transform or write stream can work with good, these are just a few inside the hapijs organization.
+
+- [good-squeeze](https://github.com/hapijs/good-squeeze)
+- [good-console](https://github.com/hapijs/good-console)
diff --git a/CHANGELOG.md b/CHANGELOG.md
deleted file mode 100644
index 72bda07..0000000
--- a/CHANGELOG.md
+++ /dev/null
@@ -1,3 +0,0 @@
-Breaking changes are documented using GitHub issues, see [issues labeled "release notes"](https://github.com/hapijs/good/issues?q=is%3Aissue+label%3A%22release+notes%22).
-
-If you want changes of a specific minor or patch release, you can browse the [GitHub milestones](https://github.com/hapijs/good/milestones?state=closed&direction=asc&sort=due_date).
diff --git a/LICENSE.md b/LICENSE.md
index ce2e425..b135f04 100755
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,4 +1,4 @@
-Copyright (c) 2014-2019, Sideway Inc, and project contributors
+Copyright (c) 2014-2020, Sideway Inc, and project contributors
Copyright (c) 2012-2014, Walmart.
All rights reserved.
diff --git a/README.md b/README.md
index dd438f3..fe30fe6 100755
--- a/README.md
+++ b/README.md
@@ -1,250 +1,19 @@
-
+
# @hapi/good
-[**hapi**](https://github.com/hapijs/hapi) process monitoring
+#### hapi process monitoring.
-[![Build Status](https://secure.travis-ci.org/hapijs/good.svg?branch=master)](http://travis-ci.org/hapijs/good)
+**good** is part of the **hapi** ecosystem and was designed to work seamlessly with the [hapi web framework](https://hapi.dev) and its other components (but works great on its own or with other frameworks). If you are using a different web framework and find this module useful, check out [hapi](https://hapi.dev) – they work even better together.
-**good** is a hapi plugin to monitor and report on a variety of hapi server events as well as ops information from the host machine. It listens for events emitted by hapi server instances and pushes standardized events to a collection of streams.
+### Visit the [hapi.dev](https://hapi.dev) Developer Portal for tutorials, documentation, and support
-## Note: this module is being deprecated on December 1st, 2019 due to lack to available support resources. Please consider using [another logging plugin](https://hapi.dev/plugins/#logging).
+## Useful resources
-## Example Usage
+- [Documentation and API](https://hapi.dev/family/good/)
+- [Version status](https://hapi.dev/resources/status/#good) (builds, dependencies, node versions, licenses, eol)
+- [Changelog](https://hapi.dev/family/good/changelog/)
+- [Project policies](https://hapi.dev/policies/)
+- [Free and commercial support options](https://hapi.dev/support/)
-### Log to Console
-
-```js
-const Hapi = require('@hapi/hapi');
-
-
-const start = async function () {
-
- const server = Hapi.server();
-
- const handler = function (request, h) {
-
- request.server.log(['a', 'b', 'c'], 'some message');
- return 'ok';
- };
-
- server.route({ path: '/', method: 'GET', handler })
-
- await server.register({
- plugin: require('@hapi/good'),
- options: {
- ops: {
- interval: 1000
- },
- reporters: {
- myConsoleReporter: [
- {
- module: '@hapi/good-squeeze',
- name: 'Squeeze',
- args: [{ log: '*', response: '*', ops: '*' }]
- },
- {
- module: '@hapi/good-console'
- },
- 'stdout'
- ]
- }
- }
- });
-
- await server.start();
- console.info(`Server started at ${server.info.uri}`);
- await server.inject('/');
-};
-
-start();
-```
-
-This reporter spec logs ops statistics, request responses, and server log events to the console. It should log to the console something like:
-```
-Server started at http://localhost:41759
-190921/234014.495, [log,a,b,c] data: some message
-190921/234014.494, (1569109214494:localhost:3616:k0u742ki:10000) [response] http://localhost:41759: get / {} 200 (6ms)
-190921/234015.494, [ops] memory: 52Mb, uptime (seconds): 1.148846148, load: [0.02734375,0.0302734375,0]
-190921/234016.493, [ops] memory: 52Mb, uptime (seconds): 2.149207332, load: [0.02734375,0.0302734375,0]
-190921/234017.494, [ops] memory: 52Mb, uptime (seconds): 3.149818512, load: [0.02734375,0.0302734375,0]
-```
-
-It uses `@hapi/good-squeeze` to select only log and response events.
-
-Events that pass the filter stream to `@hapi/good-console` for formatting. See the `good console` [constructor docs](https://github.com/hapijs/good-console#new-goodconsoleconfig) for details on `args` values.
-
-Formatted events stream to `process.stdout` for display.
-
-### Log to file
-
-Create a basic write stream class and use with good:
-
-```js
-const Fs = require('fs-extra');
-const Hapi = require('@hapi/hapi');
-
-
-class GoodFile extends Fs.WriteStream {
-
- constructor(path, options) {
-
- const defaults = {
- encoding: 'utf8',
- flags: 'a',
- mode: 0o666
- };
-
- const settings = Object.assign({}, defaults, options);
- settings.fd = -1; // Prevent open from being called in `super`
-
- super(path, settings);
- this.open();
- }
-
- open() {
-
- this.fd = null;
- Fs.ensureFile(this.path, (err) => {
-
- if (err) {
- this.destroy();
- this.emit('error', err);
- return;
- }
-
- super.open();
- });
- }
-}
-
-
-const start = async function () {
-
- const server = Hapi.server();
-
- const handler = function (request, h) {
-
- request.server.log(['a', 'b', 'c'], 'some message');
- return 'ok';
- };
-
- server.route({ path: '/', method: 'GET', handler })
-
- await server.register({
- plugin: require('@hapi/good'),
- options: {
- ops: {
- interval: 1000
- },
- reporters: {
- myReporter: [
- {
- module: '@hapi/good-squeeze', // Transform payload into a safe string
- name: 'SafeJson'
- },
- {
- module: GoodFile,
- args: ['./log.json']
- }
- ]
- }
- }
- });
-
- await server.start();
- server.log(['log'], 'Server Started');
- await server.inject('/');
-};
-
-start();
-```
-
-This will create or append a file `./log.json` with the following:
-```json
-{"event":"log","timestamp":1569109412144,"tags":["log"],"data":"Server Started","pid":3630}
-{"event":"log","timestamp":1569109412148,"tags":["a","b","c"],"data":"some message","pid":3630}
-{"event":"response","timestamp":1569109412146,"id":"1569109412146:localhost:3630:k0u78b2x:10000","instance":"http://localhost:44883","method":"get","path":"/","query":{},"responseTime":5,"statusCode":200,"pid":3630,"httpVersion":"1.1","route":"/","log":[],"source":{"remoteAddress":"127.0.0.1","userAgent":"shot"},"config":{}}
-{"event":"ops","timestamp":1569109413146,"host":"localhost","pid":3630,"os":{"load":[0.0029296875,0.02001953125,0],"mem":{"total":16682434560,"free":6650597376},"uptime":851831},"proc":{"uptime":1.160361771,"mem":{"rss":54652928,"heapTotal":18948096,"heapUsed":8310912,"external":1271839},"delay":0.9361389875411987},"load":{"requests":{"44883":{"total":1,"disconnects":0,"statusCodes":{"200":1}}},"responseTimes":{"44883":{"avg":5,"max":5}},"sockets":{"http":{"total":0},"https":{"total":0}}}}
-{"event":"ops","timestamp":1569109414145,"host":"localhost","pid":3630,"os":{"load":[0.0029296875,0.02001953125,0],"mem":{"total":16682434560,"free":6650597376},"uptime":851832},"proc":{"uptime":2.160405932,"mem":{"rss":54652928,"heapTotal":18948096,"heapUsed":8358032,"external":1271887},"delay":0.29865598678588867},"load":{"requests":{"44883":{"total":0,"disconnects":0,"statusCodes":{}}},"responseTimes":{"44883":{"avg":null,"max":0}},"sockets":{"http":{"total":0},"https":{"total":0}}}}
-```
-
-### Add custom transform stream
-
-```js
-const Stream = require('stream');
-const Hapi = require('@hapi/hapi');
-
-
-class LogDateTransform extends Stream.Transform {
-
- constructor() {
-
- super({ objectMode: true });
- }
-
- _transform(data, enc, next) {
-
- const date = new Date(Date.now()).toLocaleString('en-US');
-
- if (data.data) {
- return next(null, `${data.event}: ${date}: ${data.data}\n`);
- }
-
- next(null);
- }
-}
-
-
-const start = async function () {
-
- const server = Hapi.server();
-
- const handler = function (request, h) {
-
- request.server.log(['a', 'b', 'c'], 'some message');
- return 'ok';
- };
-
- server.route({ path: '/', method: 'GET', handler })
-
- await server.register({
- plugin: require('@hapi/good'),
- options: {
- ops: {
- interval: 1000
- },
- reporters: {
- myReporter: [
- new LogDateTransform(),
- 'stdout'
- ]
- }
- }
- });
-
- await server.start();
- server.log('info', 'Server is running...');
- await server.inject('/');
-};
-
-start();
-```
-
-This reporter logs data with a date time, writing to the console something like:
-
-```
-log: 9 / 21 / 2019, 4: 47: 25 PM: Server is running...
-log: 9 / 21 / 2019, 4: 47: 25 PM: some message
-```
-
-## Existing streams
-
-The following streams are maintained by the hapi community and are known to work with good. Any transform or write stream can work with good, these are just a few inside the hapijs organization.
-
-- [good-squeeze](https://github.com/hapijs/good-squeeze)
-- [good-console](https://github.com/hapijs/good-console)
-
-## API
-
-See the [API Reference](API.md).
+## Note: this module is being deprecated on December 31st, 2020 due to lack to available support resources. Please consider using [another logging plugin](https://hapi.dev/plugins/#logging).
diff --git a/lib/index.js b/lib/index.js
index 81eba05..050cce3 100755
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,6 +1,6 @@
'use strict';
-const Joi = require('@hapi/joi');
+const Validate = require('@hapi/validate');
const Monitor = require('./monitor');
@@ -9,45 +9,45 @@ const internals = {};
internals.reporters = [
- Joi.object({
- pipe: Joi.func().required(),
- start: Joi.func()
+ Validate.object({
+ pipe: Validate.func().required(),
+ start: Validate.func()
})
.unknown(),
- Joi.string()
+ Validate.string()
.valid('stdout', 'stderr'),
- Joi.object({
- module: Joi.alternatives().try(Joi.string(), Joi.func(), Joi.object()).required(),
- name: Joi.string(),
- args: Joi.array().default([])
+ Validate.object({
+ module: Validate.alternatives().try(Validate.string(), Validate.func(), Validate.object()).required(),
+ name: Validate.string(),
+ args: Validate.array().default([])
})
];
-internals.schema = Joi.object({
+internals.schema = Validate.object({
- includes: Joi.object({
- request: Joi.array().items(Joi.string().valid('headers', 'payload')).default([]),
- response: Joi.array().items(Joi.string().valid('headers', 'payload')).default([])
+ includes: Validate.object({
+ request: Validate.array().items(Validate.string().valid('headers', 'payload')).default([]),
+ response: Validate.array().items(Validate.string().valid('headers', 'payload')).default([])
})
.default({
request: [],
response: []
}),
- reporters: Joi.object()
- .pattern(/./, Joi.array().items(...internals.reporters))
+ reporters: Validate.object()
+ .pattern(/./, Validate.array().items(...internals.reporters))
.default({}),
- extensions: Joi.array()
- .items(Joi.string().invalid('log', 'ops', 'request', 'response'))
+ extensions: Validate.array()
+ .items(Validate.string().invalid('log', 'ops', 'request', 'response'))
.default([]),
- ops: Joi.alternatives([
- Joi.object(),
- Joi.bool().allow(false)
+ ops: Validate.alternatives([
+ Validate.object(),
+ Validate.bool().allow(false)
])
.default({
config: {},
@@ -58,19 +58,17 @@ internals.schema = Joi.object({
exports.plugin = {
- name: 'good',
pkg: require('../package.json'),
requirements: {
- hapi: '>=17.9.0'
+ hapi: '>=18.4.0'
},
register: function (server, options) {
- // Do the initial configuration
- const settings = Joi.attempt(options, internals.schema);
+ const settings = Validate.attempt(options, internals.schema);
const monitor = new Monitor(server, settings);
server.ext('onPostStop', internals.onPostStop(monitor));
- server.ext('onPreStart', internals.onPreStart(monitor));
+ server.ext('onPreStart', internals.onPreStart(monitor, settings));
server.expose('reconfigure', internals.reconfigure(monitor));
monitor.start();
@@ -87,11 +85,12 @@ internals.onPostStop = function (monitor) {
};
-internals.onPreStart = function (monitor) {
+internals.onPreStart = function (monitor, options) {
return (server, h) => {
- monitor.startOps();
+ const interval = options.ops.interval;
+ monitor.startOps(interval);
};
};
@@ -100,7 +99,7 @@ internals.reconfigure = function (monitor) {
return (options) => {
monitor.stop();
- const settings = Joi.attempt(options, internals.schema);
+ const settings = Validate.attempt(options, internals.schema);
monitor.configure(settings);
monitor.start();
};
diff --git a/lib/utils.js b/lib/utils.js
index b36c528..9323544 100755
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -75,7 +75,7 @@ exports.RequestSent = class {
this.method = request.method;
this.path = request.path;
this.query = request.query;
- this.responseTime = request.info.completed - request.info.received;
+ this.responseTime = (request.info.completed || request.info.responded) - request.info.received; // $lab:coverage:ignore$
this.statusCode = res.statusCode;
this.pid = process.pid;
this.httpVersion = request.raw.req.httpVersion;
diff --git a/package.json b/package.json
index cd1b0e6..5b85ed1 100644
--- a/package.json
+++ b/package.json
@@ -1,9 +1,12 @@
{
"name": "@elastic/good",
"description": "Server and process monitoring plugin",
- "version": "8.2.3-kibana1",
+ "version": "9.0.1-kibana1",
"repository": "git://github.com/elastic/good",
"main": "lib/index.js",
+ "files": [
+ "lib"
+ ],
"keywords": [
"process",
"monitor",
@@ -13,19 +16,20 @@
"plugin"
],
"dependencies": {
- "@hapi/hoek": "8.x.x",
- "@hapi/joi": "16.x.x",
- "@hapi/oppsy": "2.x.x",
- "pumpify": "1.x.x"
+ "@hapi/hoek": "9.x.x",
+ "@hapi/oppsy": "3.x.x",
+ "@hapi/validate": "1.x.x",
+ "pumpify": "2.x.x"
},
"devDependencies": {
- "@hapi/code": "6.x.x",
- "@hapi/hapi": "18.x.x",
- "@hapi/lab": "20.x.x",
- "@hapi/wreck": "15.x.x"
+ "@hapi/code": "8.x.x",
+ "@hapi/hapi": "20.x.x",
+ "@hapi/lab": "24.x.x",
+ "@hapi/wreck": "17.x.x"
},
"scripts": {
- "test": "lab -m 5000 -t 100 -L -a @hapi/code"
+ "test": "lab -m 5000 -t 100 -L -a @hapi/code",
+ "test-cov-html": "lab -a @hapi/code -r html -o coverage.html"
},
"license": "BSD-3-Clause"
}
diff --git a/test/fixtures/reporter.js b/test/fixtures/reporter.js
index 2501157..30fae1b 100755
--- a/test/fixtures/reporter.js
+++ b/test/fixtures/reporter.js
@@ -6,7 +6,9 @@ const Stream = require('stream');
const internals = {};
-module.exports = class extends Stream.Transform {
+module.exports = internals.Reporter = class extends Stream.Transform {
+
+ static name = 'test';
constructor() {
diff --git a/test/monitor.js b/test/monitor.js
index b65f07c..023a4eb 100755
--- a/test/monitor.js
+++ b/test/monitor.js
@@ -1,5 +1,7 @@
'use strict';
+const Path = require('path');
+
const Code = require('@hapi/code');
const Hapi = require('@hapi/hapi');
const Hoek = require('@hapi/hoek');
@@ -125,6 +127,7 @@ describe('Monitor', () => {
it('correctly passes dynamic arguments to stream constructors', { plan: 4 }, async () => {
const Inc = Reporters.Incrementer;
+ const fixturePath = Path.join(process.cwd(), 'test', 'fixtures', 'reporter.js');
Reporters.Incrementer = function (starting, multiple) {
Reporters.Incrementer = Inc;
@@ -134,9 +137,9 @@ describe('Monitor', () => {
return new Inc(starting, multiple);
};
- require.cache[process.cwd() + '/test/fixtures/reporter.js'].exports = function (options) {
+ require.cache[fixturePath].exports = function (options) {
- require.cache[process.cwd() + '/test/fixtures/reporter.js'].exports = Stringify;
+ require.cache[fixturePath].exports = Stringify;
expect(options).to.be.undefined();
return new Stringify(options);
};
@@ -145,7 +148,7 @@ describe('Monitor', () => {
reporters: {
foo: [
new Reporters.Incrementer(10, 5),
- { module: require('./fixtures/reporter') }
+ { module: require(fixturePath) }
]
}
});