8
8
TokenHat ,
9
9
TokenHatSplittingMode ,
10
10
getCursorlessRepoRoot ,
11
+ shouldUpdateFixtures ,
11
12
} from "@cursorless/common" ;
12
13
import * as fs from "fs" ;
13
14
import { unitTestSetup } from "../test/unitTestSetup" ;
@@ -18,6 +19,7 @@ import {
18
19
RankedToken ,
19
20
getRankedTokens ,
20
21
} from "../util/allocateHats/getRankedTokens" ;
22
+ import assert = require( "assert" ) ;
21
23
22
24
// We use special hat "colors"/"shapes" for nice ASCII art output.
23
25
const HAT_COLORS = [ "default" , ..."ABCDEF" ] ;
@@ -137,7 +139,13 @@ suite("hatStats", () => {
137
139
138
140
if ( index === 0 ) {
139
141
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
+ }
141
149
}
142
150
143
151
nHats . push ( ( 100 * tokenHat . length ) / allTokens . length ) ;
@@ -164,7 +172,13 @@ suite("hatStats", () => {
164
172
s += describeDistribution ( "nPenalty2" , nPenalty2 ) + "\n" ;
165
173
// replace multiple trailing newlines with just one to placate pre-commit
166
174
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
+ }
168
182
} ) ;
169
183
} ) ;
170
184
} ) ;
0 commit comments