Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS tests fix (backport #7306) [release/4.9.x] #7307

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/core-backend",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/core-backend"
}
2 changes: 1 addition & 1 deletion common/config/azure-pipelines/templates/core-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ steps:
- script: npm run ios:all
workingDirectory: core/backend
displayName: Build & run iOS backend unit tests in Simulator
condition: and(succeeded(), ${{ parameters.buildMobile }}, eq(variables['Agent.OS'], 'Darwin'), false)
condition: and(succeeded(), ${{ parameters.buildMobile }}, eq(variables['Agent.OS'], 'Darwin'))

- script: node common/scripts/install-run-rush.js lint
displayName: rush lint
Expand Down
30 changes: 26 additions & 4 deletions core/backend/runUnitTestsIosSimulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import { createWriteStream } from "fs";
import { createWriteStream, copyFile } from "fs";

// Can't use import here otherwise Typescript complains: Could not find a declaration file for module 'node-simctl'.
const Simctl = require("node-simctl").default;
Expand All @@ -12,6 +12,7 @@ const Simctl = require("node-simctl").default;
const appName = "core-test-runner"
const bundleId = `com.bentley.${appName}`;
const xmlFilter = "[Mocha_Result_XML]: ";
const xmlFileFilter = "[Mocha_Result_XML_File]: ";

// Sort function that compares strings numerically from high to low
const numericCompareDescending = (a: string, b: string) => b.localeCompare(a, undefined, { numeric: true });
Expand Down Expand Up @@ -41,7 +42,7 @@ function log(message: string) {
console.log(message);
}

function extractXML(xmlFilter: string, inputLog: string, outputXmlFile: string) {
function extractXML(inputLog: string, outputXmlFile: string) {
const lines = inputLog.split(/\r?\n/)
const outputStream = createWriteStream(outputXmlFile)

Expand All @@ -55,7 +56,28 @@ function extractXML(xmlFilter: string, inputLog: string, outputXmlFile: string)
outputStream.write(cleanedXmlLine + "\n", "utf-8");
// console.log(cleanedXmlLine);
}
};
}
}

function copyXML(inputLog: string, outputXmlFile: string) {
const start = inputLog.indexOf(xmlFileFilter) + xmlFileFilter.length;
const end = inputLog.indexOf("\n", start);
const xmlFile = inputLog.substring(start, end);
copyFile(xmlFile, outputXmlFile, (/** @type {any} */ err) => {
if (err) {
console.log(err);
}
});
}

function extractOrCopyXML(inputLog: string, outputXmlFile: string) {
if (inputLog.includes(xmlFileFilter)) {
log(`Copying XML file.`);
copyXML(inputLog, outputXmlFile);
} else {
log(`Extracting XML from log.`);
extractXML(inputLog, outputXmlFile);
}
}

async function main() {
Expand Down Expand Up @@ -137,7 +159,7 @@ async function main() {
log("Failed.");
log(`launchOutput:\n${launchOutput}`);
}
extractXML(xmlFilter, launchOutput, `${__dirname}/lib/junit_results.xml`);
extractOrCopyXML(launchOutput, `${__dirname}/lib/junit_results.xml`);

// Shut down simulator
log("Shutting down simulator");
Expand Down
14 changes: 12 additions & 2 deletions test-apps/display-test-app/runIosSimulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@ const numericCompareDescending = (a: string, b: string) => b.localeCompare(a, un

// Similar to the launchApp function but doesn't retry, adds options before the launch command, and allows for args.
Simctl.prototype.launchAppWithOptions = async function (bundleId: string, options: [string], args: [string]) {
const { stdout } = await this.exec('launch', {
const { stdout, stderr } = await this.exec('launch', {
args: [...options, this.requireUdid('launch'), bundleId, ...args],
architectures: "x86_64",
});
return stdout.trim();
const trimmedOut = stdout.trim();
const trimmedErr = stderr.trim();
if (trimmedOut && trimmedErr) {
return `=========stdout=========\n${stdout.trim()}\n=========stderr=========\n${stderr.trim()}`;
} else if (trimmedOut) {
return `=========stdout=========\n${stdout.trim()}`;
} else if (trimmedErr) {
return `=========stderr=========\n${stderr.trim()}`;
} else {
return "";
}
}

Simctl.prototype.getLatestRuntimeVersion = async function (majorVersion: string, platform = 'iOS') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/iTwin/mobile-native-ios",
"state" : {
"revision" : "b365b0ca9fe2b16cddaf26f59e8f38148027608c",
"version" : "4.8.11"
"revision" : "7d0219150c7c67f85ed59c878cf47dd84df24895",
"version" : "4.9.35"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class ViewController: ObservableObject {
let main = URL(fileURLWithPath: mainPath)
log("(ios): Running tests.")
host.loadBackend(main, withAuthClient: nil, withInspect: true) { [self] (numFailed: UInt32) in
#if targetEnvironment(simulator)
log("[Mocha_Result_XML_File]: \(testResultsUrl.path)")
#else
log("(ios): Starting Mocha Result XML dump...")
do {
let text = try String(contentsOf: testResultsUrl, encoding: .utf8)
Expand All @@ -105,6 +108,7 @@ class ViewController: ObservableObject {
log("(ios): Failed to read mocha test results.")
}
log("(ios): Mocha Result XML dump complete.")
#endif

// Indicate via UI that the tests have finished.
self.testStatus = "Tests finished."
Expand Down
Loading