88 TokenHat ,
99 TokenHatSplittingMode ,
1010 getCursorlessRepoRoot ,
11+ shouldUpdateFixtures ,
1112} from "@cursorless/common" ;
1213import * as fs from "fs" ;
1314import { unitTestSetup } from "../test/unitTestSetup" ;
@@ -18,6 +19,7 @@ import {
1819 RankedToken ,
1920 getRankedTokens ,
2021} from "../util/allocateHats/getRankedTokens" ;
22+ import assert = require( "assert" ) ;
2123
2224// We use special hat "colors"/"shapes" for nice ASCII art output.
2325const HAT_COLORS = [ "default" , ..."ABCDEF" ] ;
@@ -137,7 +139,13 @@ suite("hatStats", () => {
137139
138140 if ( index === 0 ) {
139141 const golden = goldenHatFile ( contents , allTokens , tokenHat ) ;
140- fs . writeFileSync ( filepath + ".golden" , golden ) ;
142+ const goldenPath = filepath + ".golden" ;
143+ if ( shouldUpdateFixtures ( ) ) {
144+ fs . writeFileSync ( goldenPath , golden ) ;
145+ } else {
146+ const actual = fs . readFileSync ( goldenPath , "utf-8" ) ;
147+ assert . equal ( actual , golden ) ;
148+ }
141149 }
142150
143151 nHats . push ( ( 100 * tokenHat . length ) / allTokens . length ) ;
@@ -164,7 +172,13 @@ suite("hatStats", () => {
164172 s += describeDistribution ( "nPenalty2" , nPenalty2 ) + "\n" ;
165173 // replace multiple trailing newlines with just one to placate pre-commit
166174 s = s . replace ( / \n + $ / , "\n" ) ;
167- fs . writeFileSync ( filepath + ".stats" , s ) ;
175+ const statsPath = filepath + ".stats" ;
176+ if ( shouldUpdateFixtures ( ) ) {
177+ fs . writeFileSync ( filepath + ".stats" , s ) ;
178+ } else {
179+ const actual = fs . readFileSync ( statsPath , "utf-8" ) ;
180+ assert . equal ( actual , s ) ;
181+ }
168182 } ) ;
169183 } ) ;
170184} ) ;
0 commit comments