Refactor to enforce strictNullChecks
This commit applies `strictNullChecks` to the entire codebase to improve maintainability and type safety. Key changes include: - Remove some explicit null-checks where unnecessary. - Add necessary null-checks. - Refactor static factory functions for a more functional approach. - Improve some test names and contexts for better debugging. - Add unit tests for any additional logic introduced. - Refactor `createPositionFromRegexFullMatch` to its own function as the logic is reused. - Prefer `find` prefix on functions that may return `undefined` and `get` prefix for those that always return a value.
This commit is contained in:
@@ -20,6 +20,7 @@ export function runApplication(
|
||||
|
||||
logDetails(appFile, executionDurationInSeconds);
|
||||
|
||||
const process = spawn(appFile);
|
||||
const processDetails: ApplicationProcessDetails = {
|
||||
stderrData: '',
|
||||
stdoutData: '',
|
||||
@@ -27,15 +28,15 @@ export function runApplication(
|
||||
windowTitles: [],
|
||||
isCrashed: false,
|
||||
isDone: false,
|
||||
process: undefined,
|
||||
process,
|
||||
resolve: () => { /* NOOP */ },
|
||||
};
|
||||
|
||||
const process = spawn(appFile);
|
||||
processDetails.process = process;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
processDetails.resolve = resolve;
|
||||
if (process.pid === undefined) {
|
||||
throw new Error('Unknown PID');
|
||||
}
|
||||
beginCapturingTitles(process.pid, processDetails);
|
||||
handleProcessEvents(
|
||||
processDetails,
|
||||
@@ -54,13 +55,14 @@ interface ApplicationExecutionResult {
|
||||
}
|
||||
|
||||
interface ApplicationProcessDetails {
|
||||
readonly process: ChildProcess;
|
||||
|
||||
stderrData: string;
|
||||
stdoutData: string;
|
||||
explicitlyKilled: boolean;
|
||||
windowTitles: Array<string>;
|
||||
isCrashed: boolean;
|
||||
isDone: boolean;
|
||||
process: ChildProcess;
|
||||
resolve: (value: ApplicationExecutionResult) => void;
|
||||
}
|
||||
|
||||
@@ -85,7 +87,7 @@ function beginCapturingTitles(
|
||||
const titles = await captureWindowTitles(processId);
|
||||
|
||||
(titles || []).forEach((title) => {
|
||||
if (!title?.length) {
|
||||
if (!title) {
|
||||
return;
|
||||
}
|
||||
if (!processDetails.windowTitles.includes(title)) {
|
||||
@@ -109,10 +111,10 @@ function handleProcessEvents(
|
||||
executionDurationInSeconds: number,
|
||||
): void {
|
||||
const { process } = processDetails;
|
||||
process.stderr.on('data', (data) => {
|
||||
process.stderr?.on('data', (data) => {
|
||||
processDetails.stderrData += data.toString();
|
||||
});
|
||||
process.stdout.on('data', (data) => {
|
||||
process.stdout?.on('data', (data) => {
|
||||
processDetails.stdoutData += data.toString();
|
||||
});
|
||||
|
||||
@@ -130,7 +132,7 @@ function handleProcessEvents(
|
||||
}
|
||||
|
||||
async function onProcessExit(
|
||||
code: number,
|
||||
code: number | null,
|
||||
processDetails: ApplicationProcessDetails,
|
||||
enableScreenshot: boolean,
|
||||
screenshotPath: string,
|
||||
|
||||
Reference in New Issue
Block a user