@@ -18,23 +18,21 @@ import {
1818 TestCaseFixtureLegacy ,
1919 TestCaseSnapshot ,
2020 TextEditor ,
21- TokenHat ,
2221 clientSupportsFallback ,
23- extractTargetedMarks ,
24- marksToPlainObject ,
22+ loadFixture ,
2523 omitByDeep ,
26- plainObjectToRange ,
2724 rangeToPlainObject ,
2825 serializeTestFixture ,
26+ serializedMarksToTokenHats ,
2927 shouldUpdateFixtures ,
3028 splitKey ,
3129 spyIDERecordedValuesToPlainObject ,
3230 storedTargetKeys ,
3331} from "@cursorless/common" ;
3432import { assert } from "chai" ;
35- import * as yaml from "js-yaml" ;
3633import { isUndefined } from "lodash" ;
3734import { promises as fsp } from "node:fs" ;
35+ import { getResultStateForComparison } from "./getResultStateForComparison" ;
3836
3937function createPosition ( position : PositionPlainObject ) {
4038 return new Position ( position . line , position . character ) ;
@@ -123,9 +121,7 @@ export async function runRecordedTest({
123121 testHelpers,
124122 runCursorlessCommand,
125123} : 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 ) ;
129125
130126 // FIXME The snapshot gets messed up with timing issues when running the recorded tests
131127 // "Couldn't find token default.a"
@@ -162,7 +158,10 @@ export async function runRecordedTest({
162158
163159 // Ensure that the expected hats are present
164160 await hatTokenMap . allocateHats (
165- getTokenHats ( fixture . initialState . marks , spyIde . activeTextEditor ! ) ,
161+ serializedMarksToTokenHats (
162+ fixture . initialState . marks ,
163+ spyIde . activeTextEditor ! ,
164+ ) ,
166165 ) ;
167166
168167 const readableHatMap = await hatTokenMap . getReadableMap ( usePrePhraseSnapshot ) ;
@@ -217,35 +216,11 @@ export async function runRecordedTest({
217216 await sleepWithBackoff ( fixture . postCommandSleepTimeMs ) ;
218217 }
219218
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 ,
247222 spyIde ,
248- marks ,
223+ takeSnapshot ,
249224 ) ;
250225
251226 const rawSpyIdeValues = spyIde . getSpyValues ( fixture . ide ?. flashes != null ) ;
@@ -313,34 +288,3 @@ function checkMarks(
313288 assert . deepStrictEqual ( rangeToPlainObject ( currentToken . range ) , token ) ;
314289 } ) ;
315290}
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