trip-planner/tests/config/jest.setup.js

63 lines
No EOL
1.7 KiB
JavaScript

// Jest setup file for Selenium E2E tests
const { Builder } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
// Global test configuration
global.testConfig = {
baseUrl: process.env.BASE_URL || 'http://host.docker.internal:5173',
seleniumHub: process.env.SELENIUM_HUB || 'http://localhost:4444',
timeout: 30000,
isHeadless: process.env.HEADLESS === 'true'
};
// Global test utilities
global.createDriver = async () => {
const chromeOptions = new chrome.Options();
if (global.testConfig.isHeadless) {
chromeOptions.addArguments('--headless');
}
chromeOptions.addArguments('--no-sandbox');
chromeOptions.addArguments('--disable-dev-shm-usage');
chromeOptions.addArguments('--disable-gpu');
chromeOptions.addArguments('--window-size=1920,1080');
const driver = await new Builder()
.forBrowser('chrome')
.setChromeOptions(chromeOptions)
.usingServer(global.testConfig.seleniumHub)
.build();
// Set implicit wait
await driver.manage().setTimeouts({ implicit: 10000 });
return driver;
};
// Global cleanup function
global.quitDriver = async (driver) => {
if (driver) {
await driver.quit();
}
};
// Extend Jest matchers for better assertions
expect.extend({
async toBeDisplayed(element) {
const isDisplayed = await element.isDisplayed();
return {
message: () => `expected element to ${this.isNot ? 'not ' : ''}be displayed`,
pass: isDisplayed
};
},
async toHaveText(element, expectedText) {
const actualText = await element.getText();
const pass = actualText.includes(expectedText);
return {
message: () => `expected element to contain text "${expectedText}", but got "${actualText}"`,
pass
};
}
});