| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -125,7 +125,7 @@ Checks if the test did not fail the suite. If the test is not finished yet or wa | |||
| 125 | 125 | function meta(): TaskMeta | |
| 126 | 126 | ``` | |
| 127 | 127 | ||
| 128 | - Custom metadata that was attached to the test during its execution. The meta can be attached by assigning a property to the `ctx.task.meta` object during a test run: | ||
| 128 | + Custom [metadata](/advanced/metadata) that was attached to the test during its execution. The meta can be attached by assigning a property to the `ctx.task.meta` object during a test run: | ||
| 129 | 129 | ||
| 130 | 130 | ```ts {3,6} | |
| 131 | 131 | import { test } from 'vitest' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,33 @@ function state(): TestModuleState | |||
| 32 | 32 | ||
| 33 | 33 | Works the same way as [`testSuite.state()`](/advanced/api/test-suite#state), but can also return `queued` if module wasn't executed yet. | |
| 34 | 34 | ||
| 35 | + ## meta <Version>3.1.0</Version> {#meta} | ||
| 36 | + | ||
| 37 | + ```ts | ||
| 38 | + function meta(): TaskMeta | ||
| 39 | + ``` | ||
| 40 | + | ||
| 41 | + Custom [metadata](/advanced/metadata) that was attached to the module during its execution or collection. The meta can be attached by assigning a property to the `task.meta` object during a test run: | ||
| 42 | + | ||
| 43 | + ```ts {5,10} | ||
| 44 | + import { test } from 'vitest' | ||
| 45 | + | ||
| 46 | + describe('the validation works correctly', (task) => { | ||
| 47 | + // assign "decorated" during collection | ||
| 48 | + task.file.meta.decorated = false | ||
| 49 | + | ||
| 50 | + test('some test', ({ task }) => { | ||
| 51 | + // assign "decorated" during test run, it will be available | ||
| 52 | + // only in onTestCaseReady hook | ||
| 53 | + task.file.meta.decorated = false | ||
| 54 | + }) | ||
| 55 | + }) | ||
| 56 | + ``` | ||
| 57 | + | ||
| 58 | + :::tip | ||
| 59 | + If metadata was attached during collection (outside of the `test` function), then it will be available in [`onTestModuleCollected`](./reporters#ontestmodulecollected) hook in the custom reporter. | ||
| 60 | + ::: | ||
| 61 | + | ||
| 35 | 62 | ## diagnostic | |
| 36 | 63 | ||
| 37 | 64 | ```ts | |
@@ -63,5 +90,10 @@ interface ModuleDiagnostic { | |||
| 63 | 90 | * Accumulated duration of all tests and hooks in the module. | |
| 64 | 91 | */ | |
| 65 | 92 | readonly duration: number | |
| 93 | + /** | ||
| 94 | + * The amount of memory used by the module in bytes. | ||
| 95 | + * This value is only available if the test was executed with `logHeapUsage` flag. | ||
| 96 | + */ | ||
| 97 | + readonly heap: number | undefined | ||
| 66 | 98 | } | |
| 67 | 99 | ``` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -190,3 +190,30 @@ describe('collection failed', () => { | |||
| 190 | 190 | ::: warning | |
| 191 | 191 | Note that errors are serialized into simple objects: `instanceof Error` will always return `false`. | |
| 192 | 192 | ::: | |
| 193 | + | ||
| 194 | + ## meta <Version>3.1.0</Version> {#meta} | ||
| 195 | + | ||
| 196 | + ```ts | ||
| 197 | + function meta(): TaskMeta | ||
| 198 | + ``` | ||
| 199 | + | ||
| 200 | + Custom [metadata](/advanced/metadata) that was attached to the suite during its execution or collection. The meta can be attached by assigning a property to the `task.meta` object during a test run: | ||
| 201 | + | ||
| 202 | + ```ts {5,10} | ||
| 203 | + import { test } from 'vitest' | ||
| 204 | + | ||
| 205 | + describe('the validation works correctly', (task) => { | ||
| 206 | + // assign "decorated" during collection | ||
| 207 | + task.meta.decorated = false | ||
| 208 | + | ||
| 209 | + test('some test', ({ task }) => { | ||
| 210 | + // assign "decorated" during test run, it will be available | ||
| 211 | + // only in onTestCaseReady hook | ||
| 212 | + task.suite.meta.decorated = false | ||
| 213 | + }) | ||
| 214 | + }) | ||
| 215 | + ``` | ||
| 216 | + | ||
| 217 | + :::tip | ||
| 218 | + If metadata was attached during collection (outside of the `test` function), then it will be available in [`onTestModuleCollected`](./reporters#ontestmodulecollected) hook in the custom reporter. | ||
| 219 | + ::: | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -502,25 +502,7 @@ export class Vitest { | |||
| 502 | 502 | await this._testRun.start(specifications).catch(noop) | |
| 503 | 503 | ||
| 504 | 504 | for (const file of files) { | |
| 505 | - const project = this.getProjectByName(file.projectName || '') | ||
| 506 | - await this._testRun.enqueued(project, file).catch(noop) | ||
| 507 | - await this._testRun.collected(project, [file]).catch(noop) | ||
| 508 | - | ||
| 509 | - const logs: UserConsoleLog[] = [] | ||
| 510 | - | ||
| 511 | - const { packs, events } = convertTasksToEvents(file, (task) => { | ||
| 512 | - if (task.logs) { | ||
| 513 | - logs.push(...task.logs) | ||
| 514 | - } | ||
| 515 | - }) | ||
| 516 | - | ||
| 517 | - logs.sort((log1, log2) => log1.time - log2.time) | ||
| 518 | - | ||
| 519 | - for (const log of logs) { | ||
| 520 | - await this._testRun.log(log).catch(noop) | ||
| 521 | - } | ||
| 522 | - | ||
| 523 | - await this._testRun.updated(packs, events).catch(noop) | ||
| 505 | + await this._reportFileTask(file) | ||
| 524 | 506 | } | |
| 525 | 507 | ||
| 526 | 508 | if (hasFailed(files)) { | |
@@ -538,6 +520,29 @@ export class Vitest { | |||
| 538 | 520 | } | |
| 539 | 521 | } | |
| 540 | 522 | ||
| 523 | + /** @internal */ | ||
| 524 | + public async _reportFileTask(file: File): Promise<void> { | ||
| 525 | + const project = this.getProjectByName(file.projectName || '') | ||
| 526 | + await this._testRun.enqueued(project, file).catch(noop) | ||
| 527 | + await this._testRun.collected(project, [file]).catch(noop) | ||
| 528 | + | ||
| 529 | + const logs: UserConsoleLog[] = [] | ||
| 530 | + | ||
| 531 | + const { packs, events } = convertTasksToEvents(file, (task) => { | ||
| 532 | + if (task.logs) { | ||
| 533 | + logs.push(...task.logs) | ||
| 534 | + } | ||
| 535 | + }) | ||
| 536 | + | ||
| 537 | + logs.sort((log1, log2) => log1.time - log2.time) | ||
| 538 | + | ||
| 539 | + for (const log of logs) { | ||
| 540 | + await this._testRun.log(log).catch(noop) | ||
| 541 | + } | ||
| 542 | + | ||
| 543 | + await this._testRun.updated(packs, events).catch(noop) | ||
| 544 | + } | ||
| 545 | + | ||
| 541 | 546 | async collect(filters?: string[]): Promise<TestRunResult> { | |
| 542 | 547 | const files = await this.specifications.getRelevantTestSpecifications(filters) | |
| 543 | 548 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments