diff --git a/common/changes/@itwin/core-backend/travis-ios-tests-fix_2024-10-30-17-54.json b/common/changes/@itwin/core-backend/travis-ios-tests-fix_2024-10-30-17-54.json new file mode 100644 index 000000000000..99b35bb89b62 --- /dev/null +++ b/common/changes/@itwin/core-backend/travis-ios-tests-fix_2024-10-30-17-54.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@itwin/core-backend", + "comment": "", + "type": "none" + } + ], + "packageName": "@itwin/core-backend" +} \ No newline at end of file diff --git a/common/config/azure-pipelines/templates/core-build.yaml b/common/config/azure-pipelines/templates/core-build.yaml index bb6d4f404b90..179803019a2c 100644 --- a/common/config/azure-pipelines/templates/core-build.yaml +++ b/common/config/azure-pipelines/templates/core-build.yaml @@ -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 diff --git a/core/backend/runUnitTestsIosSimulator.ts b/core/backend/runUnitTestsIosSimulator.ts index f8802db23fcb..d8e8beaa2901 100644 --- a/core/backend/runUnitTestsIosSimulator.ts +++ b/core/backend/runUnitTestsIosSimulator.ts @@ -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; @@ -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 }); @@ -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) @@ -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() { @@ -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"); diff --git a/test-apps/display-test-app/runIosSimulator.ts b/test-apps/display-test-app/runIosSimulator.ts index 4928b555f978..940beb4cd114 100644 --- a/test-apps/display-test-app/runIosSimulator.ts +++ b/test-apps/display-test-app/runIosSimulator.ts @@ -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') { diff --git a/tools/internal/ios/core-test-runner/core-test-runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/tools/internal/ios/core-test-runner/core-test-runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 1c850dbbebe2..7dc6c64932ed 100644 --- a/tools/internal/ios/core-test-runner/core-test-runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/tools/internal/ios/core-test-runner/core-test-runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -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" } } ], diff --git a/tools/internal/ios/core-test-runner/core-test-runner/ViewController.swift b/tools/internal/ios/core-test-runner/core-test-runner/ViewController.swift index f929a3f4da25..4fb57dfc7a0a 100644 --- a/tools/internal/ios/core-test-runner/core-test-runner/ViewController.swift +++ b/tools/internal/ios/core-test-runner/core-test-runner/ViewController.swift @@ -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) @@ -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."