np icon indicating copy to clipboard operation
np copied to clipboard

Add more tests

Open SamVerschueren opened this issue 9 years ago • 10 comments

Issuehunt badges

I want to write more tests but testing this library is a little bit tricky. I see two options here.

  1. Mock the execa calls
  2. Checkout sindre-playground and run np

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.

SamVerschueren avatar Jun 03 '16 07:06 SamVerschueren

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.

Hypercubed avatar Jun 16 '16 08:06 Hypercubed

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' \]/);
    });
});

Hypercubed avatar Jun 16 '16 09:06 Hypercubed

https://github.com/Hypercubed/np/tree/tests

Hypercubed avatar Jun 16 '16 09:06 Hypercubed

Might be easier to mock execa?!

Hypercubed avatar Jun 16 '16 09:06 Hypercubed

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 avatar Jul 09 '16 06:07 jamestalmage

@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.

sindresorhus avatar Jul 10 '16 19:07 sindresorhus

@issuehuntfest has funded $80.00 to this issue. See it on IssueHunt

IssueHuntBot avatar Dec 22 '18 02:12 IssueHuntBot

@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.

itaisteinherz avatar Apr 05 '19 19:04 itaisteinherz

@sindresorhus Would you mind setting up coverage report? Like codecov.io or coveralls.

chinesedfan avatar Nov 29 '19 03:11 chinesedfan

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 avatar Nov 29 '19 03:11 sindresorhus

@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

issuehunt-oss[bot] avatar Sep 02 '23 08:09 issuehunt-oss[bot]