lukeed/uvu

--grep

Rich-Harris opened this issue · 4 comments

I find this flag in mocha to be incredibly useful:

npm test -- -g "some test description"

What do you think about having something similar in uvu?

hey, does this really add something that suite.only and/or node path/to/test.js doesnt satisfy? IIRC you can't single out a mocha test file directly like you can with uvu, which may be the reason for the flag?

node path/to/test.js isn't granular enough. suite.only is close, but less convenient — you have to find the failing test in your codebase and modify the source code, and remember not to accidentally check test.only in (which I have done more times than I can count). Definitely falls under 'nice to have' rather than 'essential', but it is nice to have

I agree with @Rich-Harris, and in fact just lost some time because I assumed suite.only would allow me to specify the test to run (I didn't realise you have to modify the test case itself with .only). I feel stupid now but think possibly an easy mistake to make for people new to uvu. This is what I wrote:

import * as all_suites from "./src/all_tests"
import { Command } from "commander"

const program = new Command()
program.option("-s, --suite <suite>", "suite to run").option("-t, --test <test>", "test to run <test>")
program.parse(process.argv)

const { suite, test } = program.opts()

for (const [name, runner] of Object.entries(all_suites)) {
    if (!suite || suite === name) {
        if (test) {
            runner.only(test, ctx => {
                console.log("CTX", ctx)
                return Promise.resolve()
            })
        }
        runner.run()
    }
}

Obviously the above makes no sense, but hopefully you can see what I was trying to achieve! Perhaps an optional filter predicate passed to the run method would work?

Thanks

Having written all the above, adding .only is not a big deal for me...