mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-11-06 02:25:24 +00:00
fix: test
This commit is contained in:
1 parent
041e10eb5c
commit
c09d09f2ce
2 files changed
+28
-2
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import crypto from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
@@ -471,6 +471,27 @@ describe("rebuilding local plugins", () => {
|
||||
expect(isLocalBuildStale(root)).toBe(false);
|
||||
});
|
||||
|
||||
it("survives a build replacing dist during the scan", () => {
|
||||
const root = repo(tempDir(), "Plugin-A", "a");
|
||||
const gone = path.join(root, "dist", "migrations", "postgres");
|
||||
fs.mkdirSync(gone, { recursive: true });
|
||||
fs.writeFileSync(path.join(root, "manifest.json"), "{}");
|
||||
const realStat = fs.statSync;
|
||||
const spy = vi.spyOn(fs, "statSync").mockImplementation(((
|
||||
target: string,
|
||||
) => {
|
||||
if (target === gone) {
|
||||
throw Object.assign(new Error("gone"), { code: "ENOENT" });
|
||||
}
|
||||
return realStat(target);
|
||||
}) as typeof fs.statSync);
|
||||
try {
|
||||
expect(() => isLocalBuildStale(root)).not.toThrow();
|
||||
} finally {
|
||||
spy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("builds with this checkout's SDK CLI, not the plugin's own", () => {
|
||||
const [command, args] = localSdkBuildCommand();
|
||||
expect(command).toBe(process.execPath);
|
||||
|
||||
@@ -370,8 +370,9 @@ const BUILD_INPUTS = [
|
||||
"package.json",
|
||||
];
|
||||
|
||||
// A build can replace dist while this walks it, so a path can vanish mid scan.
|
||||
function newestMtime(target) {
|
||||
if (!fs.existsSync(target)) return 0;
|
||||
try {
|
||||
const stat = fs.statSync(target);
|
||||
if (!stat.isDirectory()) return stat.mtimeMs;
|
||||
let newest = 0;
|
||||
@@ -379,6 +380,10 @@ function newestMtime(target) {
|
||||
newest = Math.max(newest, newestMtime(path.join(target, name)));
|
||||
}
|
||||
return newest;
|
||||
} catch (error) {
|
||||
if (error.code === "ENOENT") return 0;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/** True when a plugin repo has never been built or its sources changed since. */
|
||||
|
||||
Reference in new issue
Block a user