Skip to content

Commit

Permalink
add docs for proxying modules that export functions w/ options
Browse files Browse the repository at this point in the history
Ref #56
  • Loading branch information
bendrucker committed Mar 26, 2015
1 parent 777993c commit 74365bf
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ assert.equal(foo.basenameAllCaps('/a/b/file.txt'), 'FILE.TXT');

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [Usage](#usage)
- [API](#api)
Expand All @@ -70,6 +70,7 @@ assert.equal(foo.basenameAllCaps('/a/b/file.txt'), 'FILE.TXT');
- [Globally override require during module initialization](#globally-override-require-during-module-initialization)
- [Why is proxyquire messing with my `require` cache?](#why-is-proxyquire-messing-with-my-require-cache)
- [Globally override require during module runtime](#globally-override-require-during-module-runtime)
- [Modules That Export Functions](#modules-that-export-functions)
- [Backwards Compatibility for proxyquire v0.3.x](#backwards-compatibility-for-proxyquire-v03x)
- [Examples](#examples)
- [More Examples](#more-examples)
Expand Down Expand Up @@ -357,6 +358,26 @@ every time the module is requested via `require` at runtime as no module will ev
This can cause subtle bugs so if you can guarantee that your modules will not vary their `require` behaviour at runtime,
use `@global` instead.

## Modules That Export Functions

Even if you want to override a module that exports a function directly, you can still set special properties like `@global`. You can use a named function or assign your stub function to a variable to add properties:

```js
foo['@global'] = true;
function foo () {}
proxyquire('./bar', {
foo: foo
});
```

```js
var foo = function () {};
foo['@global'] = true;
proxyquire('./bar', {
foo: foo
});
```

This comment has been minimized.

Copy link
@thlorenz

thlorenz Mar 26, 2015

Owner

Am I missing something or are these examples identical except for assignment vs. declaration?

I think it'd be very useful to show the case of someone requireing a stub from a module and then adding the flag.
We could change the heading to Configuring proxyquire by setting stub properties.

Then show the first function example and something similar to:

var foostub = require('../stubs/foostub');
foostub['@noCallThru'] = true;
proxyquire('bar, { './foo': foostub });

This comment has been minimized.

Copy link
@bendrucker

bendrucker Mar 26, 2015

Author Collaborator

Yes, they're identical in practice. And the require example makes a ton of sense. Will open a PR there.


# Backwards Compatibility for proxyquire v0.3.x

Compatibility mode with proxyquire v0.3.x **has been removed**.
Expand Down

2 comments on commit 74365bf

@thlorenz
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for very minor things it'd be easier to work off the master branch and discuss changes via a PR.
That way we can get it perfect before merging into master.
Also it's easier to see all the comments that way instead of spread over different commits.
What do you think?

@bendrucker
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

Please sign in to comment.