main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 16 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | 'use strict'
|
---|
| 2 |
|
---|
| 3 | const { Transform } = require('stream')
|
---|
| 4 | const { Console } = require('console')
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 7 | * Gets the output of `console.table(…)` as a string.
|
---|
| 8 | */
|
---|
| 9 | module.exports = class PendingInterceptorsFormatter {
|
---|
| 10 | constructor ({ disableColors } = {}) {
|
---|
| 11 | this.transform = new Transform({
|
---|
| 12 | transform (chunk, _enc, cb) {
|
---|
| 13 | cb(null, chunk)
|
---|
| 14 | }
|
---|
| 15 | })
|
---|
| 16 |
|
---|
| 17 | this.logger = new Console({
|
---|
| 18 | stdout: this.transform,
|
---|
| 19 | inspectOptions: {
|
---|
| 20 | colors: !disableColors && !process.env.CI
|
---|
| 21 | }
|
---|
| 22 | })
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | format (pendingInterceptors) {
|
---|
| 26 | const withPrettyHeaders = pendingInterceptors.map(
|
---|
| 27 | ({ method, path, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
|
---|
| 28 | Method: method,
|
---|
| 29 | Origin: origin,
|
---|
| 30 | Path: path,
|
---|
| 31 | 'Status code': statusCode,
|
---|
| 32 | Persistent: persist ? '✅' : '❌',
|
---|
| 33 | Invocations: timesInvoked,
|
---|
| 34 | Remaining: persist ? Infinity : times - timesInvoked
|
---|
| 35 | }))
|
---|
| 36 |
|
---|
| 37 | this.logger.table(withPrettyHeaders)
|
---|
| 38 | return this.transform.read().toString()
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.