skills/browser-extension/extension-testing/SKILL.md
Test browser extensions with Playwright, unit test background workers and storage, and set up CI for extension projects.
npx skillsauth add kienbui1995/magic-powers extension-testingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Playwright supports loading unpacked extensions:
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
// Load extension
contextOptions: {
args: [
`--disable-extensions-except=${path.join(__dirname, 'dist')}`,
`--load-extension=${path.join(__dirname, 'dist')}`
]
}
}
});
test('popup shows correct count', async ({ context }) => {
// Get extension service worker
const [background] = context.serviceWorkers();
// Open popup
const popupPage = await context.newPage();
await popupPage.goto(`chrome-extension://${extensionId}/popup.html`);
await expect(popupPage.locator('#count')).toHaveText('0');
});
Extract pure logic from Chrome API calls for unit testing:
// background.js — testable pure function
export function calculateBadgeText(count) {
return count > 99 ? '99+' : String(count);
}
// background.test.js — no browser APIs needed
import { calculateBadgeText } from './background';
test('badge text caps at 99+', () => {
expect(calculateBadgeText(100)).toBe('99+');
});
// vitest / jest setup
global.chrome = {
storage: {
local: {
get: vi.fn().mockResolvedValue({ count: 5 }),
set: vi.fn().mockResolvedValue(undefined)
}
},
runtime: { sendMessage: vi.fn() }
};
# .github/workflows/test.yml
- name: Build extension
run: npm run build
- name: Install Playwright browsers
run: npx playwright install chromium
- name: Run extension tests
run: npx playwright test
context.serviceWorkers() in Playwright--load-extension flag?--set-extension-name or use key in manifestchrome.* APIs unavailable in Node.js test environment — always mock themcontent-media
Use when designing for XR (AR/VR/MR), choosing interaction modes, or adapting 2D UI patterns for spatial computing
testing
Use when creating new skills, editing existing skills, or verifying skills work before deployment
development
Use when you have a spec or requirements for a multi-step task, before touching code
development
Use when executing a structured workflow — select and run a feature, bugfix, refactor, research, or incident template with correct agent and model assignments per phase.