@@ -18,23 +18,21 @@ import {
18
18
TestCaseFixtureLegacy ,
19
19
TestCaseSnapshot ,
20
20
TextEditor ,
21
- TokenHat ,
22
21
clientSupportsFallback ,
23
- extractTargetedMarks ,
24
- marksToPlainObject ,
22
+ loadFixture ,
25
23
omitByDeep ,
26
- plainObjectToRange ,
27
24
rangeToPlainObject ,
28
25
serializeTestFixture ,
26
+ serializedMarksToTokenHats ,
29
27
shouldUpdateFixtures ,
30
28
splitKey ,
31
29
spyIDERecordedValuesToPlainObject ,
32
30
storedTargetKeys ,
33
31
} from "@cursorless/common" ;
34
32
import { assert } from "chai" ;
35
- import * as yaml from "js-yaml" ;
36
33
import { isUndefined } from "lodash" ;
37
34
import { promises as fsp } from "node:fs" ;
35
+ import { getResultStateForComparison } from "./getResultStateForComparison" ;
38
36
39
37
function createPosition ( position : PositionPlainObject ) {
40
38
return new Position ( position . line , position . character ) ;
@@ -123,9 +121,7 @@ export async function runRecordedTest({
123
121
testHelpers,
124
122
runCursorlessCommand,
125
123
} : RunRecordedTestOpts ) {
126
- const buffer = await fsp . readFile ( path ) ;
127
- const fixture = yaml . load ( buffer . toString ( ) ) as TestCaseFixtureLegacy ;
128
- const excludeFields : ExcludableSnapshotField [ ] = [ ] ;
124
+ const fixture = await loadFixture ( path ) ;
129
125
130
126
// FIXME The snapshot gets messed up with timing issues when running the recorded tests
131
127
// "Couldn't find token default.a"
@@ -162,7 +158,10 @@ export async function runRecordedTest({
162
158
163
159
// Ensure that the expected hats are present
164
160
await hatTokenMap . allocateHats (
165
- getTokenHats ( fixture . initialState . marks , spyIde . activeTextEditor ! ) ,
161
+ serializedMarksToTokenHats (
162
+ fixture . initialState . marks ,
163
+ spyIde . activeTextEditor ! ,
164
+ ) ,
166
165
) ;
167
166
168
167
const readableHatMap = await hatTokenMap . getReadableMap ( usePrePhraseSnapshot ) ;
@@ -217,35 +216,11 @@ export async function runRecordedTest({
217
216
await sleepWithBackoff ( fixture . postCommandSleepTimeMs ) ;
218
217
}
219
218
220
- const marks =
221
- fixture . finalState ?. marks == null
222
- ? undefined
223
- : marksToPlainObject (
224
- extractTargetedMarks (
225
- Object . keys ( fixture . finalState . marks ) ,
226
- readableHatMap ,
227
- ) ,
228
- ) ;
229
-
230
- if ( fixture . finalState ?. clipboard == null ) {
231
- excludeFields . push ( "clipboard" ) ;
232
- }
233
-
234
- for ( const storedTargetKey of storedTargetKeys ) {
235
- const key = `${ storedTargetKey } Mark` as const ;
236
- if ( fixture . finalState ?. [ key ] == null ) {
237
- excludeFields . push ( key ) ;
238
- }
239
- }
240
-
241
- // FIXME Visible ranges are not asserted, see:
242
- // https://github.com/cursorless-dev/cursorless/issues/160
243
- const { visibleRanges, ...resultState } = await takeSnapshot (
244
- excludeFields ,
245
- [ ] ,
246
- spyIde . activeTextEditor ! ,
219
+ const resultState = await getResultStateForComparison (
220
+ fixture . finalState ,
221
+ readableHatMap ,
247
222
spyIde ,
248
- marks ,
223
+ takeSnapshot ,
249
224
) ;
250
225
251
226
const rawSpyIdeValues = spyIde . getSpyValues ( fixture . ide ?. flashes != null ) ;
@@ -313,34 +288,3 @@ function checkMarks(
313
288
assert . deepStrictEqual ( rangeToPlainObject ( currentToken . range ) , token ) ;
314
289
} ) ;
315
290
}
316
-
317
- function getTokenHats (
318
- marks : SerializedMarks | undefined ,
319
- editor : TextEditor ,
320
- ) : TokenHat [ ] {
321
- if ( marks == null ) {
322
- return [ ] ;
323
- }
324
-
325
- return Object . entries ( marks ) . map ( ( [ key , token ] ) => {
326
- const { hatStyle, character } = splitKey ( key ) ;
327
- const range = plainObjectToRange ( token ) ;
328
-
329
- return {
330
- hatStyle,
331
- grapheme : character ,
332
- token : {
333
- editor,
334
- range,
335
- offsets : {
336
- start : editor . document . offsetAt ( range . start ) ,
337
- end : editor . document . offsetAt ( range . end ) ,
338
- } ,
339
- text : editor . document . getText ( range ) ,
340
- } ,
341
-
342
- // NB: We don't care about the hat range for this test
343
- hatRange : range ,
344
- } ;
345
- } ) ;
346
- }
0 commit comments