1
- import type { PositionPlainObject } from "@cursorless/common" ;
2
- import type { TestCaseFixture , TestCaseSnapshot } from "@cursorless/common " ;
3
- import { generateHtml } from "./generateHtml " ;
1
+ import type { TargetPlainObject , TestCaseFixture , TestCaseSnapshot } from "@cursorless/common" ;
2
+ import { generateHtml } from "./generateHtml.js " ;
3
+ import type { BundledLanguage } from "shiki " ;
4
4
5
- async function safeGenerateHtml (
6
- ...args : [ stateName : string , ...rest : Parameters < typeof generateHtml > ]
7
- ) {
8
- const [ stateName , state , languageId ] = args ;
5
+ async function safeGenerateHtml ( {
6
+ stateName,
7
+ state,
8
+ languageId,
9
+ command,
10
+ ide,
11
+ thatMarkFinalState
12
+ } : {
13
+ stateName : string ;
14
+ state : TestCaseSnapshot ;
15
+ languageId : BundledLanguage ;
16
+ command ?: any ; // Replace `any` with the appropriate type if known
17
+ ide ?: any ; // Replace `any` with the appropriate type if known
18
+ thatMarkFinalState ?: TargetPlainObject
19
+ } ) {
20
+ console . log ( "✨" + stateName + "✨" ) ;
9
21
try {
10
- return await generateHtml ( state , languageId ) ;
22
+ const genObj = { stateName, state, languageId, command, ide }
23
+ return await generateHtml ( genObj ) ;
11
24
} catch ( e ) {
12
25
console . error ( "error in state" , stateName , e ) ;
13
26
console . error ( JSON . stringify ( state , null , 2 ) ) ;
@@ -17,18 +30,21 @@ async function safeGenerateHtml(
17
30
18
31
interface loadFixtureProps extends TestCaseFixture {
19
32
filename : string ;
33
+ languageId : BundledLanguage ;
34
+ initialState : TestCaseSnapshot ;
35
+ finalState : TestCaseSnapshot ;
20
36
}
21
37
22
38
export async function loadFixture ( data : loadFixtureProps ) {
23
39
try {
24
- const during = await getDuring ( data ) ;
25
-
26
40
const before = await getBefore ( {
27
41
stateName : "initialState" ,
28
42
state : data . initialState ,
29
43
languageId : data . languageId ,
30
44
} ) ;
31
45
46
+ const during = await getDuring ( data ) ;
47
+
32
48
const after = await getAfter ( {
33
49
stateName : "finalState" ,
34
50
state : data . finalState ,
@@ -50,57 +66,50 @@ export async function loadFixture(data: loadFixtureProps) {
50
66
}
51
67
}
52
68
53
- async function getBefore ( {
69
+ type Foo = TestCaseSnapshot & TargetPlainObject ;
70
+
71
+ async function getAfter ( {
54
72
stateName,
55
73
state,
56
74
languageId,
57
75
} : {
58
76
stateName : string ;
59
- state : TestCaseSnapshot ;
60
- languageId : string ;
77
+ state : Foo ;
78
+ languageId : BundledLanguage ;
61
79
} ) {
62
- return await safeGenerateHtml ( stateName , state , languageId ) ;
80
+ if ( ! state ) {
81
+ throw new Error ( "finalState is undefined" ) ;
82
+ }
83
+ return await safeGenerateHtml ( { stateName, state, languageId } ) ;
63
84
}
64
85
65
- async function getAfter ( {
86
+ type DataFixture = Partial < TestCaseFixture & TargetPlainObject >
87
+
88
+ async function getDuring ( data : DataFixture ) {
89
+ const { command, ide } = data
90
+ const stateName = "middleState"
91
+ const state = data . initialState
92
+ const languageId = data . languageId as BundledLanguage
93
+ const { thatMark : thatMarkFinalState } = data . finalState
94
+ const genObj : TestCaseSnapshot & typeof thatMarkFinalState = { stateName, state, languageId, raw : data }
95
+ if ( command ) {
96
+ genObj . command = command
97
+ }
98
+ if ( ide ) {
99
+ genObj . ide = ide
100
+ }
101
+
102
+ return await generateHtml ( genObj ) ;
103
+ }
104
+
105
+ async function getBefore ( {
66
106
stateName,
67
107
state,
68
108
languageId,
69
109
} : {
70
110
stateName : string ;
71
111
state : TestCaseSnapshot ;
72
- languageId : string ;
112
+ languageId : BundledLanguage ;
73
113
} ) {
74
- // todo, handle clipboard
75
- return await safeGenerateHtml ( stateName , state , languageId ) ;
76
- }
77
-
78
- async function getDuring ( data : TestCaseFixture ) {
79
- if ( ! ! data . ide && data . ide . flashes ) {
80
- return await safeGenerateHtml (
81
- "flashes" ,
82
- {
83
- ...data . initialState ,
84
- flashes : data . ide . flashes . map (
85
- ( props : {
86
- name : string ;
87
- type : string ;
88
- start : PositionPlainObject ;
89
- end : PositionPlainObject ;
90
- } ) => {
91
- const { name, type, start, end } = props ;
92
- console . log ( "🦄" , props ) ;
93
- return {
94
- name,
95
- type,
96
- anchor : start ,
97
- active : end ,
98
- } ;
99
- } ,
100
- ) ,
101
- } ,
102
- data . languageId ,
103
- ) ;
104
- }
105
- return null ;
114
+ return await safeGenerateHtml ( { stateName, state, languageId } ) ;
106
115
}
0 commit comments