Skip to content

Add database fixture utilities for Playwright tests with before-hook and inline setup patterns#380

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-6239364-64921004-edba2fe0-e647-4ef8-86b6-b1c28d563cf6
Draft

Add database fixture utilities for Playwright tests with before-hook and inline setup patterns#380
Copilot wants to merge 5 commits intomainfrom
copilot/fix-6239364-64921004-edba2fe0-e647-4ef8-86b6-b1c28d563cf6

Conversation

Copy link
Copy Markdown

Copilot AI commented Nov 3, 2025

Enables pre-registering or mocking IndexedDB and Chrome Storage data in Playwright tests to verify behavior against specific data scenarios.

Implementation

Core utilities (test/emulator/db-fixtures.js):

  • setupDatabase(worker, profiles) - Pre-populate IndexedDB with profile data
  • setupStorage(worker, syncData, localData) - Configure Chrome Storage
  • getProfilesFromDatabase(worker) / queryProfiles(worker, prefix) - Verify database state
  • setupTestFixture(worker, options) / cleanupTestFixture(worker) - Combined operations

Test examples:

  • db-practical.spec.js - Real-world usage patterns
  • db-fixtures.example.spec.js - Comprehensive examples with inline documentation

Documentation:

  • DATABASE_TESTING_GUIDE.md - Japanese guide
  • README_DATABASE_TESTING.md - English reference

Usage

Before-hook pattern for shared test data:

test.beforeEach(async ({ context }) => {
  [worker] = context.serviceWorkers();
  await setupTestFixture(worker, {
    profiles: [
      { profilePath: '[COMPLEX];000001', name: 'base', aws_account_id: '111122223333' },
      { profilePath: 'base;000002', name: 'dev', aws_account_id: '444455556666', role_name: 'developer' }
    ],
    syncData: { configStorageArea: 'sync' },
    localData: { profilesTableUpdated: 2000 }
  });
});

test('should filter roles correctly', async ({ expect }) => {
  const roles = await queryProfiles(worker, 'base;');
  expect(roles).toHaveLength(1);
  expect(roles[0].role_name).toBe('developer');
});

Inline pattern for test-specific scenarios:

test('handles empty database', async ({ expect }) => {
  await setupDatabase(worker, []);
  const profiles = await getProfilesFromDatabase(worker);
  expect(profiles).toHaveLength(0);
});
Original prompt

playwrightのテストにおいて、データベースのデータをbeforeで事前登録するかmockして、データ内容に応じた正しい結果が得られるかtestするための方法を考えて


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits November 3, 2025 03:21
Co-authored-by: tilfin <519017+tilfin@users.noreply.github.com>
Co-authored-by: tilfin <519017+tilfin@users.noreply.github.com>
Co-authored-by: tilfin <519017+tilfin@users.noreply.github.com>
Co-authored-by: tilfin <519017+tilfin@users.noreply.github.com>
Copilot AI changed the title [WIP] playwrightのテストにおいて、データベースのデータをbeforeで事前登録するかmockして、データ内容に応じた正しい結果が得られるかtestするための方法を考えて Add database fixture utilities for Playwright tests with before-hook and inline setup patterns Nov 3, 2025
Copilot AI requested a review from tilfin November 3, 2025 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants