mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Fix nodejs tests
This commit is contained in:
@@ -1,88 +1,84 @@
|
||||
import { copyFileSync, existsSync } from "fs";
|
||||
import {copyFileSync, existsSync} from "fs";
|
||||
import {
|
||||
UpdateManager,
|
||||
UpdateOptions,
|
||||
VelopackApp,
|
||||
VelopackLocatorConfig,
|
||||
setVelopackLogger,
|
||||
} from "../src";
|
||||
import path from "path";
|
||||
import { tempd3, fixture, updateExe, captureLogs } from "./helper";
|
||||
import {tempd3, fixture, updateExe} from "./helper";
|
||||
|
||||
test("UpdateManager detects local update", async () => {
|
||||
await captureLogs(async () => {
|
||||
await tempd3(async (tmpDir, packagesDir, rootDir) => {
|
||||
const locator: VelopackLocatorConfig = {
|
||||
ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec",
|
||||
PackagesDir: packagesDir,
|
||||
RootAppDir: rootDir,
|
||||
UpdateExePath: updateExe(),
|
||||
CurrentBinaryDir: path.join(rootDir, "current"),
|
||||
IsPortable: true,
|
||||
};
|
||||
await tempd3(async (tmpDir, packagesDir, rootDir) => {
|
||||
const locator: VelopackLocatorConfig = {
|
||||
ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec",
|
||||
PackagesDir: packagesDir,
|
||||
RootAppDir: rootDir,
|
||||
UpdateExePath: updateExe(),
|
||||
CurrentBinaryDir: path.join(rootDir, "current"),
|
||||
IsPortable: true,
|
||||
};
|
||||
|
||||
const options: UpdateOptions = {
|
||||
ExplicitChannel: "beta",
|
||||
AllowVersionDowngrade: false,
|
||||
};
|
||||
const options: UpdateOptions = {
|
||||
ExplicitChannel: "beta",
|
||||
AllowVersionDowngrade: false,
|
||||
};
|
||||
|
||||
const um = new UpdateManager(tmpDir, options, locator);
|
||||
copyFileSync(
|
||||
fixture("testfeed.json"),
|
||||
path.join(tmpDir, "releases.beta.json"),
|
||||
);
|
||||
const update = await um.checkForUpdatesAsync();
|
||||
const um = new UpdateManager(tmpDir, options, locator);
|
||||
copyFileSync(
|
||||
fixture("testfeed.json"),
|
||||
path.join(tmpDir, "releases.beta.json"),
|
||||
);
|
||||
const update = await um.checkForUpdatesAsync();
|
||||
|
||||
expect(update).not.toBeNull();
|
||||
expect(update?.TargetFullRelease).not.toBeNull();
|
||||
expect(update?.TargetFullRelease?.Version).toBe("1.0.11");
|
||||
expect(update?.TargetFullRelease?.FileName).toBe(
|
||||
"AvaloniaCrossPlat-1.0.11-full.nupkg",
|
||||
);
|
||||
});
|
||||
expect(update).not.toBeNull();
|
||||
expect(update?.TargetFullRelease).not.toBeNull();
|
||||
expect(update?.TargetFullRelease?.Version).toBe("1.0.11");
|
||||
expect(update?.TargetFullRelease?.FileName).toBe(
|
||||
"AvaloniaCrossPlat-1.0.11-full.nupkg",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("UpdateManager downloads full update", async () => {
|
||||
await captureLogs(async () => {
|
||||
await tempd3(async (feedDir, packagesDir, rootDir) => {
|
||||
const locator: VelopackLocatorConfig = {
|
||||
ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec",
|
||||
PackagesDir: packagesDir,
|
||||
RootAppDir: rootDir,
|
||||
UpdateExePath: updateExe(),
|
||||
CurrentBinaryDir: path.join(rootDir, "current"),
|
||||
IsPortable: true,
|
||||
};
|
||||
await tempd3(async (feedDir, packagesDir, rootDir) => {
|
||||
const locator: VelopackLocatorConfig = {
|
||||
ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec",
|
||||
PackagesDir: packagesDir,
|
||||
RootAppDir: rootDir,
|
||||
UpdateExePath: updateExe(),
|
||||
CurrentBinaryDir: path.join(rootDir, "current"),
|
||||
IsPortable: true,
|
||||
};
|
||||
|
||||
const options: UpdateOptions = {
|
||||
ExplicitChannel: "beta",
|
||||
AllowVersionDowngrade: false,
|
||||
};
|
||||
const options: UpdateOptions = {
|
||||
ExplicitChannel: "beta",
|
||||
AllowVersionDowngrade: false,
|
||||
};
|
||||
|
||||
const um = new UpdateManager(feedDir, options, locator);
|
||||
copyFileSync(
|
||||
fixture("testfeed.json"),
|
||||
path.join(feedDir, "releases.beta.json"),
|
||||
);
|
||||
const um = new UpdateManager(feedDir, options, locator);
|
||||
copyFileSync(
|
||||
fixture("testfeed.json"),
|
||||
path.join(feedDir, "releases.beta.json"),
|
||||
);
|
||||
|
||||
copyFileSync(
|
||||
fixture("AvaloniaCrossPlat-1.0.11-win-full.nupkg"),
|
||||
path.join(feedDir, "AvaloniaCrossPlat-1.0.11-full.nupkg"),
|
||||
);
|
||||
copyFileSync(
|
||||
fixture("AvaloniaCrossPlat-1.0.11-win-full.nupkg"),
|
||||
path.join(feedDir, "AvaloniaCrossPlat-1.0.11-full.nupkg"),
|
||||
);
|
||||
|
||||
const update = await um.checkForUpdatesAsync();
|
||||
const update = await um.checkForUpdatesAsync();
|
||||
|
||||
console.log(
|
||||
`about to download update from ${feedDir} to ${packagesDir} ...`,
|
||||
);
|
||||
await um.downloadUpdateAsync(update!, () => {});
|
||||
|
||||
expect(
|
||||
existsSync(
|
||||
path.join(packagesDir, "AvaloniaCrossPlat-1.0.11-full.nupkg"),
|
||||
),
|
||||
).toBe(true);
|
||||
console.log(
|
||||
`about to download update from ${feedDir} to ${packagesDir} ...`,
|
||||
);
|
||||
await um.downloadUpdateAsync(update!, () => {
|
||||
});
|
||||
|
||||
expect(
|
||||
existsSync(
|
||||
path.join(packagesDir, "AvaloniaCrossPlat-1.0.11-full.nupkg"),
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { VelopackApp, VelopackLocatorConfig, setVelopackLogger } from "../src";
|
||||
import { isWindows, captureLogs } from "./helper";
|
||||
import {VelopackApp, VelopackLocatorConfig} from "../src";
|
||||
import {isWindows} from "./helper";
|
||||
|
||||
class HookTester {
|
||||
public afterInstall = false;
|
||||
@@ -42,88 +42,78 @@ class HookTester {
|
||||
}
|
||||
|
||||
test("VelopackApp should handle restarted event", async () => {
|
||||
await captureLogs(async () => {
|
||||
let [builder, tester] = HookTester.build();
|
||||
let locator: VelopackLocatorConfig = {
|
||||
ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec",
|
||||
PackagesDir: "",
|
||||
RootAppDir: "",
|
||||
UpdateExePath: "",
|
||||
CurrentBinaryDir: "",
|
||||
IsPortable: true,
|
||||
};
|
||||
builder.setLocator(locator).run();
|
||||
let [builder, tester] = HookTester.build();
|
||||
let locator: VelopackLocatorConfig = {
|
||||
ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec",
|
||||
PackagesDir: "",
|
||||
RootAppDir: "",
|
||||
UpdateExePath: "",
|
||||
CurrentBinaryDir: "",
|
||||
IsPortable: true,
|
||||
};
|
||||
builder.setLocator(locator).run();
|
||||
|
||||
expect(tester.afterInstall).toBe(false);
|
||||
expect(tester.beforeUninstall).toBe(false);
|
||||
expect(tester.beforeUpdate).toBe(false);
|
||||
expect(tester.afterUpdate).toBe(false);
|
||||
expect(tester.restarted).toBe(true);
|
||||
expect(tester.firstRun).toBe(false);
|
||||
expect(tester.version).toBe("1.0.0");
|
||||
});
|
||||
expect(tester.afterInstall).toBe(false);
|
||||
expect(tester.beforeUninstall).toBe(false);
|
||||
expect(tester.beforeUpdate).toBe(false);
|
||||
expect(tester.afterUpdate).toBe(false);
|
||||
expect(tester.restarted).toBe(true);
|
||||
expect(tester.firstRun).toBe(false);
|
||||
expect(tester.version).toBe("1.0.0");
|
||||
});
|
||||
|
||||
test("VelopackApp should handle after-install hook", async () => {
|
||||
if (!isWindows()) return;
|
||||
await captureLogs(async () => {
|
||||
let [builder, tester] = HookTester.build();
|
||||
builder.setArgs(["--veloapp-install", "1.2.3-test.4"]).run();
|
||||
let [builder, tester] = HookTester.build();
|
||||
builder.setArgs(["--veloapp-install", "1.2.3-test.4"]).run();
|
||||
|
||||
expect(tester.afterInstall).toBe(true);
|
||||
expect(tester.beforeUninstall).toBe(false);
|
||||
expect(tester.beforeUpdate).toBe(false);
|
||||
expect(tester.afterUpdate).toBe(false);
|
||||
expect(tester.restarted).toBe(false);
|
||||
expect(tester.firstRun).toBe(false);
|
||||
expect(tester.version).toBe("1.2.3-test.4");
|
||||
});
|
||||
expect(tester.afterInstall).toBe(true);
|
||||
expect(tester.beforeUninstall).toBe(false);
|
||||
expect(tester.beforeUpdate).toBe(false);
|
||||
expect(tester.afterUpdate).toBe(false);
|
||||
expect(tester.restarted).toBe(false);
|
||||
expect(tester.firstRun).toBe(false);
|
||||
expect(tester.version).toBe("1.2.3-test.4");
|
||||
});
|
||||
|
||||
test("VelopackApp should handle before-uninstall hook", async () => {
|
||||
if (!isWindows()) return;
|
||||
await captureLogs(async () => {
|
||||
let [builder, tester] = HookTester.build();
|
||||
builder.setArgs(["--veloapp-uninstall", "1.2.3-test"]).run();
|
||||
let [builder, tester] = HookTester.build();
|
||||
builder.setArgs(["--veloapp-uninstall", "1.2.3-test"]).run();
|
||||
|
||||
expect(tester.afterInstall).toBe(false);
|
||||
expect(tester.beforeUninstall).toBe(true);
|
||||
expect(tester.beforeUpdate).toBe(false);
|
||||
expect(tester.afterUpdate).toBe(false);
|
||||
expect(tester.restarted).toBe(false);
|
||||
expect(tester.firstRun).toBe(false);
|
||||
expect(tester.version).toBe("1.2.3-test");
|
||||
});
|
||||
expect(tester.afterInstall).toBe(false);
|
||||
expect(tester.beforeUninstall).toBe(true);
|
||||
expect(tester.beforeUpdate).toBe(false);
|
||||
expect(tester.afterUpdate).toBe(false);
|
||||
expect(tester.restarted).toBe(false);
|
||||
expect(tester.firstRun).toBe(false);
|
||||
expect(tester.version).toBe("1.2.3-test");
|
||||
});
|
||||
|
||||
test("VelopackApp should handle after-update hook", async () => {
|
||||
if (!isWindows()) return;
|
||||
await captureLogs(async () => {
|
||||
let [builder, tester] = HookTester.build();
|
||||
builder.setArgs(["--veloapp-updated", "1.2.3"]).run();
|
||||
let [builder, tester] = HookTester.build();
|
||||
builder.setArgs(["--veloapp-updated", "1.2.3"]).run();
|
||||
|
||||
expect(tester.afterInstall).toBe(false);
|
||||
expect(tester.beforeUninstall).toBe(false);
|
||||
expect(tester.beforeUpdate).toBe(false);
|
||||
expect(tester.afterUpdate).toBe(true);
|
||||
expect(tester.restarted).toBe(false);
|
||||
expect(tester.firstRun).toBe(false);
|
||||
expect(tester.version).toBe("1.2.3");
|
||||
});
|
||||
expect(tester.afterInstall).toBe(false);
|
||||
expect(tester.beforeUninstall).toBe(false);
|
||||
expect(tester.beforeUpdate).toBe(false);
|
||||
expect(tester.afterUpdate).toBe(true);
|
||||
expect(tester.restarted).toBe(false);
|
||||
expect(tester.firstRun).toBe(false);
|
||||
expect(tester.version).toBe("1.2.3");
|
||||
});
|
||||
|
||||
test("VelopackApp should handle before-update hook", async () => {
|
||||
if (!isWindows()) return;
|
||||
await captureLogs(async () => {
|
||||
let [builder, tester] = HookTester.build();
|
||||
builder.setArgs(["--veloapp-obsolete", "1.2.3-test.4"]).run();
|
||||
let [builder, tester] = HookTester.build();
|
||||
builder.setArgs(["--veloapp-obsolete", "1.2.3-test.4"]).run();
|
||||
|
||||
expect(tester.afterInstall).toBe(false);
|
||||
expect(tester.beforeUninstall).toBe(false);
|
||||
expect(tester.beforeUpdate).toBe(true);
|
||||
expect(tester.afterUpdate).toBe(false);
|
||||
expect(tester.restarted).toBe(false);
|
||||
expect(tester.firstRun).toBe(false);
|
||||
expect(tester.version).toBe("1.2.3-test.4");
|
||||
});
|
||||
expect(tester.afterInstall).toBe(false);
|
||||
expect(tester.beforeUninstall).toBe(false);
|
||||
expect(tester.beforeUpdate).toBe(true);
|
||||
expect(tester.afterUpdate).toBe(false);
|
||||
expect(tester.restarted).toBe(false);
|
||||
expect(tester.firstRun).toBe(false);
|
||||
expect(tester.version).toBe("1.2.3-test.4");
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { setVelopackLogger } from "../lib";
|
||||
|
||||
export function isWindows(): boolean {
|
||||
return os.platform() == "win32";
|
||||
@@ -36,21 +35,6 @@ export function makeId(length: number): string {
|
||||
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 {
|
||||
// const id = makeId(10);
|
||||
// const dir = path.join(os.tmpdir(), id);
|
||||
|
||||
@@ -81,10 +81,9 @@ pub fn default_logfile_from_config(config: &VelopackLocatorConfig) -> PathBuf {
|
||||
/// Default log location for Velopack on the current OS.
|
||||
#[allow(unused_variables)]
|
||||
pub fn default_logfile_from_context(context: LocationContext) -> PathBuf {
|
||||
use crate::locator::{auto_locate_app_manifest};
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
match auto_locate_app_manifest(context) {
|
||||
match crate::locator::auto_locate_app_manifest(context) {
|
||||
Ok(locator) => {
|
||||
return default_logfile_from_locator(locator);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user