Skip to content
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

Specify test command to run #543

Closed
dhowe opened this issue Jun 12, 2020 · 8 comments · Fixed by #557
Closed

Specify test command to run #543

dhowe opened this issue Jun 12, 2020 · 8 comments · Fixed by #557

Comments

@dhowe
Copy link

dhowe commented Jun 12, 2020

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") ?

@dopecodez
Copy link
Collaborator

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.

@dhowe
Copy link
Author

dhowe commented Jul 1, 2020

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.

@dopecodez
Copy link
Collaborator

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.

@dhowe
Copy link
Author

dhowe commented Jul 1, 2020

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

@kyrstenkelly
Copy link

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.

@dopecodez
Copy link
Collaborator

@sindresorhus , what do you think about this feature? We would have to run npm run custom-test instead of the default npm test command.

@sindresorhus
Copy link
Owner

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.

@dopecodez
Copy link
Collaborator

Just a heads up for anyone looking into this, I will be taking this up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants