@@ -6,17 +6,22 @@ import * as NodeOS from "node:os";
66import * as NodePath from "node:path" ;
77
88import { assert , describe , it } from "@effect/vitest" ;
9+ import * as HostProcess from "@t3tools/shared/HostProcess" ;
910import * as Effect from "effect/Effect" ;
1011import * as Exit from "effect/Exit" ;
1112import { vi } from "vite-plus/test" ;
1213import type { AppImageUpdater as AppImageUpdaterType } from "electron-updater" ;
1314
1415const { getUpdater } = vi . hoisted ( ( ) => ( { getUpdater : vi . fn < ( ) => AppImageUpdaterType > ( ) } ) ) ;
15- vi . mock ( "electron-updater" , ( ) => ( {
16- get autoUpdater ( ) {
17- return getUpdater ( ) ;
18- } ,
19- } ) ) ;
16+ vi . mock ( "electron-updater" , async ( importOriginal ) => {
17+ const { AppImageUpdater } = await importOriginal < typeof import ( "electron-updater" ) > ( ) ;
18+ return {
19+ AppImageUpdater,
20+ get autoUpdater ( ) {
21+ return getUpdater ( ) ;
22+ } ,
23+ } ;
24+ } ) ;
2025
2126import * as ElectronUpdater from "./ElectronUpdater.ts" ;
2227
@@ -40,15 +45,6 @@ class FixtureUpdater extends AppImageUpdater {
4045 override quitAndInstall ( isSilent = false , isForceRunAfter = false ) {
4146 this . doInstall ( { isSilent, isForceRunAfter, isAdminRightsRequired : false } ) ;
4247 }
43-
44- protected override spawnLog ( destination : string ) {
45- assert . equal (
46- NodeChildProcess . execFileSync ( process . env . APPIMAGE ! , { encoding : "utf8" } ) ,
47- "updated\n" ,
48- ) ;
49- assert . equal ( NodeChildProcess . execFileSync ( destination , { encoding : "utf8" } ) , "updated\n" ) ;
50- return Promise . resolve ( true ) ;
51- }
5248}
5349
5450function fixture ( oldName : string , newName : string ) {
@@ -64,6 +60,17 @@ function fixture(oldName: string, newName: string) {
6460 NodeFS . symlinkSync ( oldPath , launcher ) ;
6561 const updater = new FixtureUpdater ( download ) ;
6662 getUpdater . mockReturnValue ( updater ) ;
63+ const prototype = AppImageUpdater . prototype as unknown as {
64+ spawnLog : ( destination : string , args ?: Array < string > ) => Promise < boolean > ;
65+ } ;
66+ const spawnLog = vi . spyOn ( prototype , "spawnLog" ) . mockImplementation ( ( destination , args = [ ] ) => {
67+ assert . equal ( NodeChildProcess . execFileSync ( oldPath , { encoding : "utf8" } ) , "updated\n" ) ;
68+ assert . equal (
69+ NodeChildProcess . execFileSync ( destination , args , { encoding : "utf8" } ) ,
70+ "updated\n" ,
71+ ) ;
72+ return Promise . resolve ( true ) ;
73+ } ) ;
6774 const originalAppImage = process . env . APPIMAGE ;
6875 process . env . APPIMAGE = oldPath ;
6976 return {
@@ -74,6 +81,7 @@ function fixture(oldName: string, newName: string) {
7481 launcher,
7582 updater,
7683 [ Symbol . dispose ] ( ) {
84+ spawnLog . mockRestore ( ) ;
7785 if ( originalAppImage === undefined ) delete process . env . APPIMAGE ;
7886 else process . env . APPIMAGE = originalAppImage ;
7987 NodeFS . rmSync ( directory , { recursive : true , force : true } ) ;
@@ -98,10 +106,10 @@ describe.skipIf(process.platform !== "linux")("AppImage launch paths", () => {
98106 Effect . gen ( function * ( ) {
99107 using f = fixture ( "My T3-0.1.7.AppImage" , "T3-Code-x86_64.AppImage" ) ;
100108 yield * ElectronUpdater . make . quitAndInstall ( { isSilent : true , isForceRunAfter : true } ) ;
101- process . env . APPIMAGE = f . newPath ;
109+ const env = yield * HostProcess . Environment ;
110+ env . APPIMAGE = f . newPath ;
102111 const nextDownload = NodePath . join ( f . directory , "cache" , "T3-Code-x86_64.AppImage" ) ;
103112 NodeFS . writeFileSync ( nextDownload , "#!/bin/sh\necho updated\n" , { mode : 0o755 } ) ;
104- process . env . APPIMAGE = NodePath . join ( f . directory , "T3-Code-x86_64.AppImage" ) ;
105113 getUpdater . mockReturnValue ( new FixtureUpdater ( nextDownload ) ) ;
106114 yield * ElectronUpdater . make . quitAndInstall ( { isSilent : true , isForceRunAfter : true } ) ;
107115 assert . equal ( NodeChildProcess . execFileSync ( f . launcher , { encoding : "utf8" } ) , "updated\n" ) ;
0 commit comments