/**
 * 🔒 Backend Isolation Test Example
 *
 * This test file demonstrates the backend isolation pattern where each test file
 * can have its own dedicated backend instance. This provides:
 *
 * - Complete test isolation between different test files
 * - Independent backend state for each test suite
 * - Ability to run tests in parallel without interference
 * - Custom backend configuration per test file
 *
 * When backend isolation is specified, the test runner will:
 * 1. Launch a dedicated backend instance before running tests in this file
 * 2. Keep the backend running for the duration of all tests in this file
 * 3. Clean up and stop the backend after all tests complete
 */

import { startBackend, stopBackend } from 'fixtures/handle-backend'

import { expect, test } from '../fixtures/test-fixtures'

/**
 * Configure tests to run in serial mode to ensure proper backend lifecycle management.
 * If one test fails, we restart the backend and run all tests again for consistency.
 */
test.describe.configure({ mode: 'serial' })

/**
 * Backend Lifecycle: Startup
 *
 * Starts a dedicated backend instance for this test file before any tests run.
 * The 'file' parameter indicates this backend is scoped to this specific test file.
 */
// eslint-disable-next-line no-empty-pattern
test.beforeAll(async ({}, testInfo) => {
  await startBackend('file', testInfo)
})

/**
 * Backend Lifecycle: Cleanup
 *
 * Stops the dedicated backend instance after all tests in this file complete.
 * This ensures proper cleanup and prevents resource leaks between test runs.
 */
// eslint-disable-next-line no-empty-pattern
test.afterAll(async ({}, testInfo) => {
  await stopBackend('file', testInfo)
})

/**
 * Example test using the isolated backend instance.
 * This test runs against the dedicated backend started in beforeAll(),
 * ensuring it has a clean, isolated environment.
 */
test('Dashboard page is accessible ', async ({ page }) => {
  await page.goto('/dashboard')

  await expect(page).toHaveURL(/.*\/dashboard$/)
})
