I need to run a slightly different set of tests before publishing
Is this possible?
For example, instead of np running 'yarn test', I want it to run 'yarn test-npm'.
How can I specify this (without changing the definition of "test") ?
I think this sounds more like a use-case specific change, rather than a functional one with np.
Could you clarify why you want to run test-npm instead of test? Looking through the np docs, the easiest solution for you would be to run np with no-tests option and define your custom test using the npm lifecycle hooks defined in the documentation.
Thanks for the reply. I have already done what you suggest above, disabling np's tests and then using a lifecycle hook, which does work, but feels a bit messy. Just to explain, when I publish to npm, I want to run tests on the exact code for the release (so the file(s) _after_ packing the archive for npm), and this is not, for obvious reasons, my default test in package.json.
Ah, makes sense.
I don't think that at the moment we are going to have any ways to configure custom tests. Let's wait and see if its something which the community wants before we think about implementing this.
Ok, makes sense. For documentation's sake, my current np command for the project (in beta) is: np --tag beta prerelease
I was imagining an option like like: np --test-script npm.test --tag beta prerelease
I would also find this useful. We have two test commands in our package.json:
"scripts": {
"test": "jest --watch",
"ci:test": "jest",
...
}
Our default "test" command is used for easily development - watches files and runs only tests related to any files you change. And the simpler, "run all tests once" option, is under "ci:test".
Running np currently hangs on the tests, and I always have to make sure I run the tests myself first, and then run np --no-tests, which is NOT ideal. It would be really nice if I could provide a different test command to run.
@sindresorhus , what do you think about this feature? We would have to run npm run custom-test instead of the default npm test command.
Sounds like there are some valid use-cases for this. A good PR would be welcome. The PR should also include docs that describe the use-cases mentioned in this thread. This is useful for users to make them realize why they would want to use such an option.
Just a heads up for anyone looking into this, I will be taking this up.
Most helpful comment
I would also find this useful. We have two test commands in our package.json:
Our default
"test"command is used for easily development - watches files and runs only tests related to any files you change. And the simpler, "run all tests once" option, is under "ci:test".Running
npcurrently hangs on the tests, and I always have to make sure I run the tests myself first, and then runnp --no-tests, which is NOT ideal. It would be really nice if I could provide a different test command to run.