-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: Add meta to TestOptions
#8405
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -485,6 +485,10 @@ export interface TestOptions { | |||
| * Whether the test is expected to fail. If it does, the test will pass, otherwise it will fail. | ||||
| */ | ||||
| fails?: boolean | ||||
| /** | ||||
| * Custom metadata for the task. This will be merged with any meta property defined in the test. | ||||
| */ | ||||
| meta?: Record<string, unknown> | ||||
|
rebasecase marked this conversation as resolved.
Outdated
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some places it is
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. e.g. vitest/packages/vite-node/src/types.ts Line 99 in c1ac15c
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what to do about this. Setting I don't understand complex typing much yet. |
||||
| } | ||||
|
|
||||
| interface ExtendedAPI<ExtraContext> { | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { beforeEach, describe, expect, test } from 'vitest' | ||
|
|
||
| describe('TestOptions meta property functionality', { meta: { suiteLevel: 'test-suite', priority: 'medium' } }, () => { | ||
| let beforeEachMeta: Record<string, unknown> | ||
|
|
||
| beforeEach(({ task }) => { | ||
| beforeEachMeta = { ...task.meta } | ||
| }) | ||
|
|
||
| test('should merge suite and test meta properties', { meta: { testLevel: 'individual-test', priority: 'high' } }, ({ task }) => { | ||
| // Test should have both suite and test meta | ||
| expect(task.meta).toMatchObject({ | ||
| suiteLevel: 'test-suite', | ||
| testLevel: 'individual-test', | ||
| priority: 'high', // test meta should override suite meta | ||
| }) | ||
|
|
||
| // beforeEach should have access to merged meta | ||
| expect(beforeEachMeta).toMatchObject({ | ||
| suiteLevel: 'test-suite', | ||
| testLevel: 'individual-test', | ||
| priority: 'high', | ||
| }) | ||
| }) | ||
|
|
||
| test('should inherit suite meta when no test meta provided', ({ task }) => { | ||
| // Test should only have suite meta | ||
| expect(task.meta).toMatchObject({ | ||
| suiteLevel: 'test-suite', | ||
| priority: 'medium', | ||
| }) | ||
|
|
||
| // beforeEach should have access to suite meta | ||
| expect(beforeEachMeta).toMatchObject({ | ||
| suiteLevel: 'test-suite', | ||
| priority: 'medium', | ||
| }) | ||
| }) | ||
|
|
||
| test('should allow adding meta at runtime', { meta: { testLevel: 'runtime-test' } }, ({ task }) => { | ||
| // Add meta at runtime | ||
| (task.meta as any).runtimeAdded = 'added-during-test' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a local type instead of assigning
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With meta now being
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wrong 😿 |
||
|
|
||
| expect(task.meta).toMatchObject({ | ||
| suiteLevel: 'test-suite', | ||
| testLevel: 'runtime-test', | ||
| priority: 'medium', | ||
| runtimeAdded: 'added-during-test', | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| describe('Suite without meta', () => { | ||
| let beforeEachMeta: Record<string, unknown> | ||
|
|
||
| beforeEach(({ task }) => { | ||
| beforeEachMeta = { ...task.meta } | ||
| }) | ||
|
|
||
| test('should only have test meta when suite has no meta', { meta: { testOnly: 'test-meta' } }, ({ task }) => { | ||
| expect(task.meta).toMatchObject({ | ||
| testOnly: 'test-meta', | ||
| }) | ||
|
|
||
| expect(beforeEachMeta).toMatchObject({ | ||
| testOnly: 'test-meta', | ||
| }) | ||
| }) | ||
| }) | ||
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.
Let's keep the meta with a null prototype. Just assign
options.metato meta collected withcollectAncestorMeta: