import { expect } from '@wdio/globals'
import { execSync } from 'node:child_process'
import { XvfbManager } from '@wdio/xvfb'
describe('xvfb existing installation', () => {
let xvfbManager: XvfbManager
beforeEach(() => {
xvfbManager = new XvfbManager()
})
it('should detect and use pre-installed xvfb', async function(this: Mocha.Context) {
this.timeout(300000)
expect(xvfbManager.shouldRun()).toBe(true)
let xvfbRunPath = ''
try {
xvfbRunPath = execSync('which xvfb-run', { encoding: 'utf8' }).trim()
} catch (error) {
throw new Error(`xvfb-run should be pre-installed: ${error}`)
}
expect(xvfbRunPath).toContain('xvfb-run')
expect(xvfbRunPath.length).toBeGreaterThan(0)
const initResult = await xvfbManager.init()
expect(initResult).toBe(true)
try {
const testOutput = execSync('xvfb-run --help', { encoding: 'utf8' })
expect(testOutput).toContain('xvfb-run')
} catch (error) {
throw new Error(`xvfb-run execution failed: ${error}`)
}
})
it('should execute xvfb-run commands with pre-installed xvfb', async function(this: Mocha.Context) {
this.timeout(300000)
await xvfbManager.init()
try {
const result = execSync('xvfb-run --auto-servernum -- echo "test successful"', {
encoding: 'utf8',
timeout: 10000
})
expect(result.trim()).toBe('test successful')
} catch (error) {
throw new Error(`xvfb-run command execution failed: ${error}`)
}
})
afterEach(async () => {
await new Promise(resolve => setTimeout(resolve, 100))
})
})