Test improvements: - Capture titles for all macOS windows, not just the frontmost. - Incorporate missing application log files. - Improve log clarity with enriched context. - Improve application termination on macOS by reducing grace period. - Ensure complete application termination on macOS. - Validate Vue application loading through an initial log. - Support ignoring environment-specific `stderr` errors. - Do not fail the test if working directory cannot be deleted. - Use retry pattern when installing dependencies due to network errors. Refactorings: - Migrate the test code to TypeScript. - Replace deprecated `rmdir` with `rm` for error-resistant directory removal. - Improve sanity checking by shifting from App.vue to Vue bootstrapper. - Centralize environment variable management with `EnvironmentVariables` construct. - Rename infrastructure/Environment to RuntimeEnvironment for clarity. - Isolate WindowVariables and SystemOperations from RuntimeEnvironment. - Inject logging via preloader. - Correct mislabeled RuntimeSanity tests. Configuration: - Introduce `npm run check:desktop` for simplified execution. - Omit `console.log` override due to `nodeIntegration` restrictions and reveal logging functionality using context-bridging.
73 lines
2.5 KiB
TypeScript
73 lines
2.5 KiB
TypeScript
import { logCurrentArgs, CommandLineFlag, hasCommandLineFlag } from './cli-args';
|
|
import { log, die } from './utils/log';
|
|
import { ensureNpmProjectDir, npmInstall, npmBuild } from './utils/npm';
|
|
import { clearAppLogFiles } from './app/app-logs';
|
|
import { checkForErrors } from './app/check-for-errors';
|
|
import { runApplication } from './app/runner.js';
|
|
import { CURRENT_PLATFORM, SupportedPlatform } from './utils/platform';
|
|
import { prepareLinuxApp } from './app/extractors/linux';
|
|
import { prepareWindowsApp } from './app/extractors/windows.js';
|
|
import { prepareMacOsApp } from './app/extractors/macos';
|
|
import {
|
|
DESKTOP_BUILD_COMMAND,
|
|
PROJECT_DIR,
|
|
DESKTOP_DIST_PATH,
|
|
APP_EXECUTION_DURATION_IN_SECONDS,
|
|
SCREENSHOT_PATH,
|
|
} from './config';
|
|
import { indentText } from './utils/text';
|
|
import { ExtractionResult } from './app/extractors/extraction-result';
|
|
|
|
export async function main(): Promise<void> {
|
|
logCurrentArgs();
|
|
await ensureNpmProjectDir(PROJECT_DIR);
|
|
await npmInstall(PROJECT_DIR);
|
|
await npmBuild(
|
|
PROJECT_DIR,
|
|
DESKTOP_BUILD_COMMAND,
|
|
DESKTOP_DIST_PATH,
|
|
hasCommandLineFlag(CommandLineFlag.ForceRebuild),
|
|
);
|
|
await clearAppLogFiles(PROJECT_DIR);
|
|
const {
|
|
stderr, stdout, isCrashed, windowTitles,
|
|
} = await extractAndRun();
|
|
if (stdout) {
|
|
log(`Output (stdout) from application execution:\n${indentText(stdout, 1)}`);
|
|
}
|
|
if (isCrashed) {
|
|
die('The application encountered an error during its execution.');
|
|
}
|
|
await checkForErrors(stderr, windowTitles, PROJECT_DIR);
|
|
log('🥳🎈 Success! Application completed without any runtime errors.');
|
|
process.exit(0);
|
|
}
|
|
|
|
async function extractAndRun() {
|
|
const extractors: {
|
|
readonly [K in SupportedPlatform]: () => Promise<ExtractionResult>;
|
|
} = {
|
|
[SupportedPlatform.macOS]: () => prepareMacOsApp(DESKTOP_DIST_PATH),
|
|
[SupportedPlatform.Linux]: () => prepareLinuxApp(DESKTOP_DIST_PATH),
|
|
[SupportedPlatform.Windows]: () => prepareWindowsApp(DESKTOP_DIST_PATH),
|
|
};
|
|
const extractor = extractors[CURRENT_PLATFORM];
|
|
if (!extractor) {
|
|
throw new Error(`Platform not supported: ${SupportedPlatform[CURRENT_PLATFORM]}`);
|
|
}
|
|
const { appExecutablePath, cleanup } = await extractor();
|
|
try {
|
|
return await runApplication(
|
|
appExecutablePath,
|
|
APP_EXECUTION_DURATION_IN_SECONDS,
|
|
hasCommandLineFlag(CommandLineFlag.TakeScreenshot),
|
|
SCREENSHOT_PATH,
|
|
);
|
|
} finally {
|
|
if (cleanup) {
|
|
log('Cleaning up post-execution resources...');
|
|
await cleanup();
|
|
}
|
|
}
|
|
}
|