Overview
The Web Stories plugin includes comprehensive test coverage across multiple test types:- PHP Unit Tests - Testing PHP backend functionality
- JavaScript Unit Tests - Testing React components and utilities
- Integration Tests - Browser-based integration tests with Karma
- E2E Tests - End-to-end tests with Puppeteer
PHP Unit Tests
PHP tests use PHPUnit and the WordPress PHPUnit Test Suite.Running PHP Tests
PHP Test Structure
PHP tests are organized in:tests/phpunit/unit/- Unit teststests/phpunit/integration/- Integration tests
phpunit.xml.dist- Unit tests configurationphpunit-integration.xml.dist- Integration tests (single site)phpunit-integration-multisite.xml.dist- Integration tests (multisite)
Writing PHP Tests
The project uses WP Test Utils for improved cross-version compatibility with PHPUnit.
JavaScript Unit Tests
JavaScript tests use Jest with Testing Library.Running JavaScript Tests
JavaScript Test Configuration
Tests are configured intests/js/jest.config.js.
Key testing libraries:
- Jest - Test runner and assertion library
- @testing-library/react - React component testing
- @testing-library/react-hooks - React hooks testing
- jest-dom - Custom DOM matchers
- jest-extended - Additional matchers
Writing JavaScript Tests
File location: If a component resides infoo/bar/baz.js, place tests in foo/bar/tests/baz.js.
Test naming convention:
Custom Matchers
The project includes custom AMP validation matchers:toBeValidAMPtoBeValidAMPStoryPagetoBeValidAMPStoryElement
Test Utils
Custom test utilities are available intestUtils folders:
renderWithTheme- Render components with theme provider- Component-specific test helpers
packages/*/src/testUtils/ for available utilities.
Code Coverage
Generate and view code coverage:build/logs/lcov-report/index.html.
Integration Tests (Karma)
Integration tests use Karma with Jasmine to run tests in real browsers.Running Karma Tests
Karma Configuration
karma-story-editor.config.cjs- Story editor testskarma-dashboard.config.cjs- Dashboard tests
packages/story-editor/src/karma/- Story editor integration testspackages/dashboard/src/karma/- Dashboard integration tests
Custom Karma Matchers
Available custom matchers:toBeEmptytoHaveFocustoHaveStyletoHaveTextContenttoHavePropertytoBeOneOftoHaveNoViolations(accessibility testing)
Debugging Karma Tests
E2E Tests (Puppeteer)
End-to-end tests use Puppeteer with Jest to test the full user experience.Running E2E Tests
E2E Test Configuration
Configuration:packages/e2e-tests/src/jest.config.js
Tests location: packages/e2e-tests/src/specs/
Test utilities: packages/e2e-test-utils/src/
E2E tests run serially (
--runInBand) to avoid conflicts, as they share the same WordPress instance.Using Custom WordPress URL
By default, E2E tests use the Docker environment. To use a different WordPress installation:Debugging E2E Tests
Non-headless mode:Writing E2E Tests
E2E Test Utilities
Common utilities from@web-stories-wp/e2e-test-utils:
createNewStory()- Create a new storyinsertStoryTitle()- Set story titlepublishStory()- Publish the storyuploadMedia()- Upload media files- And many more…
packages/e2e-test-utils/src/ for all available utilities.
Test Plugins
Utility plugins for testing specific scenarios can be added topackages/e2e-tests/src/plugins/ and activated during tests.
Common Testing Mistakes
Useful Testing Resources
JavaScript Testing
- Jest Documentation
- React Testing Library
- Which query should I use?
- Common mistakes with React Testing Library
jest-domAPI
E2E Testing
Next Steps
Contributing
Learn how to contribute your changes
Architecture
Understand the project structure