MCPcopy
hub / github.com/vitest-dev/vitest / recordArtifact

Method recordArtifact

packages/vitest/src/node/test-run.ts:58–87  ·  view source on GitHub ↗
(testId: string, artifact: Artifact)

Source from the content-addressed store, hash-verified

56 }
57
58 async recordArtifact<Artifact extends TestArtifact>(testId: string, artifact: Artifact): Promise<Artifact> {
59 const task = this.vitest.state.idMap.get(testId)
60 const entity = task && this.vitest.state.getReportedEntity(task)
61
62 assert(task && entity, `Entity must be found for task ${task?.name || testId}`)
63 assert(entity.type === 'test', `Artifacts can only be recorded on a test, instead got ${entity.type}`)
64
65 // annotations won't resolve as artifacts for backwards compatibility until next major
66 if (artifact.type === 'internal:annotation') {
67 await this.resolveTestAttachment(entity, artifact.annotation.attachment, artifact.annotation.message)
68
69 entity.task.annotations.push(artifact.annotation)
70
71 await this.vitest.report('onTestCaseAnnotate', entity, artifact.annotation)
72
73 return artifact
74 }
75
76 if (Array.isArray(artifact.attachments)) {
77 await Promise.all(
78 artifact.attachments.map(attachment => this.resolveTestAttachment(entity, attachment)),
79 )
80 }
81
82 entity.task.artifacts.push(artifact)
83
84 await this.vitest.report('onTestCaseArtifactRecord', entity, artifact)
85
86 return artifact
87 }
88
89 async updated(update: TaskResultPack[], events: TaskEventPack[]): Promise<void> {
90 this.syncUpdateStacks(update)

Callers 3

onTaskArtifactRecordFunction · 0.80
onTaskArtifactRecordFunction · 0.80
annotateTracesFunction · 0.80

Calls 6

resolveTestAttachmentMethod · 0.95
getReportedEntityMethod · 0.80
reportMethod · 0.80
allMethod · 0.80
assertFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected