hapijs / joi

The most powerful data validation library for JS
Other
20.89k stars 1.51k forks source link

Add a script to run only specific test #3028

Closed HYOSITIVE closed 6 months ago

HYOSITIVE commented 6 months ago

Runtime

node.js

Runtime version

v18.19.1

Module version

17.12.2

Used with

standalone

Any other relevant information

No response

What problem are you trying to solve?

Currently, it seems that test npm script runs lab -t 100 -a @hapi/code -L -Y and this command runs all tests written in the project folder. This might be not necessary every time and can be inefficient in most cases because contributors are usually modifying and testing a single case (or a couple of cases). I think a new script that can select a certain test will speed up the process.

Do you have a new or modified API suggestion to solve the problem?

I think a script something like below, with grep and the keyword will be enough. I've confirmed that this works in my PR.

  1. Add a select-test in sciprts section in package.json
    "scripts": {
        "prepublishOnly": "cd browser && npm install && npm run build",
        "test": "lab -t 100 -a @hapi/code -L -Y",
        "test-cov-html": "lab -r html -o coverage.html -a @hapi/code",
        "select-test": "lab -t 100 -a @hapi/code -L -Y -g"
    },
  2. Run this command with the keyword
    
    npm run select-test "uri after encoding"

joi@17.12.2 select-test lab -t 100 -a @hapi/code -L -Y -g uri after encoding

.

1 tests complete Test duration: 131 ms Assertions count: 5 (verbosity: 5.00) Leaks: No issues Coverage: 60.11% (3060/7672)

HYOSITIVE commented 6 months ago

I submitted a quick PR for this. We might need to add a guide about how to use it, but the command itself works. Let me know how you think. Thanks!

HYOSITIVE commented 6 months ago

As I mentioned in the PR, this changes are not necessary.