E2E & Integration Testing
Relevant source files
The following files were used as context for generating this wiki page:
The Duplicator project employs a multi-layered testing strategy to ensure the reliability of its cross-platform Electron application and integrated server environment. This strategy includes End-to-End (E2E) tests to validate the user interface and IPC communication, and Integration tests to verify the coordination between the Caddy web server and the PHP-FPM backend.
The testing infrastructure is built primarily on Jest as the test runner, with Spectron for Electron automation and Supertest for HTTP-based integration verification.
Sources: package.json:34-40, tests/e2e/electron-app.test.js:1-10
Test Infrastructure & Configuration
The testing environment is globally configured to handle the specific requirements of an Electron app that manages background processes.
Global Setup and Helpers
The tests/setup.js file defines global paths and ports to ensure consistency across different test suites. It also provides utility functions for file management during tests.
The system uses a standardized set of ports and timeouts to prevent conflicts during parallel execution and to accommodate the startup time of spawned processes.
| Parameter | Value | Description |
|---|---|---|
jest.setTimeout | 30000ms | Default timeout for long-running E2E and server starts |
global.testPorts.caddy | 8001 | Port used for integration server testing |
global.testPorts.php | 8002 | Port used for PHP backend testing |
Sources: tests/setup.js:4-20, tests/helpers/test-utils.js:4-15
End-to-End (E2E) Testing
E2E tests simulate real user interactions within the Electron environment. These tests verify the application lifecycle, window management, and Inter-Process Communication (IPC).
Application Lifecycle and Window Management
The E2E suite verifies that the application starts correctly, loads the local web server URL, and maintains security features like sandboxing and context isolation.
Key verifications in E2E include:
- Startup Validation: Ensuring
app.isRunning()is true and a single window is created. - Navigation: Confirming the window loads
localhost:8000and displays the correct application title. - UI Interaction: Simulating mouse clicks and window resizing to test responsiveness.
- Security: Verifying
process.sandboxedandprocess.contextIsolatedare enabled.
Sources: tests/e2e/electron-app.test.js:12-70, tests/e2e/electron-app.test.js:150-170
IPC Communication
E2E tests specifically target the window.electronAPI bridge to ensure the frontend can safely trigger backend actions.
- File Operations: Testing
window.electronAPI.openFile()for document handling. - Cleanup: Testing
window.electronAPI.cleanupTmpFiles()to manage application state.
Sources: tests/e2e/electron-app.test.js:90-110
Integration Testing
Integration tests focus on the interaction between the Caddy web server and the PHP-FPM process, ensuring that the web stack correctly handles requests and executes scripts.
Server Coordination Flow
The integration tests spawn actual instances of Caddy and PHP-FPM (or mocks in simplified environments) to test the full request lifecycle.
Verified Functionalities
The integration suite performs several critical checks on the web stack:
- Static File Serving: Confirms Caddy can serve files from the
/app/publicdirectory. - PHP Execution: Verifies that
.phpfiles are processed and return expected output (e.g., "Hello from PHP!"). - Security Headers: Checks for the presence of mandatory security headers:
X-Content-Type-Options: nosniffX-Frame-Options: DENYX-XSS-Protection: 1; mode=block
- CORS Handling: Ensures
Access-Control-Allow-Origin: *and relevant methods are supported.
Sources: tests/integration/caddy-php.test.js:120-160, tests/integration/caddy-php-simple.test.js:65-95
Testing Commands and Scripts
The project defines several npm scripts in package.json to execute different segments of the test suite.
| Script | Command | Purpose |
|---|---|---|
test:unit | jest --testPathPattern=unit | Tests individual modules in isolation |
test:integration | jest --testPathPattern=integration | Tests Caddy and PHP-FPM coordination |
test:e2e | jest --testPathPattern=e2e | Full application automation with Spectron |
test:coverage | jest --coverage | Generates LCOV and HTML coverage reports |
Sources: package.json:7-21
Summary
The testing system for Duplicator ensures that the core promise of the application—a portable, cross-platform PHP environment—is fulfilled. By combining E2E UI automation with lower-level server integration tests, the project maintains high technical standards for security (sandboxing), performance (startup times), and functional accuracy (PDF processing and accounting calculations). Integration tests specifically safeguard the Caddy configuration, while E2E tests ensure the Electron wrapper correctly exposes system-level capabilities to the web-based frontend.
Sources: tests/e2e/electron-app.test.js:180-200, tests/integration/caddy-php.test.js:170-190