mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
More nodejs tests
This commit is contained in:
24
src/lib-nodejs/package-lock.json
generated
24
src/lib-nodejs/package-lock.json
generated
@@ -2624,6 +2624,18 @@
|
|||||||
"url": "https://github.com/sindresorhus/execa?sponsor=1"
|
"url": "https://github.com/sindresorhus/execa?sponsor=1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/execa/node_modules/is-stream": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==",
|
||||||
|
"dev": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/exit": {
|
"node_modules/exit": {
|
||||||
"version": "0.1.2",
|
"version": "0.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz",
|
||||||
@@ -3107,18 +3119,6 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/is-stream": {
|
|
||||||
"version": "2.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz",
|
|
||||||
"integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==",
|
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"url": "https://github.com/sponsors/sindresorhus"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/isexe": {
|
"node_modules/isexe": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ export class UpdateManager {
|
|||||||
*/
|
*/
|
||||||
downloadUpdateAsync(
|
downloadUpdateAsync(
|
||||||
update: UpdateInfo,
|
update: UpdateInfo,
|
||||||
progress: (perc: number) => void,
|
progress?: (perc: number) => void,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!update) {
|
if (!update) {
|
||||||
throw new Error("update is required");
|
throw new Error("update is required");
|
||||||
|
|||||||
69
src/lib-nodejs/test/UpdateManager.test.ts
Normal file
69
src/lib-nodejs/test/UpdateManager.test.ts
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import { copyFileSync, existsSync } from "fs";
|
||||||
|
import { UpdateManager, UpdateOptions, VelopackLocator } from "../src";
|
||||||
|
import path from "path";
|
||||||
|
import { tempd3, fixture, updateExe } from "./helper";
|
||||||
|
|
||||||
|
test("UpdateManager detects local update", () => {
|
||||||
|
return tempd3(async (tmpDir, packagesDir, rootDir) => {
|
||||||
|
const locator: VelopackLocator = {
|
||||||
|
ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec",
|
||||||
|
PackagesDir: packagesDir,
|
||||||
|
RootAppDir: rootDir,
|
||||||
|
UpdateExePath: updateExe(),
|
||||||
|
};
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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", () => {
|
||||||
|
return tempd3(async (feedDir, packagesDir, rootDir) => {
|
||||||
|
|
||||||
|
const locator: VelopackLocator = {
|
||||||
|
ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec",
|
||||||
|
PackagesDir: packagesDir,
|
||||||
|
RootAppDir: rootDir,
|
||||||
|
UpdateExePath: updateExe(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const options: UpdateOptions = {
|
||||||
|
ExplicitChannel: "beta",
|
||||||
|
AllowVersionDowngrade: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
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"),
|
||||||
|
);
|
||||||
|
|
||||||
|
const update = await um.checkForUpdatesAsync();
|
||||||
|
await um.downloadUpdateAsync(update!, () => { });
|
||||||
|
|
||||||
|
expect(
|
||||||
|
existsSync(path.join(packagesDir, "AvaloniaCrossPlat-1.0.11-full.nupkg")),
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
94
src/lib-nodejs/test/helper.ts
Normal file
94
src/lib-nodejs/test/helper.ts
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import fs from "node:fs";
|
||||||
|
import os from "node:os";
|
||||||
|
import path from "node:path";
|
||||||
|
|
||||||
|
export function getTempDir(): string {
|
||||||
|
return fs.realpathSync(os.tmpdir());
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fixture(name: string): string {
|
||||||
|
return path.join("..", "..", "test", "fixtures", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function makeId(length: number): string {
|
||||||
|
let result = "";
|
||||||
|
const characters =
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
const charactersLength = characters.length;
|
||||||
|
let counter = 0;
|
||||||
|
while (counter < length) {
|
||||||
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||||
|
counter += 1;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tempd1<T>(cb: (dir: string) => T): T {
|
||||||
|
const id = makeId(10);
|
||||||
|
const dir = path.join(os.tmpdir(), id);
|
||||||
|
fs.mkdirSync(dir);
|
||||||
|
try {
|
||||||
|
return cb(dir);
|
||||||
|
} finally {
|
||||||
|
fs.rmSync(dir, { recursive: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tempd2<T>(cb: (dir1: string, dir2: string) => T): T {
|
||||||
|
const dir1 = path.join(os.tmpdir(), makeId(10));
|
||||||
|
const dir2 = path.join(os.tmpdir(), makeId(10));
|
||||||
|
fs.mkdirSync(dir1);
|
||||||
|
fs.mkdirSync(dir2);
|
||||||
|
try {
|
||||||
|
return cb(dir1, dir2);
|
||||||
|
} finally {
|
||||||
|
fs.rmSync(dir1, { recursive: true });
|
||||||
|
fs.rmSync(dir2, { recursive: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tempd3<T>(
|
||||||
|
cb: (dir1: string, dir2: string, dir3: string) => T,
|
||||||
|
): T {
|
||||||
|
const dir1 = path.join(os.tmpdir(), makeId(10));
|
||||||
|
const dir2 = path.join(os.tmpdir(), makeId(10));
|
||||||
|
const dir3 = path.join(os.tmpdir(), makeId(10));
|
||||||
|
fs.mkdirSync(dir1);
|
||||||
|
fs.mkdirSync(dir2);
|
||||||
|
fs.mkdirSync(dir3);
|
||||||
|
try {
|
||||||
|
return cb(dir1, dir2, dir3);
|
||||||
|
} finally {
|
||||||
|
fs.rmSync(dir1, { recursive: true });
|
||||||
|
fs.rmSync(dir2, { recursive: true });
|
||||||
|
fs.rmSync(dir3, { recursive: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateExe(): string {
|
||||||
|
const paths = [
|
||||||
|
path.join("..", "..", "target", "debug", "Update.exe"),
|
||||||
|
path.join("..", "..", "target", "release", "Update.exe"),
|
||||||
|
path.join("..", "..", "target", "debug", "update"),
|
||||||
|
path.join("..", "..", "target", "release", "update"),
|
||||||
|
path.join("..", "..", "target", "debug", "UpdateMac"),
|
||||||
|
path.join("..", "..", "target", "release", "UpdateMac"),
|
||||||
|
path.join("..", "..", "target", "debug", "UpdateNix"),
|
||||||
|
path.join("..", "..", "target", "release", "UpdateNix"),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const p of paths) {
|
||||||
|
if (fs.existsSync(p)) {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error("Update.exe not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
// export function copyUpdateExeTo(dir: string, filename?: string): string {
|
||||||
|
// const exe = updateExe();
|
||||||
|
// const dest = path.join(dir, filename ?? path.basename(exe));
|
||||||
|
// fs.copyFileSync(exe, dest);
|
||||||
|
// return dest;
|
||||||
|
// }
|
||||||
@@ -43,7 +43,7 @@ class HookTester {
|
|||||||
test("VelopackApp should handle restarted event", () => {
|
test("VelopackApp should handle restarted event", () => {
|
||||||
let [builder, tester] = HookTester.build();
|
let [builder, tester] = HookTester.build();
|
||||||
let locator: VelopackLocator = {
|
let locator: VelopackLocator = {
|
||||||
ManifestPath: "../../test/fixtures/FullNuspec.nuspec",
|
ManifestPath: "../../test/fixtures/Test.Squirrel-App.nuspec",
|
||||||
PackagesDir: "",
|
PackagesDir: "",
|
||||||
RootAppDir: "",
|
RootAppDir: "",
|
||||||
UpdateExePath: "",
|
UpdateExePath: "",
|
||||||
@@ -59,26 +59,6 @@ test("VelopackApp should handle restarted event", () => {
|
|||||||
expect(tester.version).toBe("1.0.0");
|
expect(tester.version).toBe("1.0.0");
|
||||||
});
|
});
|
||||||
|
|
||||||
// test("VelopackApp should handle firstrun event with custom locator", () => {
|
|
||||||
// let [builder, tester] = HookTester.build();
|
|
||||||
|
|
||||||
// let locator: VelopackLocator = {
|
|
||||||
// ManifestPath: "../../test/fixtures/FullNuspec.nuspec",
|
|
||||||
// PackagesDir: "",
|
|
||||||
// RootAppDir: "",
|
|
||||||
// UpdateExePath: "",
|
|
||||||
// };
|
|
||||||
// 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(false);
|
|
||||||
// expect(tester.firstRun).toBe(true);
|
|
||||||
// expect(tester.version).toBe("1.0.0");
|
|
||||||
// });
|
|
||||||
|
|
||||||
test("VelopackApp should handle after-install hook", () => {
|
test("VelopackApp should handle after-install hook", () => {
|
||||||
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();
|
||||||
|
|||||||
@@ -125,7 +125,13 @@ impl<'a> VelopackApp<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let my_version = if let Ok(ver) = self.get_current_version() { ver } else { semver::Version::new(0, 0, 0) };
|
let my_version = match self.get_current_version() {
|
||||||
|
Ok(ver) => ver,
|
||||||
|
Err(e) => {
|
||||||
|
warn!("VelopackApp: Error getting current version: {}", e);
|
||||||
|
semver::Version::new(0, 0, 0)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let firstrun = env::var("VELOPACK_FIRSTRUN").is_ok();
|
let firstrun = env::var("VELOPACK_FIRSTRUN").is_ok();
|
||||||
let restarted = env::var("VELOPACK_RESTART").is_ok();
|
let restarted = env::var("VELOPACK_RESTART").is_ok();
|
||||||
|
|||||||
18
test/fixtures/Test.Squirrel-App.nuspec
vendored
Normal file
18
test/fixtures/Test.Squirrel-App.nuspec
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||||
|
<metadata>
|
||||||
|
<id>Test.Squirrel-App</id>
|
||||||
|
<title>Test Squirrel App</title>
|
||||||
|
<description>Test Squirrel App</description>
|
||||||
|
<authors>author</authors>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<channel>asd123</channel>
|
||||||
|
<mainExe>testawareapp.exe</mainExe>
|
||||||
|
<os>win</os>
|
||||||
|
<rid>win-x64</rid>
|
||||||
|
<osMinVersion>10.0.19043</osMinVersion>
|
||||||
|
<machineArchitecture>x64</machineArchitecture>
|
||||||
|
|
||||||
|
<runtimeDependencies>net6-x64-desktop</runtimeDependencies>
|
||||||
|
</metadata>
|
||||||
|
</package>
|
||||||
Reference in New Issue
Block a user