Skip to content

Commit 98598ef

Browse files
committed
Fix mocking strategy for private-config on CI
1 parent eaed63e commit 98598ef

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

__tests__/__setup__.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
import * as path from "node:path";
2+
import * as fs from "node:fs";
23
import { snapshot } from "node:test";
34

45
snapshot.setResolveSnapshotPath(testFilePath => {
56
const base = path.dirname(testFilePath);
67
const filename = path.basename(testFilePath);
78
return path.resolve(base, "__snapshots__", `${filename}.snap`);
89
});
10+
11+
// If there's no private-config.json (e.g., as there is on CI), copy the private-config.sample.json there.
12+
// This is especially necessary since Node.js's module mocking doesn't work on files that don't exist.
13+
const privateConfigPath = path.resolve(import.meta.dirname, "../private-config.json");
14+
const privateConfigSamplePath = path.resolve(import.meta.dirname, "../private-config.sample.json");
15+
try {
16+
fs.copyFileSync(privateConfigSamplePath, privateConfigPath, fs.constants.COPYFILE_EXCL);
17+
} catch (e) {
18+
if (e.code !== "EEXIST") {
19+
throw e;
20+
}
21+
}

0 commit comments

Comments
 (0)