From 9b5e467978d4daeec6c10185f78442d35365cca7 Mon Sep 17 00:00:00 2001 From: Jon Jaques Date: Wed, 5 Jun 2019 18:31:21 -0500 Subject: [PATCH 1/2] Add options for nock output path --- index.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index bf1e858..aab2cf7 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ const fs = require('fs'); const path = require('path'); const mkdirp = require('mkdirp'); -const subPathName = '__nocks__'; +const defaults = { fixturePath: '__nocks__' }; function beforeTest (nockFilePath, nockOptions) { if (process.env.JEST_NOCK_RECORD === 'true') { @@ -64,7 +64,7 @@ const getNockOptions = (args) => { return args[args.length - 1]; } -const bindNock = (fn, testPath, overrideTitle) => { +const bindNock = (fn, testPath, opts, overrideTitle) => { return function (...args) { let title = args[0]; let testFn = args[1]; @@ -86,7 +86,7 @@ const bindNock = (fn, testPath, overrideTitle) => { }; const nockFileName = `${name}_${djb2(title)}.nock.json`; - const nockFileDir = path.resolve(dir, subPathName); + const nockFileDir = path.resolve(dir, opts.fixturePath); const nockFilePath = path.join(nockFileDir, nockFileName); let wrappedTest = null; @@ -139,14 +139,15 @@ function djb2 (str) { return hash >>> 0; } -function upgradeJasmine (jsmn, glb) { +function upgradeJasmine (jsmn, glb, options = {}) { + const opts = Object.assign(defaults, options) const env = jsmn.getEnv(); const testPath = jsmn.testPath; - glb.it.nock = bindNock(env.it, testPath); - glb.fit.nock = bindNock(env.fit, testPath); - glb.beforeAll.nock = bindNock(env.beforeAll, testPath, 'beforeAll'); - glb.afterAll.nock = bindNock(env.afterAll, testPath, 'afterAll'); + glb.it.nock = bindNock(env.it, testPath, opts); + glb.fit.nock = bindNock(env.fit, testPath, opts); + glb.beforeAll.nock = bindNock(env.beforeAll, testPath, opts, 'beforeAll'); + glb.afterAll.nock = bindNock(env.afterAll, testPath, opts, 'afterAll'); } module.exports = { From 59a94813b98af8231de17d2f343db704bbf972c8 Mon Sep 17 00:00:00 2001 From: Jon Jaques <637410+jonjaques@users.noreply.github.com> Date: Tue, 19 Oct 2021 16:32:51 -0500 Subject: [PATCH 2/2] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cdbd759..50bee60 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jest-nock", - "version": "0.1.7", + "version": "0.1.8", "description": "Nock integration for Jest", "main": "index.js", "scripts": {