From d88f065c5b708a4faa8b15e3b90232243ee9652d Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Sun, 4 Feb 2018 17:19:00 -0800 Subject: [PATCH] fix: move nock to other module BREAKING CHANGE: nock is now in @fancy-test/nock --- README.md | 3 ++ package.json | 3 -- src/index.ts | 3 -- src/nock.ts | 24 --------------- src/stub.ts | 2 +- test/nock.test.ts | 26 ---------------- yarn.lock | 76 ++--------------------------------------------- 7 files changed, 7 insertions(+), 130 deletions(-) delete mode 100644 src/nock.ts delete mode 100644 test/nock.test.ts diff --git a/README.md b/README.md index 4bf2ff8..926290a 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,9 @@ Uses [nock](https://github.com/node-nock/nock) to mock out HTTP calls to externa Automatically calls `done()` to ensure the calls were made and `cleanAll()` to remove any pending requests. ```js +const fancy = require('fancy-test') +.register('nock', require('@fancy-test/nock')) + describe('nock tests', () => { fancy .nock('https://api.github.com', nock => { diff --git a/package.json b/package.json index 1bd94f2..8526f2a 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,7 @@ "@types/chai": "^4.1.2", "@types/lodash": "^4.14.100", "@types/mocha": "^2.2.48", - "@types/nock": "^9.1.2", "@types/node": "^9.4.0", - "@types/node-notifier": "^0.0.28", "@types/read-pkg": "^3.0.0", "@types/sinon": "^4.1.3", "chai": "^4.1.2", @@ -25,7 +23,6 @@ "eslint-config-anycli": "^1.3.2", "http-call": "^5.0.2", "mocha": "^5.0.0", - "nock": "^9.1.6", "sinon": "^4.2.2", "ts-node": "^4.1.0", "typescript": "^2.7.1" diff --git a/src/index.ts b/src/index.ts index 4a91fa6..e345ea1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,6 @@ import base from './base' import _catch from './catch' import {expect} from './chai' import env from './env' -import {nock, NockScope} from './nock' import {stderr, stdout} from './stdmock' import stub from './stub' @@ -12,7 +11,6 @@ export const fancy = base .register('catch', _catch) .register('env', env) .register('stub', stub) -.register('nock', nock) .register('stderr', stderr) .register('stdout', stdout) @@ -21,6 +19,5 @@ export type Fancy = typeof fancy export { expect, FancyTypes, - NockScope, } export default fancy diff --git a/src/nock.ts b/src/nock.ts deleted file mode 100644 index acefe75..0000000 --- a/src/nock.ts +++ /dev/null @@ -1,24 +0,0 @@ -import * as _ from 'lodash' -import * as Nock from 'nock' - -export function nock(host?: string, cb?: (nock: NockScope) => any) { - if (_.isUndefined(host)) throw new Error('host is undefined') - if (_.isUndefined(cb)) throw new Error('callback is undefined') - - const nock: typeof Nock = require('nock') - const intercepter = nock(host) - return { - async run(ctx: {nock: number}) { - ctx.nock = ctx.nock || 0 - await cb(intercepter) - ctx.nock++ - }, - finally(ctx: {error?: Error, nock: number}) { - if (!ctx.error) intercepter.done() - ctx.nock-- - if (ctx.nock === 0) nock.cleanAll() - }, - } -} - -export interface NockScope extends Nock.Scope {} diff --git a/src/stub.ts b/src/stub.ts index 98a6e56..ffb95af 100644 --- a/src/stub.ts +++ b/src/stub.ts @@ -4,7 +4,7 @@ import * as _ from 'lodash' * mocks an object's property */ export default function (object?: any, path?: string, value?: any) { - if (_.isUndefined(object) || _.isUndefined(path))throw new Error('should not be undefined') + if (object === undefined || path === undefined) throw new Error('should not be undefined') return { run(ctx: {stubs: any[]}) { ctx.stubs = ctx.stubs || [] diff --git a/test/nock.test.ts b/test/nock.test.ts deleted file mode 100644 index 62d7624..0000000 --- a/test/nock.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import HTTP from 'http-call' - -import {expect, fancy} from '../src' - -describe('nock', () => { - // from readme - fancy - .nock('https://api.github.com', nock => { - nock - .get('/me') - .reply(200, {name: 'jdxcode'}) - }) - .end('mocks http call to github', async () => { - const {body: user} = await HTTP.get('https://api.github.com/me') - expect(user).to.have.property('name', 'jdxcode') - }) - // from readme - - // fancy() - // .nock('https://api.github.com', nock => { - // nock - // .get('/me') - // .reply(200, {name: 'jdxcode'}) - // }) - // .end('calls .done()') -}) diff --git a/yarn.lock b/yarn.lock index 159233f..3dcaa7c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -21,19 +21,7 @@ version "2.2.48" resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.48.tgz#3523b126a0b049482e1c3c11877460f76622ffab" -"@types/nock@^9.1.2": - version "9.1.2" - resolved "https://registry.yarnpkg.com/@types/nock/-/nock-9.1.2.tgz#0515b27e3f6bbc11834d22508ad02e2921dd376a" - dependencies: - "@types/node" "*" - -"@types/node-notifier@^0.0.28": - version "0.0.28" - resolved "https://registry.yarnpkg.com/@types/node-notifier/-/node-notifier-0.0.28.tgz#86ba3d3aa8d918352cc3191d88de328b20dc93c1" - dependencies: - "@types/node" "*" - -"@types/node@*", "@types/node@^9.4.0": +"@types/node@^9.4.0": version "9.4.0" resolved "https://registry.yarnpkg.com/@types/node/-/node-9.4.0.tgz#b85a0bcf1e1cc84eb4901b7e96966aedc6f078d1" @@ -177,14 +165,6 @@ callsites@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/callsites/-/callsites-0.2.0.tgz#afab96262910a7f33c19a5775825c69f34e350ca" -"chai@>=1.9.2 <4.0.0": - version "3.5.0" - resolved "https://registry.yarnpkg.com/chai/-/chai-3.5.0.tgz#4d02637b067fe958bdbfdd3a40ec56fef7373247" - dependencies: - assertion-error "^1.0.1" - deep-eql "^0.1.3" - type-detect "^1.0.0" - chai@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/chai/-/chai-4.1.2.tgz#0f64584ba642f0f2ace2806279f4f06ca23ad73c" @@ -329,28 +309,12 @@ debug@*, debug@3.1.0, debug@^3.1.0: dependencies: ms "2.0.0" -debug@^2.2.0: - version "2.6.9" - resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" - dependencies: - ms "2.0.0" - -deep-eql@^0.1.3: - version "0.1.3" - resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-0.1.3.tgz#ef558acab8de25206cd713906d74e56930eb69f2" - dependencies: - type-detect "0.1.1" - deep-eql@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df" dependencies: type-detect "^4.0.0" -deep-equal@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5" - deep-is@~0.1.3: version "0.1.3" resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" @@ -782,10 +746,6 @@ json-stable-stringify-without-jsonify@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" -json-stringify-safe@^5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" - just-extend@^1.1.26: version "1.1.27" resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-1.1.27.tgz#ec6e79410ff914e472652abfa0e603c03d60e905" @@ -821,7 +781,7 @@ lodash.zip@^4.2.0: version "4.2.0" resolved "https://registry.yarnpkg.com/lodash.zip/-/lodash.zip-4.2.0.tgz#ec6662e4896408ed4ab6c542a3990b72cc080020" -lodash@^4.17.4, lodash@^4.3.0, lodash@^4.5.1, lodash@~4.17.2: +lodash@^4.17.4, lodash@^4.3.0, lodash@^4.5.1: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" @@ -862,7 +822,7 @@ minimist@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" -mkdirp@0.5.1, mkdirp@^0.5.0, mkdirp@^0.5.1: +mkdirp@0.5.1, mkdirp@^0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" dependencies: @@ -905,20 +865,6 @@ nise@^1.2.0: path-to-regexp "^1.7.0" text-encoding "^0.6.4" -nock@^9.1.6: - version "9.1.6" - resolved "https://registry.yarnpkg.com/nock/-/nock-9.1.6.tgz#16395af4c45b0fd84d1a4a9668154e16fa6624db" - dependencies: - chai ">=1.9.2 <4.0.0" - debug "^2.2.0" - deep-equal "^1.0.0" - json-stringify-safe "^5.0.1" - lodash "~4.17.2" - mkdirp "^0.5.0" - propagate "0.4.0" - qs "^6.5.1" - semver "^5.3.0" - object-assign@^4.0.1: version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" @@ -1006,18 +952,10 @@ progress@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.0.tgz#8a1be366bf8fc23db2bd23f10c6fe920b4389d1f" -propagate@0.4.0: - version "0.4.0" - resolved "https://registry.yarnpkg.com/propagate/-/propagate-0.4.0.tgz#f3fcca0a6fe06736a7ba572966069617c130b481" - pseudomap@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" -qs@^6.5.1: - version "6.5.1" - resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8" - ramda@^0.24.1: version "0.24.1" resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.24.1.tgz#c3b7755197f35b8dc3502228262c4c91ddb6b857" @@ -1357,14 +1295,6 @@ type-check@~0.3.2: dependencies: prelude-ls "~1.1.2" -type-detect@0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-0.1.1.tgz#0ba5ec2a885640e470ea4e8505971900dac58822" - -type-detect@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-1.0.0.tgz#762217cc06db258ec48908a1298e8b95121e8ea2" - type-detect@^4.0.0, type-detect@^4.0.5: version "4.0.7" resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.7.tgz#862bd2cf6058ad92799ff5a5b8cf7b6cec726198"