Skip to content

Commit 9cfe918

Browse files
Add UI test environment setup documentation and increase before hook timeout
Co-authored-by: thomasnordquist <7721625+thomasnordquist@users.noreply.github.com>
1 parent daebab8 commit 9cfe918

2 files changed

Lines changed: 57 additions & 3 deletions

File tree

.github/copilot-instructions.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,59 @@ yarn lint
188188
yarn lint:fix
189189
```
190190

191+
### Running UI Tests (yarn test:ui)
192+
193+
The UI tests require specific setup in the test environment:
194+
195+
**Prerequisites:**
196+
1. **Xvfb (X Virtual Framebuffer)** - Required for headless Electron testing
197+
```bash
198+
# Start Xvfb on display :99
199+
Xvfb :99 -screen 0 1024x720x24 -ac &
200+
export DISPLAY=:99
201+
```
202+
203+
2. **Mosquitto MQTT Broker** - Required for MQTT message testing
204+
```bash
205+
# Install mosquitto
206+
sudo apt-get install -y mosquitto mosquitto-clients
207+
208+
# Start mosquitto service
209+
sudo systemctl start mosquitto
210+
211+
# Verify it's running on port 1883
212+
sudo systemctl status mosquitto
213+
```
214+
215+
3. **@types/node** - Required for TypeScript compilation
216+
```bash
217+
yarn add -D @types/node
218+
```
219+
220+
**Running UI Tests:**
221+
```bash
222+
# Build the application first
223+
yarn build
224+
225+
# Run UI tests with proper display
226+
DISPLAY=:99 yarn test:ui
227+
```
228+
229+
**Common Issues:**
230+
- **"Timeout exceeded" in before hook**: Mosquitto is not running or not accessible on port 1883
231+
- **"Cannot find type definition file for 'node'"**: Run `yarn add -D @types/node`
232+
- **Electron fails to launch**: Xvfb is not running or DISPLAY variable not set
233+
- **Tests hang**: Check if old Electron/mosquitto processes are still running and kill them
234+
235+
**Environment Cleanup:**
236+
```bash
237+
# Kill old Electron processes
238+
ps aux | grep electron | grep -v grep | awk '{print $2}' | xargs kill -9 2>/dev/null
239+
240+
# Kill old mosquitto processes (if running custom instance)
241+
ps aux | grep mosquitto | grep -v grep | awk '{print $2}' | xargs kill -9 2>/dev/null
242+
```
243+
191244
## MCP Introspection Testing
192245

193246
The project supports MCP (Model Context Protocol) for automated testing with Playwright:

src/spec/ui-tests.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('MQTT Explorer UI Tests', function () {
4646
* Setup: Start MQTT broker mock and launch Electron app
4747
*/
4848
before(async function () {
49-
this.timeout(30000)
49+
this.timeout(90000) // Increased timeout for slow CI environments
5050

5151
console.log('Starting MQTT mock broker...')
5252
await mockMqtt()
@@ -55,13 +55,14 @@ describe('MQTT Explorer UI Tests', function () {
5555
console.log('Launching Electron application...')
5656
electronApp = await electron.launch({
5757
args: [`${__dirname}/../../..`, '--runningUiTestOnCi', '--no-sandbox', '--disable-dev-shm-usage'],
58+
timeout: 60000, // Give Electron more time to launch
5859
})
5960

6061
console.log('Waiting for application window...')
61-
page = await electronApp.firstWindow({ timeout: 10000 })
62+
page = await electronApp.firstWindow({ timeout: 30000 })
6263

6364
// Wait for the connection form to be ready (Host field exists in Electron, Username only in browser)
64-
await page.locator('//label[contains(text(), "Host")]/..//input').waitFor({ timeout: 5000 })
65+
await page.locator('//label[contains(text(), "Host")]/..//input').waitFor({ timeout: 10000 })
6566

6667
console.log('Application ready for testing')
6768
})

0 commit comments

Comments
 (0)