1
1
import { createHighlighter } from "./createHighlighter" ;
2
2
import type { BundledLanguage } from "shiki" ;
3
3
import type { StepNameType , DataFixture } from "./types" ;
4
+ import type { ExtendedTestCaseSnapshot } from "./types" ;
4
5
5
6
import { renderClipboard , renderError } from "./renderHtml" ;
6
7
import { getDecorations } from "./helpers/decorations" ;
@@ -27,23 +28,7 @@ function createHtmlGenerator(data: DataFixture) {
27
28
const raw = data ;
28
29
const testCaseStates = {
29
30
before : data . initialState ,
30
- during : {
31
- ...(
32
- /**
33
- * Spread the document state with more lines (finalState vs initialState),
34
- * so Shiki decorations stay in bounds and don't go out of range.
35
- */
36
- data . finalState &&
37
- ( data . finalState . documentContents ?. split ( "\n" ) . length > data . initialState . documentContents ?. split ( "\n" ) . length )
38
- ? data . finalState
39
- : data . initialState
40
- ) ,
41
- ...data . ide ,
42
- finalStateMarkHelpers : {
43
- thatMark : data ?. finalState ?. thatMark ,
44
- sourceMark : data ?. finalState ?. sourceMark
45
- }
46
- } ,
31
+ during : getDuringSnapshot ( data ) ,
47
32
after : data . finalState
48
33
} ;
49
34
@@ -122,3 +107,29 @@ function createHtmlGenerator(data: DataFixture) {
122
107
123
108
return { generate, generateAll } ;
124
109
}
110
+
111
+ /**
112
+ * Selects the appropriate snapshot for the "during" step of a test case.
113
+ * If the final state has more lines than the initial state, it uses the final state as the base;
114
+ * otherwise, it uses the initial state. It then merges in IDE state and final mark helpers.
115
+ *
116
+ * @param {DataFixture } data - The test case data containing initialState, finalState, and ide info.
117
+ * @returns {ExtendedTestCaseSnapshot } The snapshot to use for the "during" step.
118
+ */
119
+ function getDuringSnapshot ( data : DataFixture ) : ExtendedTestCaseSnapshot {
120
+ // Spread the document state with more lines (finalState vs initialState),
121
+ // so Shiki decorations stay in bounds and don't go out of range.
122
+ const base =
123
+ data . finalState &&
124
+ ( data . finalState . documentContents ?. split ( "\n" ) . length > data . initialState . documentContents ?. split ( "\n" ) . length )
125
+ ? data . finalState
126
+ : data . initialState ;
127
+ return {
128
+ ...base ,
129
+ ...data . ide ,
130
+ finalStateMarkHelpers : {
131
+ thatMark : data ?. finalState ?. thatMark ,
132
+ sourceMark : data ?. finalState ?. sourceMark
133
+ }
134
+ } ;
135
+ }
0 commit comments