Improve desktop runtime execution tests
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.
This commit is contained in:
@@ -3,6 +3,8 @@ import { IconBootstrapper } from './Modules/IconBootstrapper';
|
||||
import { VueConstructor, IVueBootstrapper } from './IVueBootstrapper';
|
||||
import { VueBootstrapper } from './Modules/VueBootstrapper';
|
||||
import { TooltipBootstrapper } from './Modules/TooltipBootstrapper';
|
||||
import { RuntimeSanityValidator } from './Modules/RuntimeSanityValidator';
|
||||
import { AppInitializationLogger } from './Modules/AppInitializationLogger';
|
||||
|
||||
export class ApplicationBootstrapper implements IVueBootstrapper {
|
||||
public bootstrap(vue: VueConstructor): void {
|
||||
@@ -18,6 +20,8 @@ export class ApplicationBootstrapper implements IVueBootstrapper {
|
||||
new TreeBootstrapper(),
|
||||
new VueBootstrapper(),
|
||||
new TooltipBootstrapper(),
|
||||
new RuntimeSanityValidator(),
|
||||
new AppInitializationLogger(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
25
src/presentation/bootstrapping/ClientLoggerFactory.ts
Normal file
25
src/presentation/bootstrapping/ClientLoggerFactory.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { RuntimeEnvironment } from '@/infrastructure/RuntimeEnvironment/RuntimeEnvironment';
|
||||
import { IRuntimeEnvironment } from '@/infrastructure/RuntimeEnvironment/IRuntimeEnvironment';
|
||||
import { ConsoleLogger } from '@/infrastructure/Log/ConsoleLogger';
|
||||
import { ILogger } from '@/infrastructure/Log/ILogger';
|
||||
import { ILoggerFactory } from '@/infrastructure/Log/ILoggerFactory';
|
||||
import { NoopLogger } from '@/infrastructure/Log/NoopLogger';
|
||||
import { WindowInjectedLogger } from '@/infrastructure/Log/WindowInjectedLogger';
|
||||
|
||||
export class ClientLoggerFactory implements ILoggerFactory {
|
||||
public static readonly Current: ILoggerFactory = new ClientLoggerFactory();
|
||||
|
||||
public readonly logger: ILogger;
|
||||
|
||||
protected constructor(environment: IRuntimeEnvironment = RuntimeEnvironment.CurrentEnvironment) {
|
||||
if (environment.isDesktop) {
|
||||
this.logger = new WindowInjectedLogger();
|
||||
return;
|
||||
}
|
||||
if (environment.isNonProduction) {
|
||||
this.logger = new ConsoleLogger();
|
||||
return;
|
||||
}
|
||||
this.logger = new NoopLogger();
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,15 @@ import { InjectionKey, provide } from 'vue';
|
||||
import { useCollectionState } from '@/presentation/components/Shared/Hooks/UseCollectionState';
|
||||
import { useApplication } from '@/presentation/components/Shared/Hooks/UseApplication';
|
||||
import {
|
||||
useCollectionStateKey, useApplicationKey, useEnvironmentKey,
|
||||
useCollectionStateKey, useApplicationKey, useRuntimeEnvironmentKey,
|
||||
} from '@/presentation/injectionSymbols';
|
||||
import { IApplicationContext } from '@/application/Context/IApplicationContext';
|
||||
import { Environment } from '@/infrastructure/Environment/Environment';
|
||||
import { RuntimeEnvironment } from '@/infrastructure/RuntimeEnvironment/RuntimeEnvironment';
|
||||
|
||||
export function provideDependencies(context: IApplicationContext) {
|
||||
registerSingleton(useApplicationKey, useApplication(context.app));
|
||||
registerTransient(useCollectionStateKey, () => useCollectionState(context));
|
||||
registerSingleton(useEnvironmentKey, Environment.CurrentEnvironment);
|
||||
registerSingleton(useRuntimeEnvironmentKey, RuntimeEnvironment.CurrentEnvironment);
|
||||
}
|
||||
|
||||
function registerSingleton<T>(
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { ILogger } from '@/infrastructure/Log/ILogger';
|
||||
import { IVueBootstrapper } from '../IVueBootstrapper';
|
||||
import { ClientLoggerFactory } from '../ClientLoggerFactory';
|
||||
|
||||
export class AppInitializationLogger implements IVueBootstrapper {
|
||||
constructor(
|
||||
private readonly logger: ILogger = ClientLoggerFactory.Current.logger,
|
||||
) { }
|
||||
|
||||
public bootstrap(): void {
|
||||
// Do not remove [APP_INIT]; it's a marker used in tests.
|
||||
this.logger.info('[APP_INIT] Application is initialized.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { validateRuntimeSanity } from '@/infrastructure/RuntimeSanity/SanityChecks';
|
||||
import { IVueBootstrapper } from '../IVueBootstrapper';
|
||||
|
||||
export class RuntimeSanityValidator implements IVueBootstrapper {
|
||||
constructor(private readonly validator = validateRuntimeSanity) {
|
||||
|
||||
}
|
||||
|
||||
public bootstrap(): void {
|
||||
this.validator({
|
||||
validateEnvironmentVariables: true,
|
||||
validateWindowVariables: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ import TheCodeButtons from '@/presentation/components/Code/CodeButtons/TheCodeBu
|
||||
import TheScriptArea from '@/presentation/components/Scripts/TheScriptArea.vue';
|
||||
import TheSearchBar from '@/presentation/components/TheSearchBar.vue';
|
||||
import { buildContext } from '@/application/Context/ApplicationContextFactory';
|
||||
import { validateRuntimeSanity } from '@/infrastructure/RuntimeSanity/SanityChecks';
|
||||
import { provideDependencies } from '../bootstrapping/DependencyProvider';
|
||||
|
||||
const singletonAppContext = await buildContext();
|
||||
@@ -33,10 +32,6 @@ export default defineComponent({
|
||||
},
|
||||
setup() {
|
||||
provideDependencies(singletonAppContext); // In Vue 3.0 we can move it to main.ts
|
||||
validateRuntimeSanity({
|
||||
validateMetadata: true,
|
||||
validateEnvironment: true,
|
||||
});
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -29,11 +29,10 @@
|
||||
import {
|
||||
defineComponent, ref, computed, inject,
|
||||
} from 'vue';
|
||||
import { useCollectionStateKey, useEnvironmentKey } from '@/presentation/injectionSymbols';
|
||||
import { useCollectionStateKey, useRuntimeEnvironmentKey } from '@/presentation/injectionSymbols';
|
||||
import { SaveFileDialog, FileType } from '@/infrastructure/SaveFileDialog';
|
||||
import { Clipboard } from '@/infrastructure/Clipboard';
|
||||
import ModalDialog from '@/presentation/components/Shared/Modal/ModalDialog.vue';
|
||||
import { Environment } from '@/infrastructure/Environment/Environment';
|
||||
import { IReadOnlyCategoryCollectionState } from '@/application/Context/State/ICategoryCollectionState';
|
||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||
import { IApplicationCode } from '@/application/Context/State/Code/IApplicationCode';
|
||||
@@ -56,10 +55,10 @@ export default defineComponent({
|
||||
const {
|
||||
currentState, currentContext, onStateChange, events,
|
||||
} = inject(useCollectionStateKey)();
|
||||
const { isDesktop } = inject(useEnvironmentKey);
|
||||
const { os, isDesktop } = inject(useRuntimeEnvironmentKey);
|
||||
|
||||
const areInstructionsVisible = ref(false);
|
||||
const canRun = computed<boolean>(() => getCanRunState(currentState.value.os, isDesktop));
|
||||
const canRun = computed<boolean>(() => getCanRunState(currentState.value.os, isDesktop, os));
|
||||
const fileName = computed<string>(() => buildFileName(currentState.value.collection.scripting));
|
||||
const hasCode = ref(false);
|
||||
const instructions = computed<IInstructionListData | undefined>(() => getDownloadInstructions(
|
||||
@@ -122,8 +121,12 @@ function getDownloadInstructions(
|
||||
return getInstructions(os, fileName);
|
||||
}
|
||||
|
||||
function getCanRunState(selectedOs: OperatingSystem, isDesktopVersion: boolean): boolean {
|
||||
const isRunningOnSelectedOs = selectedOs === Environment.CurrentEnvironment.os;
|
||||
function getCanRunState(
|
||||
selectedOs: OperatingSystem,
|
||||
isDesktopVersion: boolean,
|
||||
hostOs: OperatingSystem,
|
||||
): boolean {
|
||||
const isRunningOnSelectedOs = selectedOs === hostOs;
|
||||
return isDesktopVersion && isRunningOnSelectedOs;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import { IEnvironment } from '@/infrastructure/Environment/IEnvironment';
|
||||
|
||||
export function useEnvironment(environment: IEnvironment) {
|
||||
if (!environment) {
|
||||
throw new Error('missing environment');
|
||||
}
|
||||
return environment;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { IRuntimeEnvironment } from '@/infrastructure/RuntimeEnvironment/IRuntimeEnvironment';
|
||||
|
||||
export function useRuntimeEnvironment(environment: IRuntimeEnvironment) {
|
||||
if (!environment) {
|
||||
throw new Error('missing environment');
|
||||
}
|
||||
return environment;
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, inject } from 'vue';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { useEnvironmentKey } from '@/presentation/injectionSymbols';
|
||||
import { useRuntimeEnvironmentKey } from '@/presentation/injectionSymbols';
|
||||
import DownloadUrlListItem from './DownloadUrlListItem.vue';
|
||||
|
||||
const supportedOperativeSystems: readonly OperatingSystem[] = [
|
||||
@@ -34,7 +34,7 @@ export default defineComponent({
|
||||
DownloadUrlListItem,
|
||||
},
|
||||
setup() {
|
||||
const { os: currentOs } = inject(useEnvironmentKey);
|
||||
const { os: currentOs } = inject(useRuntimeEnvironmentKey);
|
||||
const supportedDesktops = [
|
||||
...supportedOperativeSystems,
|
||||
].sort((os) => (os === currentOs ? 0 : 1));
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
defineComponent, PropType, computed,
|
||||
inject,
|
||||
} from 'vue';
|
||||
import { useApplicationKey, useEnvironmentKey } from '@/presentation/injectionSymbols';
|
||||
import { useApplicationKey, useRuntimeEnvironmentKey } from '@/presentation/injectionSymbols';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
export default defineComponent({
|
||||
@@ -26,7 +26,7 @@ export default defineComponent({
|
||||
},
|
||||
setup(props) {
|
||||
const { info } = inject(useApplicationKey);
|
||||
const { os: currentOs } = inject(useEnvironmentKey);
|
||||
const { os: currentOs } = inject(useRuntimeEnvironmentKey);
|
||||
|
||||
const isCurrentOs = computed<boolean>(() => {
|
||||
return currentOs === props.operatingSystem;
|
||||
|
||||
@@ -42,12 +42,12 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, computed, inject } from 'vue';
|
||||
import { useApplicationKey, useEnvironmentKey } from '@/presentation/injectionSymbols';
|
||||
import { useApplicationKey, useRuntimeEnvironmentKey } from '@/presentation/injectionSymbols';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
const { info } = inject(useApplicationKey);
|
||||
const { isDesktop } = inject(useEnvironmentKey);
|
||||
const { isDesktop } = inject(useRuntimeEnvironmentKey);
|
||||
|
||||
const repositoryUrl = computed<string>(() => info.repositoryUrl);
|
||||
const feedbackUrl = computed<string>(() => info.feedbackUrl);
|
||||
|
||||
@@ -48,7 +48,7 @@ import {
|
||||
defineComponent, ref, computed, inject,
|
||||
} from 'vue';
|
||||
import ModalDialog from '@/presentation/components/Shared/Modal/ModalDialog.vue';
|
||||
import { useApplicationKey, useEnvironmentKey } from '@/presentation/injectionSymbols';
|
||||
import { useApplicationKey, useRuntimeEnvironmentKey } from '@/presentation/injectionSymbols';
|
||||
import DownloadUrlList from './DownloadUrlList.vue';
|
||||
import PrivacyPolicy from './PrivacyPolicy.vue';
|
||||
|
||||
@@ -60,7 +60,7 @@ export default defineComponent({
|
||||
},
|
||||
setup() {
|
||||
const { info } = inject(useApplicationKey);
|
||||
const { isDesktop } = inject(useEnvironmentKey);
|
||||
const { isDesktop } = inject(useRuntimeEnvironmentKey);
|
||||
|
||||
const isPrivacyDialogVisible = ref(false);
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import log from 'electron-log';
|
||||
import fetch from 'cross-fetch';
|
||||
import { ProjectInformation } from '@/domain/ProjectInformation';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { ViteAppMetadata } from '@/infrastructure/Metadata/Vite/ViteAppMetadata';
|
||||
import { Version } from '@/domain/Version';
|
||||
import { parseProjectInformation } from '@/application/Parser/ProjectInformationParser';
|
||||
import { UpdateProgressBar } from './UpdateProgressBar';
|
||||
@@ -29,7 +28,7 @@ export async function handleManualUpdate(info: UpdateInfo) {
|
||||
}
|
||||
|
||||
function getTargetProject(targetVersion: string) {
|
||||
const existingProject = parseProjectInformation(new ViteAppMetadata());
|
||||
const existingProject = parseProjectInformation();
|
||||
const targetProject = new ProjectInformation(
|
||||
existingProject.name,
|
||||
new Version(targetVersion),
|
||||
|
||||
@@ -25,11 +25,11 @@ protocol.registerSchemesAsPrivileged([
|
||||
setupLogger();
|
||||
validateRuntimeSanity({
|
||||
// Metadata is used by manual updates.
|
||||
validateMetadata: true,
|
||||
validateEnvironmentVariables: true,
|
||||
|
||||
// Environment is populated by the preload script and is in the renderer's context;
|
||||
// it's not directly accessible from the main process.
|
||||
validateEnvironment: false,
|
||||
validateWindowVariables: false,
|
||||
});
|
||||
|
||||
function createWindow() {
|
||||
@@ -151,7 +151,4 @@ function getWindowSize(idealWidth: number, idealHeight: number) {
|
||||
|
||||
function setupLogger(): void {
|
||||
log.transports.file.level = 'silly';
|
||||
if (!isDevelopment) {
|
||||
Object.assign(console, log.functions); // override console.log, console.warn etc.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import { createNodeSystemOperations } from '@/infrastructure/Environment/SystemOperations/NodeSystemOperations';
|
||||
import { WindowVariables } from '@/infrastructure/Environment/WindowVariables';
|
||||
import log from 'electron-log';
|
||||
import { createNodeSystemOperations } from '@/infrastructure/SystemOperations/NodeSystemOperations';
|
||||
import { createElectronLogger } from '@/infrastructure/Log/ElectronLogger';
|
||||
import { ILogger } from '@/infrastructure/Log/ILogger';
|
||||
import { WindowVariables } from '@/infrastructure/WindowVariables/WindowVariables';
|
||||
import { convertPlatformToOs } from './NodeOsMapper';
|
||||
|
||||
export function provideWindowVariables(
|
||||
createSystem = createNodeSystemOperations,
|
||||
createLogger: () => ILogger = () => createElectronLogger(log),
|
||||
convertToOs = convertPlatformToOs,
|
||||
): WindowVariables {
|
||||
return {
|
||||
system: createSystem(),
|
||||
isDesktop: true,
|
||||
log: createLogger(),
|
||||
os: convertToOs(process.platform),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ import { provideWindowVariables } from './WindowVariablesProvider';
|
||||
validateRuntimeSanity({
|
||||
// Validate metadata as a preventive measure for fail-fast,
|
||||
// even if it's not currently used in the preload script.
|
||||
validateMetadata: true,
|
||||
validateEnvironmentVariables: true,
|
||||
|
||||
// The preload script cannot access variables on the window object.
|
||||
validateEnvironment: false,
|
||||
validateWindowVariables: false,
|
||||
});
|
||||
|
||||
const windowVariables = provideWindowVariables();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { useCollectionState } from '@/presentation/components/Shared/Hooks/UseCollectionState';
|
||||
import { useApplication } from '@/presentation/components/Shared/Hooks/UseApplication';
|
||||
import { useEnvironment } from '@/presentation/components/Shared/Hooks/UseEnvironment';
|
||||
import { useRuntimeEnvironment } from '@/presentation/components/Shared/Hooks/UseRuntimeEnvironment';
|
||||
import type { InjectionKey } from 'vue';
|
||||
|
||||
export const useCollectionStateKey = defineTransientKey<ReturnType<typeof useCollectionState>>('useCollectionState');
|
||||
export const useApplicationKey = defineSingletonKey<ReturnType<typeof useApplication>>('useApplication');
|
||||
export const useEnvironmentKey = defineSingletonKey<ReturnType<typeof useEnvironment>>('useEnvironment');
|
||||
export const useRuntimeEnvironmentKey = defineSingletonKey<ReturnType<typeof useRuntimeEnvironment>>('useRuntimeEnvironment');
|
||||
|
||||
function defineSingletonKey<T>(key: string) {
|
||||
return Symbol(key) as InjectionKey<T>;
|
||||
|
||||
Reference in New Issue
Block a user