Skip to content

Commit 23bd84e

Browse files
committed
respect update fixtures flag
1 parent 6c16e45 commit 23bd84e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/cursorless-engine/src/core/hatStats.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
TokenHat,
99
TokenHatSplittingMode,
1010
getCursorlessRepoRoot,
11+
shouldUpdateFixtures,
1112
} from "@cursorless/common";
1213
import * as fs from "fs";
1314
import { 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.
2325
const 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

Comments
 (0)