-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit-id:08bc84d8
- Loading branch information
Showing
7 changed files
with
26 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
import { createHash } from "node:crypto"; | ||
import * as fs from "node:fs/promises"; | ||
import * as path from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace NodeJS { | ||
interface ProcessEnv { | ||
CAIRO_FIX_TESTS: string; | ||
} | ||
} | ||
} | ||
|
||
const isFixMode = process.env.CAIRO_FIX_TESTS === "1"; | ||
|
||
export const snap = isFixMode ? fix : read; | ||
|
||
async function read(key) { | ||
async function read(key: string) { | ||
const snapshotPath = getSnapshotPath(key); | ||
return await fs.readFile(snapshotPath, "utf8"); | ||
} | ||
|
||
async function fix(key, text) { | ||
async function fix(key: string, text: string) { | ||
const snapshotPath = getSnapshotPath(key); | ||
await fs.mkdir(path.dirname(snapshotPath), { recursive: true }); | ||
await fs.writeFile(snapshotPath, text, "utf8"); | ||
return text; | ||
} | ||
|
||
function getSnapshotPath(key) { | ||
function getSnapshotPath(key: string) { | ||
const hash = createHash("sha256").update(key).digest("hex").slice(0, 10); | ||
return path.join(fileURLToPath(import.meta.url), "..", "..", "test", "snapshots", `${hash}.txt`); | ||
return path.join(__filename, "..", "..", "..", "test", "snapshots", `${hash}.txt`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters