Skip to content

Commit

Permalink
Add coverage ignores to recorder, and emit text report (#1608)
Browse files Browse the repository at this point in the history
Ref #1404 (comment)

This leaves intact two missed coverage spots in `lib/recorder.js` which are being taken care of in #1588.

Also ref #1607
  • Loading branch information
paulmelnikow authored and gr2m committed Sep 4, 2019
1 parent 3223365 commit 50791bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/recorder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
'use strict'

// This file contains some coverage ignores marked TODO-coverage. Before
// refactoring within this file, these lines should be cleaned up.
// https://github.com/nock/nock/issues/1607

const { inspect } = require('util')
const { parse: urlParse } = require('url')
const common = require('./common')
Expand All @@ -25,6 +29,8 @@ function getScope(options) {

scope.push(options.host)

// TODO-coverage Some part of this conditional is not reached.
/* istanbul ignore if */
if (
options.host.indexOf(':') === -1 &&
options.port &&
Expand Down Expand Up @@ -153,6 +159,7 @@ function generateRequestAndResponse(req, bodyChunks, options, res, dataChunks) {
}
ret.push(')\n')
// TODO-coverage: Try to add coverage of this case.
/* istanbul ignore if */
if (req.headers) {
for (const k in req.headers) {
ret.push(
Expand All @@ -173,6 +180,7 @@ function generateRequestAndResponse(req, bodyChunks, options, res, dataChunks) {
ret.push(res.statusCode.toString())
ret.push(', ')
ret.push(JSON.stringify(responseBody))
/* istanbul ignore else */
if (res.rawHeaders) {
ret.push(', ')
ret.push(inspect(res.rawHeaders))
Expand Down Expand Up @@ -257,6 +265,7 @@ function record(recOptions) {

// Node 0.11 https.request calls http.request -- don't want to record things
// twice.
/* istanbul ignore if */
if (options._recording) {
return overriddenRequest(options, callback)
}
Expand Down Expand Up @@ -284,6 +293,7 @@ function record(recOptions) {
res,
dataChunks
)
/* istanbul ignore else */
// TODO-coverage: The `else` case is missing coverage. Maybe look
// into the enable_reqheaders_recording option.
if (out.reqheaders) {
Expand Down Expand Up @@ -325,6 +335,7 @@ function record(recOptions) {

if (!dontPrint) {
if (useSeparator) {
/* istanbul ignore if */
if (typeof out !== 'string') {
// TODO-coverage: This is missing coverage. Could this be
// connected to the `output_object` option?
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"tap": "^14.0.0"
},
"scripts": {
"unit": "tap --coverage ./tests/test_*.js",
"unit": "tap --coverage --coverage-report=text ./tests/test_*.js",
"pretest": "npm run -s lint",
"test": "npm run -s unit",
"posttest": "npm run -s prettier:check",
Expand Down

0 comments on commit 50791bc

Please sign in to comment.