@@ -5,6 +5,7 @@ import { syncBuiltinESMExports } from "node:module";
55import { tmpdir } from "node:os" ;
66import path from "node:path" ;
77import { fileURLToPath } from "node:url" ;
8+ import { stripVTControlCharacters } from "node:util" ;
89import { afterEach , describe , expect , it , vi } from "vitest" ;
910import { refitTestTimings , type CiTimingRun } from "../../scripts/lib/ci-test-timings-refit.mts" ;
1011import {
@@ -69,6 +70,86 @@ it("rejects non-plain timing objects even when their fields are valid", () => {
6970} ) ;
7071
7172describe ( "CI test timing refit" , ( ) => {
73+ it ( "ingests the native UI reporters without losing case progress or suite hooks" , async ( ) => {
74+ const { default : config } = await import ( "../vitest/vitest.ui-e2e.config.ts" ) ;
75+ const root = fileURLToPath ( new URL ( "../../" , import . meta. url ) ) ;
76+ const artifacts = path . join ( root , ".artifacts" ) ;
77+ fs . mkdirSync ( artifacts , { recursive : true } ) ;
78+ const directory = mkdtempSync ( path . join ( artifacts , "ci-ui-timings-" ) ) ;
79+ const files = [ "ui/src/e2e/first.e2e.test.ts" , "ui/src/e2e/second.e2e.test.ts" ] ;
80+ const configFile = path . join ( directory , "vitest.config.mjs" ) ;
81+ try {
82+ for ( const file of files ) {
83+ fs . mkdirSync ( path . dirname ( path . join ( directory , file ) ) , { recursive : true } ) ;
84+ writeFileSync (
85+ path . join ( directory , file ) ,
86+ `import { setTimeout } from "node:timers/promises";
87+ import { beforeAll, afterAll, it } from "vitest";
88+ beforeAll(() => setTimeout(50));
89+ afterAll(() => setTimeout(50));
90+ it("reports completed case progress", () => {});
91+ it.skip("retains skipped coverage", () => {});
92+ it.todo("retains todo coverage");
93+ ` ,
94+ ) ;
95+ }
96+ writeFileSync (
97+ configFile ,
98+ `export default ${ JSON . stringify ( {
99+ root : directory ,
100+ test : {
101+ name : "ui-e2e" ,
102+ include : files ,
103+ reporters : config . test ?. reporters ,
104+ fileParallelism : false ,
105+ } ,
106+ } ) } ;\n`,
107+ ) ;
108+ const runs = [ 1 , 2 ] . map ( ( id ) => {
109+ const result = spawnSync (
110+ process . execPath ,
111+ [ "scripts/run-vitest.mjs" , "run" , "--config" , configFile , "--configLoader" , "runner" ] ,
112+ {
113+ cwd : root ,
114+ encoding : "utf8" ,
115+ timeout : 30_000 ,
116+ env : { ...process . env , GITHUB_STEP_SUMMARY : path . join ( directory , "summary.md" ) } ,
117+ } ,
118+ ) ;
119+ expect ( result . status , result . stderr || result . stdout ) . toBe ( 0 ) ;
120+ const text = stripVTControlCharacters ( result . stdout ) ;
121+ expect ( text ) . toContain ( "> reports completed case progress" ) ;
122+ const nativeFileDurations = [ ...text . matchAll ( / \. e 2 e \. t e s t \. t s [ ^ \n ] * \) \s + ( \d + ) m s / gu) ] ;
123+ expect ( nativeFileDurations , text ) . toHaveLength ( files . length ) ;
124+ // Native file time includes both suite hooks, unlike the case-only verbose rows.
125+ expect ( nativeFileDurations . every ( ( match ) => Number ( match [ 1 ] ) >= 90 ) ) . toBe ( true ) ;
126+ return timingRun ( id , [ { kind : "uiE2e" , text : result . stdout } ] ) ;
127+ } ) ;
128+ expect ( refitTestTimings ( runs ) . timings . uiE2e . fileSeconds ) . toEqual (
129+ Object . fromEntries ( files . map ( ( file ) => [ file , 1 ] ) ) ,
130+ ) ;
131+ } finally {
132+ rmSync ( directory , { recursive : true , force : true } ) ;
133+ }
134+ } ) ;
135+
136+ it ( "accepts completed passed file summaries once, excluding failed, skipped and unfinished files" , ( ) => {
137+ const log = [
138+ `✓ |ui-e2e| ${ measuredFile } (3 tests | 1 skipped | 1 todo) 4000ms` ,
139+ `✓ \u001b[32mui-e2e\u001b[0m ${ measuredFile } (3 tests | 1 skipped | 1 todo) 4000ms` ,
140+ "❯ ui-e2e ui/src/e2e/failed.e2e.test.ts (1 test | 1 failed) 20s" ,
141+ "❯ ui-e2e ui/src/e2e/timeout.e2e.test.ts (0 test) 30s" ,
142+ "↓ ui-e2e ui/src/e2e/skipped.e2e.test.ts (1 test | 1 skipped) 0ms" ,
143+ "Duration 56s (transform 1s, setup 1s, tests 54s, environment 0ms)" ,
144+ "✓ ui-e2e ui/src/e2e/unfinished.e2e.test.ts (1 test) 5s" ,
145+ ] . join ( "\n" ) ;
146+ const runs = [ 1 , 2 ] . map ( ( id ) => timingRun ( id , [ { kind : "uiE2e" , text : log } ] ) ) ;
147+ expect ( refitTestTimings ( runs ) . timings . uiE2e ) . toEqual ( {
148+ fileSeconds : { [ measuredFile ] : 4 } ,
149+ perFileOverheadSeconds : 2 ,
150+ } ) ;
151+ } ) ;
152+
72153 it ( "records per-file medians without outliers or one-run weights and measures excluded overhead" , ( ) => {
73154 const pageFile = "ui/src/pages/settings/measured.e2e.test.ts" ;
74155 const singleFile = "ui/src/e2e/single.e2e.test.ts" ;
0 commit comments