-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix(runner): correctly initialize suite in task #7374
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
55a96d5
to
f2bfd0d
Compare
I can't really figure out why the test fails. It seems that the fnMap in the runner gets re-inited, somehow that module is being imported twice. But while I was creating it, the test was passing. |
I haven't fully understood the logic around here, but potentially this vitest/packages/runner/src/collect.ts Lines 92 to 98 in 3830d61
|
@hi-ogawa so when I just initialize the task with the suite in suite.ts, everything works in my repo. It only removes the suite if the id is '', which is fine for my use case. I suppose the test.only errors can be disabled for linting, but linting seems to pass? The problem is that somehow the runner support |
@hi-ogawa oh disregard sorry, I now found the actual error you explained https://github.com/vitest-dev/vitest/actions/runs/13021120069/job/36321826300?pr=7374#step:8:226 |
this adds a test with a custom runner that allows you to wait for other tests, even when they weren't scheduled. It requires `suite` to be defined at context extension time.
f2bfd0d
to
bdd9a7a
Compare
@@ -304,7 +304,7 @@ function createSuiteCollector( | |||
const task: Test = { | |||
id: '', | |||
name, | |||
suite: undefined!, | |||
suite, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to #7374 (comment), technically we want to keep this undefined
for top-level task? (in your example, "supports passing options"
test)
Otherwise, context.task.suite
is defined during extendTaskContext
, but becomes undefined
during test execution for example.
Does this support getting ancestor like vitest/packages/runner/src/suite.ts Lines 415 to 417 in fbbd21d
|
@hi-ogawa I didn't look into the suite logic really. What matters is that the extendTaskContext will get the same suite name as runTask. I couldn't easily find where the suite Maybe the suite could be set in the task only if suite.name is defined? |
I think there's a way to properly fix the initialization, but it might require more careful considerations (maybe something like this #7414). In the mean time, I don't mind having your use case fixed with a simple change and follow up separately. I'll check with team. |
@wmertens Btw, do you have your custom runner somewhere in open source? It would be nice to know more context and concrete code if it's available. |
@hi-ogawa Well, it's fully open-sourced in this PR now ;) we use it internally, because our e2e test suite does expensive initializations and we want to reuse them in subsequent tests. For example, suppose you want to test an S3 bucket, filling it with 1000 files for various things, this runner allows you to do it in stages, skipping stages you're not testing right now etc. I'd be happy to help make this part of the actual API as well. Another API approach would be to export a import {it, result} from 'vitest'
const init = it('should initialize', async () => {
const stuff = await makeStuff()
expect(stuff.foo).toEqual(500)
return stuff
})
it('should bar', async () => {
const stuff = await result(init)
await expect(stuff.doThing()).resolves.toBeTruthy()
}) you could also allow |
Description
this adds a test with a custom runner that allows you to wait for other tests, even when they weren't scheduled. It requires
suite
to be defined at context extension time, and this is corrected in vitest.pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.