2025-09-17 13:05:40 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { vi } from 'vitest';
|
2026-03-03 22:18:12 -08:00
|
|
|
import {
|
|
|
|
|
RELAUNCH_EXIT_CODE,
|
|
|
|
|
relaunchApp,
|
|
|
|
|
_resetRelaunchStateForTesting,
|
|
|
|
|
} from './processUtils.js';
|
2025-09-17 13:05:40 -07:00
|
|
|
import * as cleanup from './cleanup.js';
|
2026-03-03 09:18:29 -08:00
|
|
|
import * as handleAutoUpdate from './handleAutoUpdate.js';
|
|
|
|
|
|
|
|
|
|
vi.mock('./handleAutoUpdate.js', () => ({
|
|
|
|
|
waitForUpdateCompletion: vi.fn().mockResolvedValue(undefined),
|
|
|
|
|
}));
|
2025-09-17 13:05:40 -07:00
|
|
|
|
|
|
|
|
describe('processUtils', () => {
|
|
|
|
|
const processExit = vi
|
|
|
|
|
.spyOn(process, 'exit')
|
|
|
|
|
.mockReturnValue(undefined as never);
|
|
|
|
|
const runExitCleanup = vi.spyOn(cleanup, 'runExitCleanup');
|
|
|
|
|
|
2026-03-03 22:18:12 -08:00
|
|
|
beforeEach(() => {
|
|
|
|
|
_resetRelaunchStateForTesting();
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-03 09:18:29 -08:00
|
|
|
afterEach(() => vi.clearAllMocks());
|
|
|
|
|
|
|
|
|
|
it('should wait for updates, run cleanup, and exit with the relaunch code', async () => {
|
2025-09-17 13:05:40 -07:00
|
|
|
await relaunchApp();
|
2026-03-03 09:18:29 -08:00
|
|
|
expect(handleAutoUpdate.waitForUpdateCompletion).toHaveBeenCalledTimes(1);
|
2025-09-17 13:05:40 -07:00
|
|
|
expect(runExitCleanup).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(processExit).toHaveBeenCalledWith(RELAUNCH_EXIT_CODE);
|
|
|
|
|
});
|
|
|
|
|
});
|