forked from nodejs/undici
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add pending interceptor check functions to mock agent (nodejs#1358
- Loading branch information
1 parent
25a979f
commit 1f773fb
Showing
8 changed files
with
434 additions
and
22 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
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,40 @@ | ||
'use strict' | ||
|
||
const { Transform } = require('stream') | ||
const { Console } = require('console') | ||
|
||
/** | ||
* Gets the output of `console.table(…)` as a string. | ||
*/ | ||
module.exports = class PendingInterceptorsFormatter { | ||
constructor ({ disableColors } = {}) { | ||
this.transform = new Transform({ | ||
transform (chunk, _enc, cb) { | ||
cb(null, chunk) | ||
} | ||
}) | ||
|
||
this.logger = new Console({ | ||
stdout: this.transform, | ||
inspectOptions: { | ||
colors: !disableColors && !process.env.CI | ||
} | ||
}) | ||
} | ||
|
||
format (pendingInterceptors) { | ||
const withPrettyHeaders = pendingInterceptors.map( | ||
({ method, path, data: { statusCode }, persist, times, timesInvoked, origin }) => ({ | ||
Method: method, | ||
Origin: origin, | ||
Path: path, | ||
'Status code': statusCode, | ||
Persistent: persist ? '✅' : '❌', | ||
Invocations: timesInvoked, | ||
Remaining: persist ? Infinity : times - timesInvoked | ||
})) | ||
|
||
this.logger.table(withPrettyHeaders) | ||
return this.transform.read().toString() | ||
} | ||
} |
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,29 @@ | ||
'use strict' | ||
|
||
const singulars = { | ||
pronoun: 'it', | ||
is: 'is', | ||
was: 'was', | ||
this: 'this' | ||
} | ||
|
||
const plurals = { | ||
pronoun: 'they', | ||
is: 'are', | ||
was: 'were', | ||
this: 'these' | ||
} | ||
|
||
module.exports = class Pluralizer { | ||
constructor (singular, plural) { | ||
this.singular = singular | ||
this.plural = plural | ||
} | ||
|
||
pluralize (count) { | ||
const one = count === 1 | ||
const keys = one ? singulars : plurals | ||
const noun = one ? this.singular : this.plural | ||
return { ...keys, count, noun } | ||
} | ||
} |
Oops, something went wrong.