fix(runner): correctly initialize suite in task#7374
fix(runner): correctly initialize suite in task#7374wmertens wants to merge 2 commits intovitest-dev:mainfrom
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
| id: '', | ||
| name, | ||
| suite: undefined!, | ||
| suite, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
this should validate if the suite is not the top-level one because it is removed later
There was a problem hiding this comment.
Any ideas on how I should test for this?
There was a problem hiding this comment.
suite should be undefined in extendTaskContext when the test is defined in top level:
test('i am a lonely test') -> // task.suite === undefined|
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 |
|
@hi-ogawa is there anything I can do in the meanwhile? |
There was a problem hiding this comment.
Okay, I don't mind a one liner change if it unblocks you even though it's technically an incomplete fix. I'll wait for another review from the team.
(An ideal fix would probably look like this #7414, but not sure when I can get back to it.)
|
I updated my PR and it's ready for review #7414. |
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
suiteto be defined at context extension time, and this is corrected in vitest.pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.