forked from trent_larson/crowd-funder-for-time-pwa
feat: Add comprehensive mobile testing infrastructure
- Add test scripts for Android and iOS platforms - Create prerequisite checker for mobile development setup - Add device/simulator availability checks - Update test-all command to include mobile tests - Add granular test commands for web and mobile The changes improve testing by: 1. Adding structured mobile test runners 2. Validating development environment setup 3. Separating web and mobile test flows 4. Adding device availability checks 5. Providing detailed test documentation Added scripts: - check-prerequisites.js: Validates dev environment - test-android.js: Runs Android tests - test-ios.js: Runs iOS tests - run-available-mobile-tests.js: Smart platform detection
This commit is contained in:
93
scripts/test-ios.js
Normal file
93
scripts/test-ios.js
Normal file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* @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();
|
||||
Reference in New Issue
Block a user