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 { | import { | ||||||
|   UpdateManager, |   UpdateManager, | ||||||
|   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", |       PackagesDir: packagesDir, | ||||||
|         PackagesDir: packagesDir, |       RootAppDir: rootDir, | ||||||
|         RootAppDir: rootDir, |       UpdateExePath: updateExe(), | ||||||
|         UpdateExePath: updateExe(), |       CurrentBinaryDir: path.join(rootDir, "current"), | ||||||
|         CurrentBinaryDir: path.join(rootDir, "current"), |       IsPortable: true, | ||||||
|         IsPortable: true, |     }; | ||||||
|       }; |  | ||||||
|  |  | ||||||
|       const options: UpdateOptions = { |     const options: UpdateOptions = { | ||||||
|         ExplicitChannel: "beta", |       ExplicitChannel: "beta", | ||||||
|         AllowVersionDowngrade: false, |       AllowVersionDowngrade: false, | ||||||
|       }; |     }; | ||||||
|  |  | ||||||
|       const um = new UpdateManager(tmpDir, options, locator); |     const um = new UpdateManager(tmpDir, options, locator); | ||||||
|       copyFileSync( |     copyFileSync( | ||||||
|         fixture("testfeed.json"), |       fixture("testfeed.json"), | ||||||
|         path.join(tmpDir, "releases.beta.json"), |       path.join(tmpDir, "releases.beta.json"), | ||||||
|       ); |     ); | ||||||
|       const update = await um.checkForUpdatesAsync(); |     const update = await um.checkForUpdatesAsync(); | ||||||
|  |  | ||||||
|       expect(update).not.toBeNull(); |     expect(update).not.toBeNull(); | ||||||
|       expect(update?.TargetFullRelease).not.toBeNull(); |     expect(update?.TargetFullRelease).not.toBeNull(); | ||||||
|       expect(update?.TargetFullRelease?.Version).toBe("1.0.11"); |     expect(update?.TargetFullRelease?.Version).toBe("1.0.11"); | ||||||
|       expect(update?.TargetFullRelease?.FileName).toBe( |     expect(update?.TargetFullRelease?.FileName).toBe( | ||||||
|         "AvaloniaCrossPlat-1.0.11-full.nupkg", |       "AvaloniaCrossPlat-1.0.11-full.nupkg", | ||||||
|       ); |     ); | ||||||
|     }); |  | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| 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", |       PackagesDir: packagesDir, | ||||||
|         PackagesDir: packagesDir, |       RootAppDir: rootDir, | ||||||
|         RootAppDir: rootDir, |       UpdateExePath: updateExe(), | ||||||
|         UpdateExePath: updateExe(), |       CurrentBinaryDir: path.join(rootDir, "current"), | ||||||
|         CurrentBinaryDir: path.join(rootDir, "current"), |       IsPortable: true, | ||||||
|         IsPortable: true, |     }; | ||||||
|       }; |  | ||||||
|  |  | ||||||
|       const options: UpdateOptions = { |     const options: UpdateOptions = { | ||||||
|         ExplicitChannel: "beta", |       ExplicitChannel: "beta", | ||||||
|         AllowVersionDowngrade: false, |       AllowVersionDowngrade: false, | ||||||
|       }; |     }; | ||||||
|  |  | ||||||
|       const um = new UpdateManager(feedDir, options, locator); |     const um = new UpdateManager(feedDir, options, locator); | ||||||
|       copyFileSync( |     copyFileSync( | ||||||
|         fixture("testfeed.json"), |       fixture("testfeed.json"), | ||||||
|         path.join(feedDir, "releases.beta.json"), |       path.join(feedDir, "releases.beta.json"), | ||||||
|       ); |     ); | ||||||
|  |  | ||||||
|       copyFileSync( |     copyFileSync( | ||||||
|         fixture("AvaloniaCrossPlat-1.0.11-win-full.nupkg"), |       fixture("AvaloniaCrossPlat-1.0.11-win-full.nupkg"), | ||||||
|         path.join(feedDir, "AvaloniaCrossPlat-1.0.11-full.nupkg"), |       path.join(feedDir, "AvaloniaCrossPlat-1.0.11-full.nupkg"), | ||||||
|       ); |     ); | ||||||
|  |  | ||||||
|       const update = await um.checkForUpdatesAsync(); |     const update = await um.checkForUpdatesAsync(); | ||||||
|  |  | ||||||
|       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( |  | ||||||
|         existsSync( |  | ||||||
|           path.join(packagesDir, "AvaloniaCrossPlat-1.0.11-full.nupkg"), |  | ||||||
|         ), |  | ||||||
|       ).toBe(true); |  | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  |     expect( | ||||||
|  |       existsSync( | ||||||
|  |         path.join(packagesDir, "AvaloniaCrossPlat-1.0.11-full.nupkg"), | ||||||
|  |       ), | ||||||
|  |     ).toBe(true); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|   | |||||||
| @@ -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,88 +42,78 @@ 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", |     PackagesDir: "", | ||||||
|       PackagesDir: "", |     RootAppDir: "", | ||||||
|       RootAppDir: "", |     UpdateExePath: "", | ||||||
|       UpdateExePath: "", |     CurrentBinaryDir: "", | ||||||
|       CurrentBinaryDir: "", |     IsPortable: true, | ||||||
|       IsPortable: true, |   }; | ||||||
|     }; |   builder.setLocator(locator).run(); | ||||||
|     builder.setLocator(locator).run(); |  | ||||||
|  |  | ||||||
|     expect(tester.afterInstall).toBe(false); |   expect(tester.afterInstall).toBe(false); | ||||||
|     expect(tester.beforeUninstall).toBe(false); |   expect(tester.beforeUninstall).toBe(false); | ||||||
|     expect(tester.beforeUpdate).toBe(false); |   expect(tester.beforeUpdate).toBe(false); | ||||||
|     expect(tester.afterUpdate).toBe(false); |   expect(tester.afterUpdate).toBe(false); | ||||||
|     expect(tester.restarted).toBe(true); |   expect(tester.restarted).toBe(true); | ||||||
|     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(); |  | ||||||
|  |  | ||||||
|     expect(tester.afterInstall).toBe(true); |   expect(tester.afterInstall).toBe(true); | ||||||
|     expect(tester.beforeUninstall).toBe(false); |   expect(tester.beforeUninstall).toBe(false); | ||||||
|     expect(tester.beforeUpdate).toBe(false); |   expect(tester.beforeUpdate).toBe(false); | ||||||
|     expect(tester.afterUpdate).toBe(false); |   expect(tester.afterUpdate).toBe(false); | ||||||
|     expect(tester.restarted).toBe(false); |   expect(tester.restarted).toBe(false); | ||||||
|     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(); |  | ||||||
|  |  | ||||||
|     expect(tester.afterInstall).toBe(false); |   expect(tester.afterInstall).toBe(false); | ||||||
|     expect(tester.beforeUninstall).toBe(true); |   expect(tester.beforeUninstall).toBe(true); | ||||||
|     expect(tester.beforeUpdate).toBe(false); |   expect(tester.beforeUpdate).toBe(false); | ||||||
|     expect(tester.afterUpdate).toBe(false); |   expect(tester.afterUpdate).toBe(false); | ||||||
|     expect(tester.restarted).toBe(false); |   expect(tester.restarted).toBe(false); | ||||||
|     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(); |  | ||||||
|  |  | ||||||
|     expect(tester.afterInstall).toBe(false); |   expect(tester.afterInstall).toBe(false); | ||||||
|     expect(tester.beforeUninstall).toBe(false); |   expect(tester.beforeUninstall).toBe(false); | ||||||
|     expect(tester.beforeUpdate).toBe(false); |   expect(tester.beforeUpdate).toBe(false); | ||||||
|     expect(tester.afterUpdate).toBe(true); |   expect(tester.afterUpdate).toBe(true); | ||||||
|     expect(tester.restarted).toBe(false); |   expect(tester.restarted).toBe(false); | ||||||
|     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(); |  | ||||||
|  |  | ||||||
|     expect(tester.afterInstall).toBe(false); |   expect(tester.afterInstall).toBe(false); | ||||||
|     expect(tester.beforeUninstall).toBe(false); |   expect(tester.beforeUninstall).toBe(false); | ||||||
|     expect(tester.beforeUpdate).toBe(true); |   expect(tester.beforeUpdate).toBe(true); | ||||||
|     expect(tester.afterUpdate).toBe(false); |   expect(tester.afterUpdate).toBe(false); | ||||||
|     expect(tester.restarted).toBe(false); |   expect(tester.restarted).toBe(false); | ||||||
|     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"); | ||||||
|   }); |  | ||||||
| }); | }); | ||||||
|   | |||||||
| @@ -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); | ||||||
|   | |||||||
| @@ -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); | ||||||
|             } |             } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user