Skip to content

Commit 77a5aa5

Browse files
committed
tests(helpers): add http formatter tests for Express objects
1 parent bfd437b commit 77a5aa5

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

helpers/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ for winston.
8282
### `formatHttpRequest`
8383

8484
Function that enhances an ECS object with http request data.
85-
The request object should be Node.js's core request object.
85+
The request object should be Node.js's core
86+
[`http.IncomingMessage`](https://nodejs.org/api/all.html#http_class_http_incomingmessage),
87+
or [Express's request object](https://expressjs.com/en/5x/api.html#req) that
88+
extends it.
8689

8790
```js
8891
const { formatHttpRequest } = require('@elastic/ecs-helpers')
@@ -105,7 +108,10 @@ console.log(ecs)
105108
### `formatHttpResponse`
106109

107110
Function that enhances an ECS object with http response data.
108-
The response object should be Node.js's core response object.
111+
The response object should be Node.js's core
112+
[`http.ServerResponse`](https://nodejs.org/api/all.html#http_class_http_serverresponse),
113+
or [Express's response object](https://expressjs.com/en/5x/api.html#res) that
114+
extends it.
109115

110116
```js
111117
const { formatHttpResponse } = require('@elastic/ecs-helpers')

helpers/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"homepage": "https://github.com/elastic/ecs-logging-nodejs/blob/master/helpers/README.md",
1919
"scripts": {
20-
"test": "standard && tap --timeout ${TAP_TIMEOUT:-10} test.js"
20+
"test": "standard && tap --timeout ${TAP_TIMEOUT:-10} test/*.test.js"
2121
},
2222
"engines": {
2323
"node": ">=10"
@@ -28,6 +28,7 @@
2828
"devDependencies": {
2929
"ajv": "^7.0.3",
3030
"ajv-formats": "^1.5.1",
31+
"express": "^4.17.1",
3132
"semver": "^7.1.3",
3233
"standard": "16.x",
3334
"tap": "^14.x"

helpers/test.js renamed to helpers/test/basic.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ const Ajv = require('ajv').default
2424
const semver = require('semver')
2525
const test = require('tap').test
2626

27-
const { ecsLoggingValidate } = require('../utils/lib/ecs-logging-validate')
27+
const { ecsLoggingValidate } = require('../../utils/lib/ecs-logging-validate')
2828

2929
const {
3030
version,
3131
stringify,
3232
formatError,
3333
formatHttpRequest,
3434
formatHttpResponse
35-
} = require('./')
35+
} = require('../')
3636

3737
const ajv = new Ajv({
3838
allErrors: true,
3939
verbose: true
4040
})
4141
addFormats(ajv)
42-
const validate = ajv.compile(require('../utils/schema.json'))
42+
const validate = ajv.compile(require('../../utils/schema.json'))
4343

4444
test('stringify should return a valid ecs json', t => {
4545
const ecsFields = {

0 commit comments

Comments
 (0)