Skip to content

Commit cc73dde

Browse files
authored
fix(bazel/api-golden): do not try to read golden in approve mode (#2666)
This allows us to approve goldens even if the files don't exist yet.
1 parent 099af4b commit cc73dde

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

bazel/api-golden/index_npm_packages.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ async function main(
5353
const goldenFilePath = path.join(goldenDir, goldenName);
5454
const moduleName = normalizePathToPosix(path.join(packageJson.name, subpath));
5555

56-
const expected = fs.readFileSync(goldenFilePath, 'utf8');
5756
const actual = await testApiGolden(
5857
typesEntryPointPath,
5958
stripExportPattern,
@@ -67,17 +66,17 @@ async function main(
6766
process.exit(1);
6867
}
6968

70-
// Keep track of outdated goldens.
71-
if (actual !== expected) {
72-
if (approveGolden) {
73-
fs.mkdirSync(path.dirname(goldenFilePath), {recursive: true});
74-
fs.writeFileSync(goldenFilePath, actual, 'utf8');
75-
} else {
69+
if (approveGolden) {
70+
fs.mkdirSync(path.dirname(goldenFilePath), {recursive: true});
71+
fs.writeFileSync(goldenFilePath, actual, 'utf8');
72+
} else {
73+
const expected = fs.readFileSync(goldenFilePath, 'utf8');
74+
if (actual !== expected) {
75+
// Keep track of outdated goldens for error message.
7676
outdatedGoldens.push(goldenName);
77+
allTestsSucceeding = false;
7778
}
7879
}
79-
80-
allTestsSucceeding = allTestsSucceeding && actual === expected;
8180
}
8281

8382
if (outdatedGoldens.length) {

0 commit comments

Comments
 (0)