From d20312e05a84b7b7461d746f3afdcb633236f764 Mon Sep 17 00:00:00 2001 From: Ben Drucker Date: Thu, 1 Mar 2018 10:00:37 -0800 Subject: [PATCH] add tests asserting array behavior * empty stub arrays are filled * filled stub arrays are untouched * you can set a non-enumerable @noCallThru via Object.defineProperty This is not necessarily the ideal behavior, just the simplest way to define where we are today and leave someone with the opporunity to contribute a use case and a different strategy Closes #191 --- test/proxyquire-non-object.js | 55 +++++++++++++++++++++++++++++++++++ test/samples/foo.js | 2 ++ test/samples/fooarray.js | 1 + 3 files changed, 58 insertions(+) create mode 100644 test/samples/fooarray.js diff --git a/test/proxyquire-non-object.js b/test/proxyquire-non-object.js index a21a5f0..a0b56d9 100644 --- a/test/proxyquire-non-object.js +++ b/test/proxyquire-non-object.js @@ -11,6 +11,8 @@ describe('Given foo requires the boof, foonum and foobool modules and boof is a var boofber = 'a_string' var foonumber = 4 var fooboolber = false + var emptyarray = [] + var fooarray = ['x', 'y', 'z'] describe('When I resolve foo with boofber stub as boof.', function () { before(function () { @@ -62,4 +64,57 @@ describe('Given foo requires the boof, foonum and foobool modules and boof is a }) }) }) + + describe('When I resolve foo with ./fooarray stub as fooarray.', function () { + before(function () { + stats.reset() + foo = proxyquire('./samples/foo', {'./fooarray': fooarray}) + }) + + it('foo is required 1 times', function () { + assert.equal(stats.fooRequires(), 1) + }) + + describe('foo\'s fooarray is fooarray', function () { + it('foo.fooarray is fooarray', function () { + assert.deepEqual(foo.fooarray, ['x', 'y', 'z']) + }) + }) + }) + + describe('When I resolve foo with ./fooarray stub as empty.', function () { + before(function () { + stats.reset() + foo = proxyquire('./samples/foo', {'./fooarray': []}) + }) + + it('foo is required 1 times', function () { + assert.equal(stats.fooRequires(), 1) + }) + + describe('foo\'s fooarray is the original', function () { + it('foo.fooarray is empty', function () { + assert.deepEqual(foo.fooarray, ['a', 'b', 'c']) + }) + }) + }) + + describe('When I resolve foo with ./fooarray stub as empty with @noCallThru.', function () { + before(function () { + stats.reset() + var empty = [] + Object.defineProperty(empty, '@noCallThru', {value: true}) + foo = proxyquire('./samples/foo', {'./fooarray': empty}) + }) + + it('foo is required 1 times', function () { + assert.equal(stats.fooRequires(), 1) + }) + + describe('foo\'s fooarray is empty', function () { + it('foo.fooarray is empty', function () { + assert.deepEqual(foo.fooarray, []) + }) + }) + }) }) diff --git a/test/samples/foo.js b/test/samples/foo.js index e58989d..d525ea5 100644 --- a/test/samples/foo.js +++ b/test/samples/foo.js @@ -3,6 +3,7 @@ var bar = require('./bar') var boof = require('./boof') var foonum = require('./foonum') var foobool = require('./foobool') +var fooarray = require('./fooarray') var path = require('path') var crypto @@ -41,6 +42,7 @@ module.exports = { boof: boof, foonum: foonum, foobool: foobool, + fooarray: fooarray, bigCrypto: bigCrypto, state: '' } diff --git a/test/samples/fooarray.js b/test/samples/fooarray.js new file mode 100644 index 0000000..c7c7aa4 --- /dev/null +++ b/test/samples/fooarray.js @@ -0,0 +1 @@ +module.exports = ['a', 'b', 'c']