update nodejs tests

This commit is contained in:
Caelan
2024-10-06 20:29:58 -06:00
parent d91478fff6
commit 4fe71521f6
4 changed files with 100 additions and 93 deletions

3
.gitignore vendored
View File

@@ -3,7 +3,6 @@ target/
_docyml/ _docyml/
target target
index.node
**/node_modules **/node_modules
**/.DS_Store **/.DS_Store
npm-debug.log* npm-debug.log*
@@ -11,7 +10,7 @@ lib
cargo.log cargo.log
cross.log cross.log
*.tgz *.tgz
*.node
################# #################
## Eclipse ## Eclipse

View File

@@ -5,24 +5,31 @@ const path = require("node:path");
const platform = os.platform(); const platform = os.platform();
function makeCopies(input) { function makeCopies(input) {
// this is obviously not correct for a "production" bundle, but it is used for testing // 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 // creating a "node" module at all of the expected production locations allows us to test
// webpack require resolution and native module bundling etc. // webpack require resolution and native module bundling etc.
fs.mkdirSync("./lib/native"); if (!fs.existsSync("./lib/native")) fs.mkdirSync("./lib/native");
fs.copyFileSync(input, "./lib/native/velopack_nodeffi_win_x86_msvc.node"); if (!fs.existsSync("./src/native")) fs.mkdirSync("./src/native");
fs.copyFileSync(input, "./lib/native/velopack_nodeffi_win_x64_msvc.node"); fs.copyFileSync(input, "./lib/native/velopack_nodeffi_win_x86_msvc.node");
fs.copyFileSync(input, "./lib/native/velopack_nodeffi_win_arm64_msvc.node"); fs.copyFileSync(input, "./lib/native/velopack_nodeffi_win_x64_msvc.node");
fs.copyFileSync(input, "./lib/native/velopack_nodeffi_osx.node"); fs.copyFileSync(input, "./lib/native/velopack_nodeffi_win_arm64_msvc.node");
fs.copyFileSync(input, "./lib/native/velopack_nodeffi_linux_x64_gnu.node"); fs.copyFileSync(input, "./lib/native/velopack_nodeffi_osx.node");
fs.copyFileSync(input, "./lib/native/velopack_nodeffi_linux_arm64_gnu.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") { if (platform == "win32") {
makeCopies("../../target/debug/velopack_nodeffi.dll"); makeCopies("../../target/debug/velopack_nodeffi.dll");
} else if (platform == "darwin") { } else if (platform == "darwin") {
makeCopies("../../target/debug/libvelopack_nodeffi.dylib"); makeCopies("../../target/debug/libvelopack_nodeffi.dylib");
} else if (platform == "linux") { } else if (platform == "linux") {
makeCopies("../../target/debug/libvelopack_nodeffi.so"); makeCopies("../../target/debug/libvelopack_nodeffi.so");
} else { } else {
throw new Error("Unsupported platform: " + platform); throw new Error("Unsupported platform: " + platform);
} }

View File

@@ -1,93 +1,94 @@
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, 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", () => { test("UpdateManager detects local update", () => {
return tempd3(async (tmpDir, packagesDir, rootDir) => { return tempd3(async (tmpDir, packagesDir, rootDir) => {
VelopackApp.build() testInit();
.setLogger((level, msg) => { const locator: VelopackLocatorConfig = {
console.log(level, msg); ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec",
}) PackagesDir: packagesDir,
.run(); RootAppDir: rootDir,
const locator: VelopackLocatorConfig = { UpdateExePath: updateExe(),
ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec", CurrentBinaryDir: path.join(rootDir, "current"),
PackagesDir: packagesDir, IsPortable: true,
RootAppDir: rootDir, };
UpdateExePath: updateExe(),
CurrentBinaryDir: path.join(rootDir, "current"),
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",
); );
await shortDelay(); await shortDelay();
}); });
}); });
test("UpdateManager downloads full update", () => { test("UpdateManager downloads full update", () => {
return tempd3(async (feedDir, packagesDir, rootDir) => { return tempd3(async (feedDir, packagesDir, rootDir) => {
VelopackApp.build() testInit();
.setLogger((level, msg) => { const locator: VelopackLocatorConfig = {
console.log(level, msg); ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec",
}) PackagesDir: packagesDir,
.run(); RootAppDir: rootDir,
const locator: VelopackLocatorConfig = { UpdateExePath: updateExe(),
ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec", CurrentBinaryDir: path.join(rootDir, "current"),
PackagesDir: packagesDir, IsPortable: true,
RootAppDir: rootDir, };
UpdateExePath: updateExe(),
CurrentBinaryDir: path.join(rootDir, "current"),
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( expect(
existsSync(path.join(packagesDir, "AvaloniaCrossPlat-1.0.11-full.nupkg")), existsSync(path.join(packagesDir, "AvaloniaCrossPlat-1.0.11-full.nupkg")),
).toBe(true); ).toBe(true);
await shortDelay(); await shortDelay();
}); });
}); });

View File

@@ -1,4 +1,4 @@
import { VelopackApp, VelopackLocatorConfig } from "../src/index"; import { VelopackApp, VelopackLocatorConfig, setVelopackLogger } from "../src";
import { shortDelay, isWindows } from "./helper"; import { shortDelay, isWindows } from "./helper";
class HookTester { class HookTester {
@@ -37,7 +37,7 @@ class HookTester {
tester.firstRun = true; tester.firstRun = true;
tester.version = ver; tester.version = ver;
}); });
builder.setLogger((level, msg) => { setVelopackLogger((level, msg) => {
console.log(level, msg); console.log(level, msg);
}); });
return [builder, tester]; return [builder, tester];