-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#33] Search for packages locally #34
Conversation
@@ -58,22 +63,52 @@ const after = () => { | |||
}; | |||
|
|||
|
|||
test('Find Scaffolds success', assert => { | |||
test('Find Scaffolds API', assert => { | |||
before(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip: instead of using a generic name like this, you could use a more semantic name like "stubNpm()
".
Also, as a matter of discipline, you could also localize the npm
var and inject it as a dependency to findGlobal rather than requiring it. That way you separate the side-effects (npm API I/O) from the program logic, and it allows you to do this:
const npm = stubNpm();
// ... do stuff
resetNpm(npm);
assert.end();
I find this easier to read because you can see what's going on inline without scrolling up and looking at the before()
and after()
functions. You also avoid the common situation where some tests need more setup/teardown than others, but you run everything for all tests. For example, your first test doesn't need the stub at all (unless I'm reading it wrong), but you're calling the functions anyway...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that all makes a lot of sense. After I started with tape I began to "purify" my functions and modules as much as possible. Will update this code as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 On a related note... I'm going into lots of detail about how to write better tests in a webcast next week.
I've made a little refactoring to keep find-scaffolds pure by passing npm in. Which simplified tests. No need to reset |
new Promise((...args) => npm.load({global, silent: true, depth: 0}, loaded(npm)(...args))); | ||
|
||
|
||
export const findLocal = npm => findScaffolds(npm)(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kill the boolean trap, please. Switch on 'local'
/'global'
instead of true
/false
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice article, thanks.
lgtm... remove the boolean trap, and I think we're good to go, right? |
Sure, as soon as I get to my laptop :)
|
👍 |
Pushed the code for boolean trap fix. |
new Promise((...args) => npm.load({silent: true, depth: 0, ...options}, loaded(npm)(...args))); | ||
|
||
|
||
export const findLocal = npm => findScaffolds(npm)({global: false}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice: =)
[#33] Search for packages locally
Tested by installing fixed (corrected
main
) cf-package from fs:npm install ~/nkbt/cf-package
. All picked up: