-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
Improve Programmatic Usage #113
Comments
I have a really ugly workaround, where I insert a fake suite before calling the others: const run = async () => {
suite('hack').run()
for (const scenario of scenarios) { This still prints out the |
Hey, so First, you need to use Then here is your updated // runner.js
import * as assert from 'uvu/assert'
const scenarios = [
'./tests/foo.js',
'./tests/bar.js',
]
const run = async () => {
globalThis.UVU_DEFER = 1
const uvu = await import('uvu')
for (const scenario of scenarios) {
const test = uvu.suite(scenario)
// manually replicate uvu global state
const count = globalThis.UVU_QUEUE.push([scenario])
globalThis.UVU_INDEX = count - 1
const run = await import(scenario)
run.default(test, assert)
test.run()
}
return uvu.exec()
}
run()
.then(() => { console.log('done') })
.catch(error => { console.error('error', error) }) This gives you the following output: If you don't want to have the const run = async () => {
globalThis.UVU_DEFER = 1
globalThis.UVU_QUEUE = [[null]] // not a typo
const uvu = await import('uvu')
for (const scenario of scenarios) {
const test = uvu.suite(scenario)
const run = await import(scenario)
run.default(test, assert)
test.run()
}
return uvu.exec()
} Producing this: |
Ah, that's great, thanks! I actually did exactly what you had, except I set the I think this will work well enough for me. It's kind of reaching into the internals more than I'd like of course, but it'll be fine until there's an API sorted out. (Note: it's actually working on |
Cool! I'll have to go back & see what the actual differences in Will leave this issue open for now, but track it a bit differently. Thanks |
Just a note to myself / whoever else stumbles across this: if you don't bail (i.e. const run = async () => {
// ... any of the forms @lukeed wrote
return uvu.exec()
}
// ... where you call `run`
await run()
// after the promise resolves
if (process.exitCode) {
// one or more tests failed
} else {
// all tests passed
} |
Just an update: I'm working on this now, which is effectively a rewrite of uvu. It will allow you to call a new |
Could we have a way to feed uvu with tests? so that we can use vite to provide uvu with only the files that changed. |
Another option I figured out for running import { parse } from 'uvu/parse';
import { run } from 'uvu/run';
const runUvu = async () => {
const uvuCtx = await parse(join(process.cwd(), 'test'), /\.spec\.ts$/, {
ignore: [/(index)/],
});
await run(uvuCtx.suites, { bail: false });
}; This is pretty much mimicking what the CLI does. Works out well as you can see here |
@lukeed Any updates on this ☝️ ? I use uvu to test Cloudflare workers with Miniflare and I need a way to tell if the suite runs successfully or not so that the worker can return a fetch response accordingly. The setup is similar to https://github.com/cloudflare/miniflare-typescript-esbuild-jest. Thanks. |
What I did
I've got a bunch of tests that I want to run in a specific order, e.g. "create the user" -> "log in as user" -> "log out as user" (where each of those has a bunch of tests).
Each of those tests is in its own file, then I created a test runner so I can manage state easier.
The test files all export a default function that takes
test
(the suite) andassert
(for convenience):The custom test runner sets up state, and manually controls the suite ordering:
Then I execute the runner simply
node ./runner.js
What I expect
When I execute the runner, normal
uvu
output should list each suite:What actually happens
If I try reordering the tests, they are all run in order, except always the first one is skipped and prints this instead:
Other information
The text was updated successfully, but these errors were encountered: