From 4fe71521f6327be70db65df7c054f47b15d25b0d Mon Sep 17 00:00:00 2001 From: Caelan Date: Sun, 6 Oct 2024 20:29:58 -0600 Subject: [PATCH] update nodejs tests --- .gitignore | 3 +- src/lib-nodejs/copy-lib.js | 35 +++-- src/lib-nodejs/test/UpdateManager.test.ts | 151 +++++++++++----------- src/lib-nodejs/test/VelopackApp.test.ts | 4 +- 4 files changed, 100 insertions(+), 93 deletions(-) diff --git a/.gitignore b/.gitignore index 532d5394..89192eb1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ target/ _docyml/ target -index.node **/node_modules **/.DS_Store npm-debug.log* @@ -11,7 +10,7 @@ lib cargo.log cross.log *.tgz - +*.node ################# ## Eclipse diff --git a/src/lib-nodejs/copy-lib.js b/src/lib-nodejs/copy-lib.js index 9b48a98e..85346323 100644 --- a/src/lib-nodejs/copy-lib.js +++ b/src/lib-nodejs/copy-lib.js @@ -5,24 +5,31 @@ const path = require("node:path"); const platform = os.platform(); function makeCopies(input) { - // this is obviously not correct for a "production" bundle, but it is used for testing - // creating a "node" module at all of the expected production locations allows us to test - // webpack require resolution and native module bundling etc. - fs.mkdirSync("./lib/native"); - fs.copyFileSync(input, "./lib/native/velopack_nodeffi_win_x86_msvc.node"); - fs.copyFileSync(input, "./lib/native/velopack_nodeffi_win_x64_msvc.node"); - fs.copyFileSync(input, "./lib/native/velopack_nodeffi_win_arm64_msvc.node"); - fs.copyFileSync(input, "./lib/native/velopack_nodeffi_osx.node"); - fs.copyFileSync(input, "./lib/native/velopack_nodeffi_linux_x64_gnu.node"); - fs.copyFileSync(input, "./lib/native/velopack_nodeffi_linux_arm64_gnu.node"); + // this is obviously not correct for a "production" bundle, but it is used for testing + // creating a "node" module at all of the expected production locations allows us to test + // webpack require resolution and native module bundling etc. + if (!fs.existsSync("./lib/native")) fs.mkdirSync("./lib/native"); + if (!fs.existsSync("./src/native")) fs.mkdirSync("./src/native"); + fs.copyFileSync(input, "./lib/native/velopack_nodeffi_win_x86_msvc.node"); + fs.copyFileSync(input, "./lib/native/velopack_nodeffi_win_x64_msvc.node"); + fs.copyFileSync(input, "./lib/native/velopack_nodeffi_win_arm64_msvc.node"); + fs.copyFileSync(input, "./lib/native/velopack_nodeffi_osx.node"); + fs.copyFileSync(input, "./lib/native/velopack_nodeffi_linux_x64_gnu.node"); + fs.copyFileSync(input, "./lib/native/velopack_nodeffi_linux_arm64_gnu.node"); + fs.copyFileSync(input, "./src/native/velopack_nodeffi_win_x86_msvc.node"); + fs.copyFileSync(input, "./src/native/velopack_nodeffi_win_x64_msvc.node"); + fs.copyFileSync(input, "./src/native/velopack_nodeffi_win_arm64_msvc.node"); + fs.copyFileSync(input, "./src/native/velopack_nodeffi_osx.node"); + fs.copyFileSync(input, "./src/native/velopack_nodeffi_linux_x64_gnu.node"); + fs.copyFileSync(input, "./src/native/velopack_nodeffi_linux_arm64_gnu.node"); } if (platform == "win32") { - makeCopies("../../target/debug/velopack_nodeffi.dll"); + makeCopies("../../target/debug/velopack_nodeffi.dll"); } else if (platform == "darwin") { - makeCopies("../../target/debug/libvelopack_nodeffi.dylib"); + makeCopies("../../target/debug/libvelopack_nodeffi.dylib"); } else if (platform == "linux") { - makeCopies("../../target/debug/libvelopack_nodeffi.so"); + makeCopies("../../target/debug/libvelopack_nodeffi.so"); } else { - throw new Error("Unsupported platform: " + platform); + throw new Error("Unsupported platform: " + platform); } diff --git a/src/lib-nodejs/test/UpdateManager.test.ts b/src/lib-nodejs/test/UpdateManager.test.ts index f5e148b0..40d62f38 100644 --- a/src/lib-nodejs/test/UpdateManager.test.ts +++ b/src/lib-nodejs/test/UpdateManager.test.ts @@ -1,93 +1,94 @@ -import { copyFileSync, existsSync } from "fs"; +import {copyFileSync, existsSync} from "fs"; import { - UpdateManager, - UpdateOptions, - VelopackApp, - VelopackLocatorConfig, + UpdateManager, + UpdateOptions, + VelopackApp, + VelopackLocatorConfig, + setVelopackLogger, } from "../src"; import path from "path"; -import { tempd3, fixture, updateExe, shortDelay } from "./helper"; +import {tempd3, fixture, updateExe, shortDelay} from "./helper"; + +function testInit() { + VelopackApp.build().run(); + setVelopackLogger((level, msg) => { + console.log(level, msg); + }); +} test("UpdateManager detects local update", () => { - return tempd3(async (tmpDir, packagesDir, rootDir) => { - VelopackApp.build() - .setLogger((level, msg) => { - console.log(level, msg); - }) - .run(); - const locator: VelopackLocatorConfig = { - ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec", - PackagesDir: packagesDir, - RootAppDir: rootDir, - UpdateExePath: updateExe(), - CurrentBinaryDir: path.join(rootDir, "current"), - IsPortable: true, - }; + return tempd3(async (tmpDir, packagesDir, rootDir) => { + testInit(); + 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", - ); - await shortDelay(); - }); + 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", + ); + await shortDelay(); + }); }); test("UpdateManager downloads full update", () => { - return tempd3(async (feedDir, packagesDir, rootDir) => { - VelopackApp.build() - .setLogger((level, msg) => { - console.log(level, msg); - }) - .run(); - const locator: VelopackLocatorConfig = { - ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec", - PackagesDir: packagesDir, - RootAppDir: rootDir, - UpdateExePath: updateExe(), - CurrentBinaryDir: path.join(rootDir, "current"), - IsPortable: true, - }; + return tempd3(async (feedDir, packagesDir, rootDir) => { + testInit(); + 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!, () => {}); + 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); - await shortDelay(); - }); + expect( + existsSync(path.join(packagesDir, "AvaloniaCrossPlat-1.0.11-full.nupkg")), + ).toBe(true); + await shortDelay(); + }); }); diff --git a/src/lib-nodejs/test/VelopackApp.test.ts b/src/lib-nodejs/test/VelopackApp.test.ts index d8e97c3a..5cc1d43e 100644 --- a/src/lib-nodejs/test/VelopackApp.test.ts +++ b/src/lib-nodejs/test/VelopackApp.test.ts @@ -1,4 +1,4 @@ -import { VelopackApp, VelopackLocatorConfig } from "../src/index"; +import { VelopackApp, VelopackLocatorConfig, setVelopackLogger } from "../src"; import { shortDelay, isWindows } from "./helper"; class HookTester { @@ -37,7 +37,7 @@ class HookTester { tester.firstRun = true; tester.version = ver; }); - builder.setLogger((level, msg) => { + setVelopackLogger((level, msg) => { console.log(level, msg); }); return [builder, tester];