Skip to content

Accept record metadata in the Cypress adapter - #7

Open
SilinMykola wants to merge 2 commits into
MageLens:mainfrom
SilinMykola:cypress-record-metadata
Open

SilinMykola wants to merge 2 commits into
MageLens:mainfrom
SilinMykola:cypress-record-metadata

Conversation

@SilinMykola

@SilinMykola SilinMykola commented Nov 20, 2026 •

Copy link
Copy Markdown

Adds a metadata option to the Cypress registerTemplateCoverage, matching the Playwright metadata option, and keeps custom metadata passed to the Playwright withTemplateCoverage fixture through templateCoverageOptions; the fixture used to replace it with the test identity fields.

metadata is a function called once per test in afterEach; the object it returns is spread into the record before the record's own fields, so schemaVersion, recordId, spec, test, retry, ids, hits and references cannot be replaced. A non-function option or a non-object result throws. Without the option, records are unchanged.

MageLens needs it to match Cypress template records to test attempts (MageLens/MageLens#72, MageLens/MageLens#85): spec, title path and retry cannot tell apart two tests with the same title in one spec. Agreed in MageLens/MageLens#72 (comment).

Tests

  • New test/playwright/metadata.spec.js: an attempt field passed through templateCoverageOptions reaches the record written by the fixture, while spec, test and retry still describe the running test. It fails when the fixture drops custom metadata or lets it replace those fields.

  • New test/cypress-support.test.js runs the adapter's afterEach with stand-ins for the Cypress globals: records without metadata are unchanged, metadata fields are added without replacing the record's own fields, and invalid options are rejected. Each case fails when the behavior is removed.

  • npm test: 55/55 and npm run test:playwright: 14/14 with Chrome 157, npm run test:types passes. On macOS both suites need TMPDIR set to its real path: /var is a symlink to /private/var, and the fixtures' symlink protection rejects the temporary copies otherwise; that happens on main too.

  • Not run: the Magento Cypress harness npm run test:browser, which needs a Magento checkout.

The Playwright adapters already add a metadata object to each record.
Cypress records could only be identified by spec, title path and retry,
which cannot tell apart two tests with the same title in one spec. A
metadata function, called once per test in afterEach, now adds fields
such as a test attempt ID without replacing the record's own fields.
@VitaliyBoyko

Copy link
Copy Markdown
Collaborator

Thanks, @SilinMykola! Could we also update the Playwright fixture here?

The low-level registerTemplateCoverage() already accepts metadata, but [withTemplateCoverage()](https://github.com/MageLens/MagentoTemplateCoverage/blob/d261a7df2582588e2570435390d90fc3d41ed0fc/playwright/index.js#L129-L133) currently replaces it with its own test fields, so a custom attempt ID gets dropped.

Could we preserve custom metadata while keeping the built-in fields protected, and add a regression test confirming that the attempt ID survives through the wrapper?

Then, in [MageLens/MageLens#85](MageLens/MageLens#85), we can pass { attempt: coverageAttempt } through the per-test options fixture, so PHP, JavaScript and template records all share the same attempt ID.

The existing object-based Playwright API should be sufficient—we just need to carry that ID through the full integration. 🙂

withTemplateCoverage replaced the metadata of templateCoverageOptions
with the test identity fields, so a test attempt ID passed per test was
dropped. Custom fields are now kept, and spec, test, retry, project and
worker still describe the running test.
@SilinMykola

SilinMykola commented Nov 20, 2026 •

Copy link
Copy Markdown
Author

Done in 5048972. withTemplateCoverage now keeps the metadata of templateCoverageOptions and still sets spec, test, retry, project and worker itself. The new test/playwright/metadata.spec.js passes an attempt through test.use({templateCoverageOptions}) and checks that it reaches the record while the test identity stays intact. I will wire {attempt: coverageAttempt} through the options fixture in MageLens/MageLens#85.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants