You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

93 lines
2.8 KiB

/**
* @fileoverview iOS test runner for Capacitor-based mobile app
*
* This script handles the build and testing of the iOS app using Xcode's
* command-line tools. It ensures the app is properly synced with the latest
* web build and runs the test suite on a specified iOS simulator.
*
* Process flow:
* 1. Sync Capacitor project with latest web build
* 2. Build app for iOS simulator
* 3. Run XCTest suite
*
* Prerequisites:
* - macOS operating system
* - Xcode installed with command line tools
* - iOS simulator available
* - Capacitor iOS platform added to project
* - Valid iOS development certificates
*
* Exit codes:
* - 0: Tests completed successfully
* - 1: Build or test failure
*
* @example
* // Run directly
* node scripts/test-ios.js
*
* // Run via npm script
* npm run test:ios
*
* @requires child_process
* @requires path
*
* @author TimeSafari Team
* @license MIT
*/
const { execSync } = require('child_process');
const { join } = require('path');
/**
* Runs the complete iOS test suite including build and testing
*
* The function performs the following steps:
* 1. Syncs the Capacitor project with latest web build
* 2. Builds and tests the app using xcodebuild
*
* Note: This function requires a running iOS simulator. The test will
* fail if no simulator is available or if it's not in a booted state.
*
* @async
* @throws {Error} If any step in the build or test process fails
*
* @example
* runIosTests().catch(error => {
* console.error('Test execution failed:', error);
* process.exit(1);
* });
*/
async function runIosTests() {
try {
// Sync Capacitor project with latest web build
// This ensures the iOS project has the latest web assets
execSync('npx cap sync ios', {
stdio: 'inherit',
// Inherit stdio to show real-time output
});
// Build and run tests using xcodebuild
execSync(
'cd ios && xcodebuild test ' +
'-workspace App/App.xcworkspace ' + // Workspace containing the project
'-scheme App ' + // The scheme to build and test
'-destination "platform=iOS Simulator,name=iPhone 14"', // Target simulator
{
stdio: 'inherit',
// test: Builds and runs tests
// -workspace: Specifies the Xcode workspace
// -scheme: Specifies the scheme to test
// -destination: Specifies the target simulator
}
);
console.log('✅ iOS tests completed successfully');
} catch (error) {
// Log the error and exit with failure code
console.error('❌ iOS tests failed:', error);
process.exit(1);
}
}
// Execute the test suite
runIosTests();