Files
wehub-resource-sync 70bf21e064
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:11 +08:00

36 lines
1.0 KiB
TypeScript

import fs from "node:fs";
import { onTestFinished, test } from "vitest";
import { isWindows } from "../vitest-setup";
export * from "../vitest-setup";
export * from "./responses";
export { satisfiesMinimumViteVersion } from "./vite-version";
/** Common options to use with `vi.waitFor()` */
export const WAIT_FOR_OPTIONS = {
timeout: isWindows ? 10_000 : 5_000,
interval: 500,
};
export function failsIf(condition: boolean) {
return condition ? test.fails : test;
}
/**
* Makes a change to a file and restores it after the test is finished.
*/
export function mockFileChange(
/** The path to the file to change */
filePath: string,
/** A function that modifies the original content of the file */
mutateFn: (originalContent: string) => string
) {
const originalContent = fs.readFileSync(filePath, "utf-8");
onTestFinished(() => {
console.log("Restoring file change for", filePath);
fs.writeFileSync(filePath, originalContent);
});
console.log("Mocking file change for", filePath);
fs.writeFileSync(filePath, mutateFn(originalContent));
}