@@ -54,10 +54,56 @@ test("captures a rendered element with the Argos Vitest SDK metadata", async ()
5454 expect ( attachments . length ) . toBe ( 2 ) ;
5555
5656 // The whole point of the package: the screenshot is attributed to this SDK
57- // and to the Playwright provider (proves setMetadataConfig propagated).
57+ // and to Vitest as the automation library (proves setMetadataConfig
58+ // propagated).
5859 const metadata = await readMetadata ( attachments ) ;
5960 expect ( metadata . sdk . name ) . toBe ( "@argos-ci/vitest" ) ;
60- expect ( metadata . automationLibrary . name ) . toBe ( "@vitest/browser-playwright" ) ;
61+ expect ( metadata . automationLibrary . name ) . toBe ( "vitest" ) ;
62+ } ) ;
63+
64+ test ( "attaches the Vitest test metadata to the screenshot" , async ( ) => {
65+ mount ( `<div style="padding:20px">Metadata</div>` ) ;
66+ const attachments = await argosScreenshot ( "with-metadata" ) ;
67+ const metadata = await readMetadata ( attachments ) ;
68+
69+ // Test metadata (injected from the Vitest test context, since Playwright's
70+ // own testInfo is absent in a Vitest run).
71+ expect ( metadata . test . id ) . toBeTruthy ( ) ;
72+ expect ( metadata . test . title ) . toBe (
73+ "attaches the Vitest test metadata to the screenshot" ,
74+ ) ;
75+ expect ( metadata . test . titlePath ) . toEqual ( [
76+ "e2e/screenshot.test.ts" ,
77+ "attaches the Vitest test metadata to the screenshot" ,
78+ ] ) ;
79+ // `location.file` is resolved relative to the git repository on the Node side.
80+ expect ( metadata . test . location . file ) . toContain (
81+ "packages/vitest/e2e/screenshot.test.ts" ,
82+ ) ;
83+ // `includeTaskLocation` (enabled by the plugin) provides real line/column.
84+ expect ( metadata . test . location . line ) . toBeGreaterThan ( 0 ) ;
85+ expect ( metadata . test . location . column ) . toBeGreaterThan ( 0 ) ;
86+
87+ // Browser-derived metadata comes for free through the Playwright SDK.
88+ expect ( metadata . browser . name ) . toBe ( "chromium" ) ;
89+ expect ( typeof metadata . url ) . toBe ( "string" ) ;
90+ expect ( [ "light" , "dark" ] ) . toContain ( metadata . colorScheme ) ;
91+ expect ( metadata . mediaType ) . toBe ( "screen" ) ;
92+ } ) ;
93+
94+ test ( "auto-names a screenshot from the current test" , async ( ) => {
95+ mount (
96+ `<div style="padding:40px;background:#22c55e;color:#fff;font:700 32px sans-serif;">Auto</div>` ,
97+ ) ;
98+ // No name: it is derived from the current test + a per-test counter, so the
99+ // file lands under the test title with a ` 1` suffix.
100+ const attachments = await argosScreenshot ( ) ;
101+ expect ( attachments . length ) . toBe ( 2 ) ;
102+
103+ const screenshot = attachments . find ( ( a ) => a . path . endsWith ( ".png" ) ) ;
104+ expect ( screenshot ) . toBeDefined ( ) ;
105+ expect ( screenshot ! . path ) . toContain ( "auto-names a screenshot" ) ;
106+ expect ( screenshot ! . path ) . toContain ( " 1.png" ) ;
61107} ) ;
62108
63109test ( "captures a specific element via a selector" , async ( ) => {
@@ -115,15 +161,20 @@ test("grows the iframe to capture content wider than the viewport", async () =>
115161test ( "writes a value snapshot that the reporter can upload" , async ( ) => {
116162 // `argosSnapshot` works without a browser, but here we exercise the browser
117163 // RPC path: the value is serialized in the browser, written on the node side.
118- const attachments = await argosSnapshot ( "payload" , {
119- id : 1 ,
120- name : "Argos" ,
121- tags : [ "a" , "b" ] ,
122- } ) ;
164+ const attachments = await argosSnapshot (
165+ {
166+ id : 1 ,
167+ name : "Argos" ,
168+ tags : [ "a" , "b" ] ,
169+ } ,
170+ { name : "payload" } ,
171+ ) ;
123172 // The snapshot file + its metadata attachment.
124173 expect ( attachments . length ) . toBe ( 2 ) ;
125174
126- const snapshot = attachments . find ( ( a ) => a . path . endsWith ( ".snapshot.txt" ) ) ;
175+ const snapshot = attachments . find ( ( a ) =>
176+ a . path . endsWith ( "payload.snapshot.txt" ) ,
177+ ) ;
127178 expect ( snapshot ) . toBeDefined ( ) ;
128179 // The value is serialized with pretty-format, ready for Argos to diff.
129180 const content = await server . commands . readFile ( snapshot ! . path ) ;
@@ -135,8 +186,35 @@ test("writes a value snapshot that the reporter can upload", async () => {
135186 expect ( parsed . sdk . name ) . toBe ( "@argos-ci/vitest" ) ;
136187} ) ;
137188
189+ test ( "attaches the Vitest test metadata to the snapshot" , async ( ) => {
190+ const attachments = await argosSnapshot (
191+ { hello : "world" } ,
192+ { name : "snapshot-metadata" } ,
193+ ) ;
194+ const metadata = attachments . find ( ( a ) => a . path . endsWith ( ".argos.json" ) ) ;
195+ expect ( metadata ) . toBeDefined ( ) ;
196+ const parsed = JSON . parse ( await server . commands . readFile ( metadata ! . path ) ) ;
197+
198+ // Snapshots have no browser, so Vitest is the automation library, but they
199+ // still carry the test metadata.
200+ expect ( parsed . automationLibrary . name ) . toBe ( "vitest" ) ;
201+ expect ( parsed . test . id ) . toBeTruthy ( ) ;
202+ expect ( parsed . test . title ) . toBe (
203+ "attaches the Vitest test metadata to the snapshot" ,
204+ ) ;
205+ expect ( parsed . test . titlePath ) . toEqual ( [
206+ "e2e/screenshot.test.ts" ,
207+ "attaches the Vitest test metadata to the snapshot" ,
208+ ] ) ;
209+ // `location.file` is resolved relative to the git repository on the Node side.
210+ expect ( parsed . test . location . file ) . toContain (
211+ "packages/vitest/e2e/screenshot.test.ts" ,
212+ ) ;
213+ } ) ;
214+
138215test ( "writes a snapshot with a custom extension" , async ( ) => {
139- const attachments = await argosSnapshot ( "config" , '{"enabled":true}' , {
216+ const attachments = await argosSnapshot ( '{"enabled":true}' , {
217+ name : "config" ,
140218 extension : ".json" ,
141219 } ) ;
142220 const snapshot = attachments . find ( ( a ) => a . path . endsWith ( ".snapshot.json" ) ) ;
0 commit comments