Skip to content

Commit

Permalink
chore(lauchIOS): wait for xcode record with a promise
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeEgret committed Aug 2, 2023
1 parent c61b291 commit d9d0981
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions packages/ios-poc/src/launchIOS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { program } from "commander";
import { execSync, exec } from "child_process";
import os from "os";

const DURATION = 10;

const tmpFiles: string[] = [];
const removeTmpFiles = () => {
for (const tmpFile of tmpFiles) {
Expand All @@ -29,22 +27,27 @@ const writeTmpFile = (fileName: string, content: string): string => {
return tmpPath;
};

const executeAsyncCommand = (command: string): void => {
exec(command, (error, stdout, stderr) => {
if (error) {
console.log(`Ah, quel dommage! An error occurred: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
const executeAsyncCommand = (command: string): Promise<void> => {
return new Promise<void>((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
console.log(`Ah, quel dommage! An error occurred: ${error.message}`);
reject();
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
resolve();
return;
}
console.log(`stdout: ${stdout}`);
resolve();
});
});
};

const startRecord = (simulatorId: string, traceFile: string) => {
executeAsyncCommand(
const startRecord = (simulatorId: string, traceFile: string): Promise<void> => {
return executeAsyncCommand(
`xcrun xctrace record --device ${simulatorId} --template Flashlight --attach 'fakeStore' --output ${traceFile}`
);
};
Expand All @@ -57,7 +60,7 @@ const save = (traceFile: string, resultsFilePath: string) => {
writeReport(xmlOutputFile, resultsFilePath);
};

const launchTest = ({
const launchTest = async ({
testCommand,
appId,
simulatorId,
Expand All @@ -79,11 +82,11 @@ const launchTest = ({
execSync(`maestro test ${lauchAppFile} --no-ansi`, {
stdio: "inherit",
});
startRecord(simulatorId, traceFile);
const recordingPromise = startRecord(simulatorId, traceFile);

execSync(`${testCommand} --no-ansi`, {
stdio: "inherit",
});
execSync(`sleep ${DURATION}`);
const stopAppFile = writeTmpFile(
"./stop.yaml",
`appId: ${appId}
Expand All @@ -94,6 +97,7 @@ const launchTest = ({
execSync(`maestro test ${stopAppFile} --no-ansi`, {
stdio: "inherit",
});
await recordingPromise;
save(traceFile, resultsFilePath);

removeTmpFiles();
Expand Down

0 comments on commit d9d0981

Please sign in to comment.