Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

workbox-tests

БесплатноБез исполняемых скриптовНе проверен

Use when a project uses or is adopting a Workbox service worker and its caching must stay stable across refactors or upgrades: recipe behavior, precache…

testlandот testland★ 18 звёзд на GitHub

Об этом скилле

workbox-tests

Overview

This skill tests Workbox-built service workers: assert that an already-shipped Workbox SW behaves the way its recipes claim, using the workbox-precaching / workbox-routing / workbox-strategies / workbox-recipes / workbox-window packages per developer.chrome.com/docs/workbox/modules. The design-side counterpart - choosing a strategy per route type and authoring the Workbox strategy code before pinning it - is in references/cache-strategy-design.md.

Pinned version

Time-sensitive pin - re-check at wb-gh on upgrade: Workbox v7.4.1 (released May 2026).

When to use

  • A PWA already uses Workbox and tests need to lock its behavior against future refactors.
  • Migrating from Workbox v6 → v7 - assert each recipe behaves the same on the new release.
  • A "stale forever" bug report - pin the workbox-expiration plugin's TTL with a test before patching.
  • A workbox-precaching injection drifted (build emits wrong __WB_MANIFEST) - assert the precache manifest shape in CI.

Choosing a cache strategy

When the SW under test doesn't exist yet, or a hand-rolled sw.js is being migrated to Workbox, start with references/cache-strategy-design.md: the strategy-per-route-type table (CacheFirst / NetworkFirst / StaleWhileRevalidate / NetworkOnly), worked Workbox strategy code with ExpirationPlugin + CacheableResponsePlugin, the matching Playwright assertions, an audit table classifying existing hand-rolled fetch handlers, and invalidation locking (SW_VERSION bump + user-opt-in skipWaiting).

Authoring

Step 1 - Install test dependencies

Workbox ships no first-party test runner; the canonical pairing is Playwright (for runtime SW assertions) plus a unit-test runner (Vitest or Jest) for the workbox-window page-side helper:

npm install --save-dev @playwright/test vitest
# Workbox itself is already a runtime dep at this point

Step 2 - Decide where each assertion lives

Subject Runner Why
Precache manifest shape (__WB_MANIFEST) Vitest reading the built sw.js artifact Static; no browser needed
Recipe behavior at runtime (pageCache, imageCache) Playwright Needs a real caches API + fetch interception
workbox-window events on the page Playwright (page side) Listens on wb.addEventListener(...) from page code
Plugin TTL / quota (workbox-expiration) Playwright with clock manipulation Needs the SW to actually call the plugin's pruning logic

Step 3 - Author the precache-manifest static assertion

// tests/precache-manifest.spec.ts
import { describe, it, expect } from 'vitest';
import { readFileSync } from 'node:fs';

describe('workbox-precaching manifest', () => {
  it('emits the __WB_MANIFEST entries with revision strings', () => {
    const sw = readFileSync('./dist/sw.js', 'utf8');
    // workbox-precaching tokens; per wb-modules
    expect(sw).toMatch(/precacheAndRoute\s*\(/);
    // Build-tool injects __WB_MANIFEST as an array of { url, revision } records
    const manifest = sw.match(/self\.__WB_MANIFEST\s*=\s*(\[[^;]+\])/)?.[1];
    expect(manifest).toBeDefined();
    const entries = JSON.parse(manifest!);
    expect(Array.isArray(entries)).toBe(true);
    for (const entry of entries) {
      expect(typeof entry.url).toBe('string');
      // Hashed filenames carry revision: null; non-hashed must have a revision string
      const isHashed = /\.[a-f0-9]{8,}\./.test(entry.url);
      if (!isHashed) expect(typeof entry.revision).toBe('string');
    }
  });
});

precacheAndRoute() is the entry point exported from workbox-precaching per wb-modules - it precaches a file set and manages updates to those files.

Step 4 - Author per-recipe runtime tests

Each named recipe has a documented default per wb-recipes; pin those defaults with tests. imageCache() is a cache-first strategy with defaults of 60 images cached for 30 days - pin the 60-entry cap:

import { test, expect } from '@playwright/test';

test('imageCache() applies the 60-entry default cap', async ({ context, page }) => {
  await page.goto('https://localhost:3000/gallery');
  await page.waitForLoadState('networkidle');

  // Force 61 distinct image requests
  for (let i = 0; i < 61; i++) {
    await page.evaluate((n) => fetch(`/img/test-${n}.png`).catch(() => {}), i);
  }

  // Wait for ExpirationPlugin to prune (it runs async)
  await page.waitForTimeout(500);

  let [sw] = context.serviceWorkers();
  if (!sw) sw = await context.waitForEvent('serviceworker');

  const count = await sw.evaluate(async () => {
    const cacheName = (await cac
Полный SKILL.md на GitHub

Установить workbox-tests в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

.tessl-plugin/plugin.jsonreferences/cache-strategy-design.mdreferences/recipe-tests.md

FAQ

Что делает скилл workbox-tests?

Use when a project uses or is adopting a Workbox service worker and its caching must stay stable across refactors or upgrades: recipe behavior, precache manifest injection, routes, expiration and cacheable-response plugins, workbox-window events, and choosing a cache strategy per route.

Как установить скилл workbox-tests?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл workbox-tests запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить workbox-tests с