When running layered tests where one app extends another (e.g., a site-specific app extending the base Hyva tests), there's a need to skip certain base tests that aren't relevant to the extending app. The original implementation had a flaw where tests with identical names in different test suites would both be skipped when only one was intended to be skipped.
For example, if both simple_product.spec.ts and configurable_product.spec.ts had tests with identical names, and only the tests in configurable_product.spec.ts needed to be skipped, the original implementation would skip those tests in both files.
The solution implemented provides a more robust way to skip tests by considering both the test suite name and the test title, rather than just the test title.
-
Structured Configuration
- The
skipBaseTestsconfiguration inconfig.jsonuses a hierarchical structure - Tests to skip are organized by test suite name, preventing conflicts between identical test titles in different suites
- The
-
Helper Function
- A
shouldSkipTesthelper function insrc/utils/functions/test-skip.tshandles the logic - The function automatically extracts the test suite name and test title from the Playwright
testInfoobject
- A
-
Consistent Implementation
- All test files use the same pattern for skipping tests
- The beforeEach hook in each test file calls the helper function with the testInfo object
-
tests/m2-hyva-playwright/config.init.ts- Updated to handle the structured skipBaseTests format
- Added serialization of the skipBaseTests object to JSON
-
tests/m2-hyva-playwright/src/utils/functions/test-skip.ts- Created a helper function that determines if a test should be skipped
- Parses the JSON structure and checks if the test should be skipped based on test suite and test title
-
tests/m2-hyva-playwright/README.md- Updated documentation to explain the format
- Added examples of how to use the helper function
-
Test files in various app directories
- Updated all test files to use the new helper function
- Removed manual test suite name declarations in favor of automatic extraction
{
"skipBaseTests": {
"Category test suite": [
"Filters",
"it can sort the products by name (a-z)"
],
"Configurable products test suite": [
"Can increment the product quantity on the pdp",
"Can add configurable product to cart and verify options in cart"
]
}
}-
Configure Tests to Skip
- In your app's
config.json, add askipBaseTestsobject - Organize tests to skip by test suite name
- For each test suite, list the test titles to skip
- In your app's
-
Implement in Test Files
- Import the helper function:
import { shouldSkipTest } from "@utils/functions/test-skip"; - Use it in the beforeEach hook:
test.beforeEach(async ({ page }, testInfo) => { const shouldSkip = shouldSkipTest(testInfo); test.skip(shouldSkip, testInfo.title + " test skipped for this environment: " + process.env.APP_NAME); // Rest of your beforeEach code });
- Import the helper function:
- Precision: Skip tests based on both test suite and test title, preventing unintended skips
- Maintainability: Clearer configuration structure makes it easier to manage which tests to skip
- Simplicity: Automatic extraction of test suite name eliminates the need for manual declaration
If tests aren't being skipped as expected:
- Verify the test suite name in your config matches the describe block's title exactly
- Check that the test title in your config matches the test's title exactly
- Ensure the
shouldSkipTestfunction is being called correctly in the beforeEach hook - For debugging, you can add console logs in the test-skip.ts file to see what's being checked