fancy-test-nock
Advanced tools
Comparing version
import * as Nock from 'nock'; | ||
export import NockScope = Nock.Scope; | ||
export declare type Callback = (nock: NockScope) => any; | ||
export type Callback = (nock: NockScope) => unknown; | ||
export default function nock(host?: string, options?: Callback | Nock.Options, cb?: Callback): { | ||
@@ -5,0 +5,0 @@ run(ctx: { |
@@ -12,13 +12,15 @@ "use strict"; | ||
throw new Error('callback is undefined'); | ||
// eslint-disable-next-line unicorn/prefer-module | ||
const nock = require('nock'); | ||
const intercepter = nock(host, options); | ||
const interceptor = nock(host, options); | ||
return { | ||
async run(ctx) { | ||
ctx.nock = ctx.nock || 0; | ||
await cb(intercepter); | ||
await cb(interceptor); | ||
ctx.nock++; | ||
}, | ||
// eslint-disable-next-line perfectionist/sort-objects | ||
finally(ctx) { | ||
if (!ctx.error) | ||
intercepter.done(); | ||
interceptor.done(); | ||
ctx.nock--; | ||
@@ -25,0 +27,0 @@ if (ctx.nock === 0) |
{ | ||
"name": "fancy-test-nock", | ||
"description": "extendable utilities for testing", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"author": "Salesforce", | ||
@@ -9,19 +9,17 @@ "bugs": "https://github.com/oclif/fancy-test-nock/issues", | ||
"devDependencies": { | ||
"@types/chai": "^4.3.6", | ||
"@types/mocha": "^8.0.0", | ||
"@types/chai": "^4.3.11", | ||
"@types/mocha": "^10.0.0", | ||
"@types/nock": "^11.1.0", | ||
"@types/node": "^14.18.62", | ||
"chai": "^4.3.8", | ||
"concurrently": "^6.5.1", | ||
"eslint": "^7.3.1", | ||
"eslint-config-anycli": "^1.3.2", | ||
"eslint-config-oclif": "^3.1.0", | ||
"eslint-config-oclif-typescript": "^0.2.0", | ||
"fancy-test": "^1.0.4", | ||
"@types/node": "^14.18.63", | ||
"chai": "^4.4.1", | ||
"eslint": "^8", | ||
"eslint-config-oclif": "^5", | ||
"eslint-config-oclif-typescript": "^3", | ||
"fancy-test": "^3", | ||
"http-call": "^5.1.0", | ||
"mocha": "^5.1.0", | ||
"nock": "^13.3.3", | ||
"sinon": "^9.0.2", | ||
"ts-node": "^9.0.0", | ||
"typescript": "4.6.3" | ||
"mocha": "^10", | ||
"nock": "^13.5.1", | ||
"sinon": "^17", | ||
"ts-node": "^10", | ||
"typescript": "^5" | ||
}, | ||
@@ -45,3 +43,3 @@ "engines": { | ||
"prepublishOnly": "yarn run build", | ||
"pretest": "yarn build --noEmit && tsc -p test --noEmit", | ||
"pretest": "yarn build && tsc -p test --noEmit", | ||
"test": "mocha --forbid-only \"test/**/*.test.ts\"", | ||
@@ -51,2 +49,2 @@ "posttest": "yarn lint" | ||
"types": "lib/index.d.ts" | ||
} | ||
} |
3061
0.36%15
-11.76%43
4.88%