0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-25 11:17:50 +01:00
posthog/test-runner-jest-environment.js

28 lines
1.0 KiB
JavaScript
Raw Normal View History

const { setupPage } = require('@storybook/test-runner')
const PlaywrightEnvironment = require('jest-playwright-preset/lib/PlaywrightEnvironment').default
class CustomEnvironment extends PlaywrightEnvironment {
async setup() {
await super.setup()
await setupPage(this.global.page, this.global.context)
}
async teardown() {
await super.teardown()
}
async handleTestEvent(event) {
if (event.name === 'test_done' && event.test.errors.length > 0) {
// Take screenshots on test failures - these become Actions artifacts
const parentName = event.test.parent.parent.name.replace(/\W/g, '-').toLowerCase()
const specName = event.test.parent.name.replace(/\W/g, '-').toLowerCase()
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
await this.global.page.locator('body, main').last().screenshot({
path: `frontend/__snapshots__/__failures__/${parentName}--${specName}.png`,
})
}
await super.handleTestEvent(event)
}
}
module.exports = CustomEnvironment