testing

द्वारा cloudflare

इस प्रोजेक्ट के लिए टेस्ट लिखने या चलाने के दौरान उपयोग करें। इसमें यूनिट बनाम E2E टेस्ट निर्णय, टेस्ट फ़ाइल स्थान, मॉक पैटर्न और प्रोजेक्ट-विशिष्ट परीक्षण शामिल हैं…

npx skills add https://github.com/cloudflare/sandbox-sdk --skill testing

Testing in Sandbox SDK

This skill covers project-specific testing conventions. For TDD methodology, use the superpowers:test-driven-development skill.

Two Test Suites

Unit Tests

When to use: Testing isolated logic, client behavior, service methods, utilities.

Location:

  • SDK: packages/sandbox/tests/
  • Container: packages/sandbox-container/tests/

Runtime:

  • SDK tests run in Workers runtime via @cloudflare/vitest-pool-workers
  • Container tests run in Bun runtime

Commands:

npm test                              # All unit tests
npm test -w @cloudflare/sandbox       # SDK tests only
npm test -w @repo/sandbox-container   # Container tests only

Mock patterns:

  • SDK tests use a mock container (no Docker needed)
  • Container tests mock external dependencies (filesystem, processes)
  • Use createNoOpLogger() from @repo/shared for logger mocks

Known issue: SDK unit tests may hang on exit due to vitest-pool-workers workerd shutdown. Tests still pass/fail correctly - the hang is cosmetic.

E2E Tests

When to use: Testing full request flow, container integration, real Docker behavior.

Location: tests/e2e/

Runtime: Real Cloudflare Workers + Docker containers

Commands:

npm run test:e2e                                                           # All E2E tests (vitest + browser)
npm run test:e2e:vitest -- -- tests/e2e/process-lifecycle-workflow.test.ts # Single vitest file
npm run test:e2e:vitest -- -- tests/e2e/git-clone-workflow.test.ts -t 'test name'  # Single vitest test
npm run test:e2e:browser                                                   # Browser tests only (Playwright)

Note: Use test:e2e:vitest when filtering tests. The test:e2e wrapper doesn't support argument passthrough.

Key patterns:

  • All tests share ONE container for performance
  • Use unique sessions for test isolation
  • Tests run in parallel via thread pool
  • Config: vitest.e2e.config.ts (root level)

Writing E2E tests:

import { createTestSession } from './helpers';

describe('Feature X', () => {
  let session: TestSession;

  beforeEach(async () => {
    session = await createTestSession(); // Gets unique session
  });

  it('should do something', async () => {
    const result = await session.sandbox.exec('echo hello');
    expect(result.stdout).toBe('hello\n');
  });
});

When to Use Which

ScenarioTest Type
Client method logicUnit
Service business logicUnit
Request/response handlingUnit
Full command execution flowE2E
File operations with real filesystemE2E
Process lifecycle (start, stop, signal)E2E
Port exposure and preview URLsE2E
Git operationsE2E

Test-Specific Conventions

File naming: *.test.ts for both unit and E2E tests

Test structure:

describe('ComponentName', () => {
  describe('methodName', () => {
    it('should do X when Y', async () => {
      // Arrange
      // Act
      // Assert
    });
  });
});

Assertions: Use vitest's expect() with clear, specific assertions

Running Tests During Development

After making any meaningful code change:

  1. npm run check - catch type errors first
  2. npm test - verify unit tests pass
  3. npm run test:e2e - if touching core functionality

Build trust: The monorepo build system handles dependencies automatically. E2E tests always run against latest built code - no manual rebuild needed.

cloudflare की और Skills

workerd-api-review
cloudflare
कार्य प्रदर्शन अनुकूलन, API डिज़ाइन और अनुकूलता, सुरक्षा कमज़ोरियाँ, और workerd कोड समीक्षा के लिए मानक विनिर्देश अनुपालन। tcmalloc-जागरूक को शामिल करता है…
official
workerd-safety-review
cloudflare
मेमोरी सुरक्षा, थ्रेड सुरक्षा, समवर्तीता, और workerd कोड समीक्षा के लिए महत्वपूर्ण पहचान पैटर्न। V8/KJ सीमा खतरे, जीवनकाल प्रबंधन को शामिल करता है,…
official
module-registry
cloudflare
जब workerd में मॉड्यूल रजिस्ट्री के साथ काम कर रहे हों — मॉड्यूल रिज़ॉल्यूशन, संकलन, मूल्यांकन या पंजीकरण को पढ़ना, संशोधित करना, डीबग करना या समीक्षा करना — तब लोड करें।
official
reproduce
cloudflare
क्लाउडफ्लेयर/एजेंट्स गिटहब इश्यू को पुनः उत्पन्न करने के लिए एक न्यूनतम एजेंट्स/वर्कर प्रोजेक्ट तैयार करें और इसे एक अस्थायी क्लाउडफ्लेयर खाते में डिप्लॉय करें, फिर रिपोर्ट करें…
official
local-explorer
cloudflare
स्थानीय एक्सप्लोरर या स्थानीय API में उत्पादों/संसाधनों को कैसे जोड़ें। नए स्थानीय APIs या UI रूट्स को लागू करते समय उपयोग करें...
official
commit-categories
cloudflare
चेंजलॉग और "नया क्या है" सारांश के लिए कमिट वर्गीकरण नियम। चेंजलॉग या व्हाट्स-न्यू कमांड में कमिट को वर्गीकृत करने से पहले लोड किया जाना चाहिए। प्रदान करता है…
official
architecture
cloudflare
कोडबेस में पहली बार नेविगेट करते समय, नया क्लाइंट मेथड जोड़ते समय, नया कंटेनर हैंडलर/सर्विस जोड़ते समय, या यह समझने के लिए उपयोग करें कि अनुरोध कैसे प्रवाहित होता है…
official
changesets
cloudflare
चेंजसेट बनाते समय, रिलीज़ तैयार करते समय, या वर्ज़न अपडेट करते समय उपयोग करें। इसमें शामिल है कि किन पैकेजों का संदर्भ लेना है, उपयोगकर्ता-सामने वाले चेंजसेट विवरण कैसे लिखने हैं,…
official