np
np copied to clipboard
Add more tests
I want to write more tests but testing this library is a little bit tricky. I see two options here.
- Mock the
execacalls - Checkout
sindre-playgroundand runnp
The first one doesn't really feel quite ok. Option number 2 looks much better but will create a lot of releases and noise.
Any other suggestions for adding more tests?
There is a $80.00 open bounty on this issue. Add more on Issuehunt.
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on Issuehunt to raise funds.
As I mentioned in #36 probably need a mock project, otherwise, you will always get a "Not on master branch" or such error. You could use sindre-playground but only three people could run tests unless you know a way to mock the registry.
Here is one way to do this tests... assuming you have a clean mock project at ./playground:
(note sindre-playground won't work, it doesn't have any tests).
import test from 'ava';
import execa from 'execa';
test.before(() => {
process.chdir('./playground');
process.env.DEBUG = 'np';
});
test('defaults', t => {
return execa('../cli.js', ['--dry']).then(result => {
t.regex(result.stderr, /del node_modules/);
t.regex(result.stderr, /npm \[ 'install' \]/);
t.regex(result.stderr, /npm \[ 'test' \]/);
t.regex(result.stderr, /npm \[ 'version', 'patch' \]/);
t.regex(result.stderr, /git \[ 'push', '--follow-tags' \]/);
});
});
test('yolo', t => {
return execa('../cli.js', ['--dry', '--yolo']).then(result => {
t.falsy(/del node_modules/.test(result.stderr));
t.falsy(/npm \[ 'install' \]/.test(result.stderr));
t.falsy(/npm \[ 'test' \]/.test(result.stderr));
t.regex(result.stderr, /npm \[ 'version', 'patch' \]/);
t.regex(result.stderr, /git \[ 'push', '--follow-tags' \]/);
});
});
https://github.com/Hypercubed/np/tree/tests
Might be easier to mock execa?!
I think we should start by exposing the tasks functions, and testing them individually.
For all the git stuff, you can just clone from one directory to another (origin does not have to be a remote server, it can also be path on your file system).
When it comes to the Travis and AppVeyor stuff, maybe people just need to fork sindre-playground, set up Travis and AppVeyor for their forks, and provide their own credentials for pushing to GitHub for their forks (./tests/config.json - ignored in .gitignore). We would need to create a contributing.md to explain all that. Those tests probably should just skip if users don't setup that config file.
For actually publishing to npm, I am tempted to say just mock execa for that. Although, maybe we could look into one of the sinopia forks (though none seem to be really active).
@jamestalmage Agreed.
When it comes to the Travis and AppVeyor stuff, maybe people just need to fork sindre-playground, set up Travis and AppVeyor for their forks
I can just add anyone that wants to work on it.
For actually publishing to npm, I am tempted to say just mock execa for that
Mocking is enough. We don't need to publish as that's already tested by npm.
@issuehuntfest has funded $80.00 to this issue. See it on IssueHunt
@sindresorhus I created #381, #383 and #384 (see https://github.com/sindresorhus/np/pull/354#issuecomment-475854045). I tried to avoid creating issues that have a scope that is too wide, but if you think we should change something feel free to update the issues (#383 may be a bit too big as it requires many (small) tests). As those get resolved we can create more tests issues, depending on how things go.
@sindresorhus Would you mind setting up coverage report? Like codecov.io or coveralls.
We can add nyc locally, but I don't see much value yet in codecov.io as the kinda tests we need, integration tests, will not affect code coverage much.
@sindresorhus has rewarded $72.00 to @tommy-mitchell. See it on IssueHunt
- :moneybag: Total deposit: $80.00
- :tada: Repository reward(0%): $0.00
- :wrench: Service fee(10%): $8.00