Fix nodejs tests

This commit is contained in:
Caelan Sayler
2025-03-03 21:19:13 +00:00
parent 961c63746a
commit a70dc44c4d
4 changed files with 116 additions and 147 deletions

View File

@@ -4,13 +4,11 @@ import {
UpdateOptions, UpdateOptions,
VelopackApp, VelopackApp,
VelopackLocatorConfig, VelopackLocatorConfig,
setVelopackLogger,
} from "../src"; } from "../src";
import path from "path"; import path from "path";
import { tempd3, fixture, updateExe, captureLogs } from "./helper"; import {tempd3, fixture, updateExe} from "./helper";
test("UpdateManager detects local update", async () => { test("UpdateManager detects local update", async () => {
await captureLogs(async () => {
await tempd3(async (tmpDir, packagesDir, rootDir) => { await tempd3(async (tmpDir, packagesDir, rootDir) => {
const locator: VelopackLocatorConfig = { const locator: VelopackLocatorConfig = {
ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec", ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec",
@@ -41,10 +39,8 @@ test("UpdateManager detects local update", async () => {
); );
}); });
}); });
});
test("UpdateManager downloads full update", async () => { test("UpdateManager downloads full update", async () => {
await captureLogs(async () => {
await tempd3(async (feedDir, packagesDir, rootDir) => { await tempd3(async (feedDir, packagesDir, rootDir) => {
const locator: VelopackLocatorConfig = { const locator: VelopackLocatorConfig = {
ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec", ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec",
@@ -76,7 +72,8 @@ test("UpdateManager downloads full update", async () => {
console.log( console.log(
`about to download update from ${feedDir} to ${packagesDir} ...`, `about to download update from ${feedDir} to ${packagesDir} ...`,
); );
await um.downloadUpdateAsync(update!, () => {}); await um.downloadUpdateAsync(update!, () => {
});
expect( expect(
existsSync( existsSync(
@@ -85,4 +82,3 @@ test("UpdateManager downloads full update", async () => {
).toBe(true); ).toBe(true);
}); });
}); });
});

View File

@@ -1,5 +1,5 @@
import { VelopackApp, VelopackLocatorConfig, setVelopackLogger } from "../src"; import {VelopackApp, VelopackLocatorConfig} from "../src";
import { isWindows, captureLogs } from "./helper"; import {isWindows} from "./helper";
class HookTester { class HookTester {
public afterInstall = false; public afterInstall = false;
@@ -42,7 +42,6 @@ class HookTester {
} }
test("VelopackApp should handle restarted event", async () => { test("VelopackApp should handle restarted event", async () => {
await captureLogs(async () => {
let [builder, tester] = HookTester.build(); let [builder, tester] = HookTester.build();
let locator: VelopackLocatorConfig = { let locator: VelopackLocatorConfig = {
ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec", ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec",
@@ -62,11 +61,9 @@ test("VelopackApp should handle restarted event", async () => {
expect(tester.firstRun).toBe(false); expect(tester.firstRun).toBe(false);
expect(tester.version).toBe("1.0.0"); expect(tester.version).toBe("1.0.0");
}); });
});
test("VelopackApp should handle after-install hook", async () => { test("VelopackApp should handle after-install hook", async () => {
if (!isWindows()) return; if (!isWindows()) return;
await captureLogs(async () => {
let [builder, tester] = HookTester.build(); let [builder, tester] = HookTester.build();
builder.setArgs(["--veloapp-install", "1.2.3-test.4"]).run(); builder.setArgs(["--veloapp-install", "1.2.3-test.4"]).run();
@@ -78,11 +75,9 @@ test("VelopackApp should handle after-install hook", async () => {
expect(tester.firstRun).toBe(false); expect(tester.firstRun).toBe(false);
expect(tester.version).toBe("1.2.3-test.4"); expect(tester.version).toBe("1.2.3-test.4");
}); });
});
test("VelopackApp should handle before-uninstall hook", async () => { test("VelopackApp should handle before-uninstall hook", async () => {
if (!isWindows()) return; if (!isWindows()) return;
await captureLogs(async () => {
let [builder, tester] = HookTester.build(); let [builder, tester] = HookTester.build();
builder.setArgs(["--veloapp-uninstall", "1.2.3-test"]).run(); builder.setArgs(["--veloapp-uninstall", "1.2.3-test"]).run();
@@ -94,11 +89,9 @@ test("VelopackApp should handle before-uninstall hook", async () => {
expect(tester.firstRun).toBe(false); expect(tester.firstRun).toBe(false);
expect(tester.version).toBe("1.2.3-test"); expect(tester.version).toBe("1.2.3-test");
}); });
});
test("VelopackApp should handle after-update hook", async () => { test("VelopackApp should handle after-update hook", async () => {
if (!isWindows()) return; if (!isWindows()) return;
await captureLogs(async () => {
let [builder, tester] = HookTester.build(); let [builder, tester] = HookTester.build();
builder.setArgs(["--veloapp-updated", "1.2.3"]).run(); builder.setArgs(["--veloapp-updated", "1.2.3"]).run();
@@ -110,11 +103,9 @@ test("VelopackApp should handle after-update hook", async () => {
expect(tester.firstRun).toBe(false); expect(tester.firstRun).toBe(false);
expect(tester.version).toBe("1.2.3"); expect(tester.version).toBe("1.2.3");
}); });
});
test("VelopackApp should handle before-update hook", async () => { test("VelopackApp should handle before-update hook", async () => {
if (!isWindows()) return; if (!isWindows()) return;
await captureLogs(async () => {
let [builder, tester] = HookTester.build(); let [builder, tester] = HookTester.build();
builder.setArgs(["--veloapp-obsolete", "1.2.3-test.4"]).run(); builder.setArgs(["--veloapp-obsolete", "1.2.3-test.4"]).run();
@@ -126,4 +117,3 @@ test("VelopackApp should handle before-update hook", async () => {
expect(tester.firstRun).toBe(false); expect(tester.firstRun).toBe(false);
expect(tester.version).toBe("1.2.3-test.4"); expect(tester.version).toBe("1.2.3-test.4");
}); });
});

View File

@@ -1,7 +1,6 @@
import fs from "node:fs"; import fs from "node:fs";
import os from "node:os"; import os from "node:os";
import path from "node:path"; import path from "node:path";
import { setVelopackLogger } from "../lib";
export function isWindows(): boolean { export function isWindows(): boolean {
return os.platform() == "win32"; return os.platform() == "win32";
@@ -36,21 +35,6 @@ export function makeId(length: number): string {
return result; return result;
} }
export async function captureLogs<T>(cb: () => Promise<T>): Promise<T> {
setVelopackLogger((level, msg) => {
console.log(level, msg);
});
try {
return await cb();
} finally {
await shortDelay();
setVelopackLogger(() => {
// unhook logger from jest
});
}
}
// export function tempd1<T>(cb: (dir: string) => T): T { // export function tempd1<T>(cb: (dir: string) => T): T {
// const id = makeId(10); // const id = makeId(10);
// const dir = path.join(os.tmpdir(), id); // const dir = path.join(os.tmpdir(), id);

View File

@@ -81,10 +81,9 @@ pub fn default_logfile_from_config(config: &VelopackLocatorConfig) -> PathBuf {
/// Default log location for Velopack on the current OS. /// Default log location for Velopack on the current OS.
#[allow(unused_variables)] #[allow(unused_variables)]
pub fn default_logfile_from_context(context: LocationContext) -> PathBuf { pub fn default_logfile_from_context(context: LocationContext) -> PathBuf {
use crate::locator::{auto_locate_app_manifest};
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
match auto_locate_app_manifest(context) { match crate::locator::auto_locate_app_manifest(context) {
Ok(locator) => { Ok(locator) => {
return default_logfile_from_locator(locator); return default_logfile_from_locator(locator);
} }