mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
improve upd search in js test
This commit is contained in:
@@ -3,28 +3,36 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
export function isWindows(): boolean {
|
||||
return os.platform() == "win32";
|
||||
return os.platform() == "win32";
|
||||
}
|
||||
|
||||
export function isLinux(): boolean {
|
||||
return os.platform() == "linux";
|
||||
}
|
||||
|
||||
export function isMacos(): boolean {
|
||||
return os.platform() == "darwin";
|
||||
}
|
||||
|
||||
export function getTempDir(): string {
|
||||
return fs.realpathSync(os.tmpdir());
|
||||
return fs.realpathSync(os.tmpdir());
|
||||
}
|
||||
|
||||
export function fixture(name: string): string {
|
||||
return path.join("..", "..", "test", "fixtures", name);
|
||||
return path.join("..", "..", "test", "fixtures", name);
|
||||
}
|
||||
|
||||
export function makeId(length: number): string {
|
||||
let result = "";
|
||||
const characters =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
const charactersLength = characters.length;
|
||||
let counter = 0;
|
||||
while (counter < length) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
counter += 1;
|
||||
}
|
||||
return result;
|
||||
let result = "";
|
||||
const characters =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
const charactersLength = characters.length;
|
||||
let counter = 0;
|
||||
while (counter < length) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
counter += 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// export function tempd1<T>(cb: (dir: string) => T): T {
|
||||
@@ -52,67 +60,78 @@ export function makeId(length: number): string {
|
||||
// }
|
||||
|
||||
export async function tempd3<T>(
|
||||
cb: (dir1: string, dir2: string, dir3: string) => T,
|
||||
cb: (dir1: string, dir2: string, dir3: string) => T,
|
||||
): Promise<T> {
|
||||
const dir1 = path.join(os.tmpdir(), makeId(16));
|
||||
const dir2 = path.join(os.tmpdir(), makeId(16));
|
||||
const dir3 = path.join(os.tmpdir(), makeId(16));
|
||||
fs.mkdirSync(dir1);
|
||||
fs.mkdirSync(dir2);
|
||||
fs.mkdirSync(dir3);
|
||||
try {
|
||||
return await cb(dir1, dir2, dir3);
|
||||
} finally {
|
||||
fs.rmSync(dir1, { recursive: true });
|
||||
fs.rmSync(dir2, { recursive: true });
|
||||
fs.rmSync(dir3, { recursive: true });
|
||||
}
|
||||
const dir1 = path.join(os.tmpdir(), makeId(16));
|
||||
const dir2 = path.join(os.tmpdir(), makeId(16));
|
||||
const dir3 = path.join(os.tmpdir(), makeId(16));
|
||||
fs.mkdirSync(dir1);
|
||||
fs.mkdirSync(dir2);
|
||||
fs.mkdirSync(dir3);
|
||||
try {
|
||||
return await cb(dir1, dir2, dir3);
|
||||
} finally {
|
||||
fs.rmSync(dir1, {recursive: true});
|
||||
fs.rmSync(dir2, {recursive: true});
|
||||
fs.rmSync(dir3, {recursive: true});
|
||||
}
|
||||
}
|
||||
|
||||
export async function tempd4<T>(
|
||||
cb: (dir1: string, dir2: string, dir3: string, dir4: string) => T,
|
||||
cb: (dir1: string, dir2: string, dir3: string, dir4: string) => T,
|
||||
): Promise<T> {
|
||||
const dir1 = path.join(os.tmpdir(), makeId(16));
|
||||
const dir2 = path.join(os.tmpdir(), makeId(16));
|
||||
const dir3 = path.join(os.tmpdir(), makeId(16));
|
||||
const dir4 = path.join(os.tmpdir(), makeId(16));
|
||||
fs.mkdirSync(dir1);
|
||||
fs.mkdirSync(dir2);
|
||||
fs.mkdirSync(dir3);
|
||||
fs.mkdirSync(dir4);
|
||||
try {
|
||||
return await cb(dir1, dir2, dir3, dir4);
|
||||
} finally {
|
||||
fs.rmSync(dir1, { recursive: true });
|
||||
fs.rmSync(dir2, { recursive: true });
|
||||
fs.rmSync(dir3, { recursive: true });
|
||||
fs.rmSync(dir4, { recursive: true });
|
||||
}
|
||||
const dir1 = path.join(os.tmpdir(), makeId(16));
|
||||
const dir2 = path.join(os.tmpdir(), makeId(16));
|
||||
const dir3 = path.join(os.tmpdir(), makeId(16));
|
||||
const dir4 = path.join(os.tmpdir(), makeId(16));
|
||||
fs.mkdirSync(dir1);
|
||||
fs.mkdirSync(dir2);
|
||||
fs.mkdirSync(dir3);
|
||||
fs.mkdirSync(dir4);
|
||||
try {
|
||||
return await cb(dir1, dir2, dir3, dir4);
|
||||
} finally {
|
||||
fs.rmSync(dir1, {recursive: true});
|
||||
fs.rmSync(dir2, {recursive: true});
|
||||
fs.rmSync(dir3, {recursive: true});
|
||||
fs.rmSync(dir4, {recursive: true});
|
||||
}
|
||||
}
|
||||
|
||||
export function updateExe(): string {
|
||||
const paths = [
|
||||
path.join("..", "..", "target", "debug", "Update.exe"),
|
||||
path.join("..", "..", "target", "release", "Update.exe"),
|
||||
path.join("..", "..", "target", "debug", "update"),
|
||||
path.join("..", "..", "target", "release", "update"),
|
||||
path.join("..", "..", "target", "debug", "UpdateMac"),
|
||||
path.join("..", "..", "target", "release", "UpdateMac"),
|
||||
path.join("..", "..", "target", "debug", "UpdateNix"),
|
||||
path.join("..", "..", "target", "release", "UpdateNix"),
|
||||
];
|
||||
|
||||
for (const p of paths) {
|
||||
if (fs.existsSync(p)) {
|
||||
return p;
|
||||
const paths = [];
|
||||
|
||||
if (isMacos()) {
|
||||
paths.push(path.join("..", "..", "target", "debug", "UpdateMac"));
|
||||
paths.push(path.join("..", "..", "target", "release", "UpdateMac"));
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("Update.exe not found");
|
||||
if (isLinux()) {
|
||||
paths.push(path.join("..", "..", "target", "debug", "UpdateNix"));
|
||||
paths.push(path.join("..", "..", "target", "release", "UpdateNix"));
|
||||
}
|
||||
|
||||
if (isMacos() || isLinux()) {
|
||||
paths.push(path.join("..", "..", "target", "debug", "update"));
|
||||
paths.push(path.join("..", "..", "target", "release", "update"));
|
||||
}
|
||||
|
||||
if (isWindows()) {
|
||||
paths.push(path.join("..", "..", "target", "debug", "Update.exe"));
|
||||
paths.push(path.join("..", "..", "target", "release", "Update.exe"));
|
||||
}
|
||||
|
||||
for (const p of paths) {
|
||||
if (fs.existsSync(p)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("Update.exe not found");
|
||||
}
|
||||
|
||||
export function shortDelay(): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, 300));
|
||||
return new Promise((resolve) => setTimeout(resolve, 300));
|
||||
}
|
||||
|
||||
// export function copyUpdateExeTo(dir: string, filename?: string): string {
|
||||
|
||||
Reference in New Issue
Block a user