mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
update nodejs tests
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user