Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ permissions:

jobs:
test:
name: Node ${{ matrix.node }}
name: Node ${{ matrix.node }} / ${{ matrix.browser }}
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
node: ['24', '26']
browser: [chromium]
include:
- node: '24'
browser: chrome-156
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
Expand All @@ -32,5 +36,18 @@ jobs:
- run: npm test
- run: npm run test:types
- run: npx playwright install --with-deps chromium
if: matrix.browser == 'chromium'
- name: Install MageLens's pinned Chrome for Testing
if: matrix.browser == 'chrome-156'
env:
CHROME_VERSION: '156.0.8078.80'
CHROME_SHA256: b711c720f774be355197f32edf37e0651418ba036d92446ee2da19ac017540a7
run: |
npx playwright install-deps chromium
curl --fail --location --output "$RUNNER_TEMP/chrome.zip" "https://storage.googleapis.com/chrome-for-testing-public/$CHROME_VERSION/linux64/chrome-linux64.zip"
echo "$CHROME_SHA256 $RUNNER_TEMP/chrome.zip" | sha256sum --check
unzip -q "$RUNNER_TEMP/chrome.zip" -d "$RUNNER_TEMP/mtc-chrome"
echo "MTC_CHROME_EXECUTABLE_PATH=$RUNNER_TEMP/mtc-chrome/chrome-linux64/chrome" >> "$GITHUB_ENV"
echo "MTC_CHROME_VERSION=$CHROME_VERSION" >> "$GITHUB_ENV"
- run: npm run test:playwright
- run: npm pack --dry-run
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ License: see LICENSE in the repository root.

# Changelog

## 1.5.4 - 2026-11-06

- Verify Playwright 1.65 compatibility with Chrome for Testing 156.0.8078.80, including inert controls, rendered accessible names and authenticated CSP fixtures with path-scoped cookies.

## 1.5.3 - 2026-10-29

- Verify Node.js 26 compatibility alongside Node.js 24 for template analysis, Playwright integration and TypeScript declarations.
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vitaliiboiko/magento-template-coverage",
"version": "1.5.3",
"version": "1.5.4",
"description": "Magento 2 HTML/PHTML template execution coverage for Cypress and Playwright, including Knockout, Hyva/Alpine and inline JavaScript",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -74,7 +74,7 @@
},
"devDependencies": {
"@alpinejs/csp": "3.14.3",
"@playwright/test": "1.64.1",
"@playwright/test": "1.65.0",
"@types/node": "24.19.2",
"alpinejs": "3.17.4",
"knockout": "3.5.1",
Expand Down
9 changes: 8 additions & 1 deletion test/playwright/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@
// SPDX-License-Identifier: MIT
// License: see LICENSE in the repository root.

module.exports = {testDir: __dirname, testMatch: '*.spec.js', workers: 1, retries: 0, reporter: 'list', use: {browserName: process.env.MTC_BROWSER || 'chromium', headless: true}, outputDir: '../../artifacts/playwright'};
module.exports = {
testDir: __dirname, testMatch: '*.spec.js', workers: 1, retries: 0, reporter: 'list',
use: {
browserName: process.env.MTC_BROWSER || 'chromium', headless: true,
launchOptions: process.env.MTC_CHROME_EXECUTABLE_PATH ? {executablePath: process.env.MTC_CHROME_EXECUTABLE_PATH} : {}
},
outputDir: '../../artifacts/playwright'
};
33 changes: 27 additions & 6 deletions test/playwright/csp-worker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,54 @@ const authenticated = base.extend({
fixture.write(path.join(source, 'app/code'));
const manifest = createManifest({source, roots: ['app/code']});
instrument({source, manifest, mappings: {'app/code': copy}});
const server = http.createServer((req, res) => {if (!fixture.serve(req, res, copy)) res.writeHead(404).end();});
const server = http.createServer((req, res) => {
if (req.url === '/login' && req.method === 'POST') {
res.setHeader('Set-Cookie', 'session=authenticated; Path=/admin; HttpOnly; SameSite=Lax');
res.writeHead(204).end(); return;
}
if (req.url === '/administrator') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({cookie: req.headers.cookie || ''})); return;
}
if (req.url === '/admin/csp.html') {
if (req.headers.cookie !== 'session=authenticated') { res.writeHead(401).end(); return; }
fixture.serve({url: '/csp.html'}, res, copy); return;
}
if (!fixture.serve(req, res, copy)) res.writeHead(404).end();
});
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
try { await use({root, manifest, url: `http://127.0.0.1:${server.address().port}/csp.html`}); }
try { await use({root, manifest, url: `http://127.0.0.1:${server.address().port}/admin/csp.html`}); }
finally { await new Promise(resolve => server.close(resolve)); fs.rmSync(root, {recursive: true, force: true}); }
}, {scope: 'worker'}],
login: [async ({browser, site}, use) => {
const context = await browser.newContext();
let state;
try {
expect((await context.request.post(new URL('/login', site.url).href)).status()).toBe(204);
const page = await context.newPage();
const errors = []; page.on('pageerror', error => errors.push(error.message));
await page.goto(site.url);
for (let i = 0; i < 7; i++) await page.locator('#increment').click();
await expect(page.locator('#count')).toHaveText('7');
expect(errors).toEqual([]);
expect(fs.existsSync(path.join(site.root, 'hits'))).toBe(false);
state = await context.storageState();
} finally { await context.close(); }
await use(true);
await use(state);
}, {scope: 'worker'}],
storageState: async ({login}, use) => { expect(login).toBe(true); await use({cookies: [], origins: []}); }
storageState: async ({login}, use) => use(login)
});
const test = withTemplateCoverage(authenticated).extend({
templateCoverageOptions: async ({site}, use) => use({outputDir: path.join(site.root, 'hits')})
});

test('worker login contexts run CSP bindings without adding coverage records', async ({page, site}) => {
test('worker login contexts run CSP bindings without adding coverage records', async ({page, context, site}) => {
const errors = []; page.on('pageerror', error => errors.push(error.message));
await page.goto(site.url);
expect((await context.cookies(site.url)).map(cookie => cookie.name)).toEqual(['session']);
const outside = new URL('/administrator', site.url).href;
expect(await context.cookies(outside)).toEqual([]);
expect(await (await context.request.get(outside)).json()).toEqual({cookie: ''});
expect((await page.goto(site.url)).status()).toBe(200);
await expect(page.locator('#count')).toHaveText('0');
await page.locator('#increment').click();
await expect(page.locator('#count')).toHaveText('1');
Expand Down
90 changes: 90 additions & 0 deletions test/playwright/interaction.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// SPDX-FileCopyrightText: Private Entrepreneur Vitalii Boiko
// SPDX-License-Identifier: MIT
// License: see LICENSE in the repository root.

'use strict';
const {test, expect} = require('@playwright/test');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const http = require('node:http');
const {createManifest, instrument, merge, readRecords} = require('../../lib');
const {registerTemplateCoverage} = require('../../playwright');

test.beforeAll(async ({browser}) => {
const name = process.env.MTC_CHROME_EXECUTABLE_PATH ? 'chrome-for-testing' : browser.browserType().name();
console.log(`Compatibility browser: ${name} ${browser.version()}; Playwright ${require('@playwright/test/package.json').version}`);
if (process.env.MTC_CHROME_VERSION) expect(browser.version()).toBe(process.env.MTC_CHROME_VERSION);
});

test('instrumentation preserves inert controls and rendered accessible names', async ({context, page}) => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'mtc-interaction-'));
const source = path.join(root, 'source'), copy = path.join(root, 'copy');
const html = `<section x-data="{ locked: true, name: '', choice: 'a', checked: false, count: 0 }">
<button id="unlock" @click="locked = false">Unlock</button>
<div :inert="locked">
<input id="name" x-model="name"><output id="echo" x-text="name"></output>
<select id="choice" x-model="choice"><option value="a">A</option><option value="b">B</option></select>
<input id="checked" type="checkbox" x-model="checked">
<button id="apply" aria-labelledby="label" @click="count++">Apply</button>
<span id="label">Apply <details><summary>Options</summary>Unrendered text</details></span>
<output id="count" x-text="count"></output>
<button id="unused" @click="count = 100">Unused</button>
</div></section>`;
fs.mkdirSync(path.join(source, 'app/code'), {recursive: true});
fs.writeFileSync(path.join(source, 'app/code/controls.html'), html);
const manifest = createManifest({source, roots: ['app/code']});
instrument({source, manifest, mappings: {'app/code': copy}});
const server = http.createServer((req, res) => {
if (req.url === '/alpine.js') {
res.setHeader('Content-Type', 'application/javascript');
res.end(fs.readFileSync(require.resolve('alpinejs').replace(/module.cjs.js$/, 'cdn.js'))); return;
}
if (!['/original', '/instrumented'].includes(req.url)) { res.writeHead(404).end(); return; }
res.setHeader('Content-Type', 'text/html');
const body = req.url === '/original' ? html : fs.readFileSync(path.join(copy, 'controls.html'), 'utf8');
res.end('<!doctype html><script defer src="/alpine.js"></script>' + body);
});
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
const coverage = await registerTemplateCoverage(context, {outputDir: path.join(root, 'hits')});
const errors = []; page.on('pageerror', error => errors.push(error.message));
try {
for (const route of ['original', 'instrumented']) {
await page.goto(`http://127.0.0.1:${server.address().port}/${route}`);
await expect(page.locator('#count')).toHaveText('0');
for (const action of [
() => page.locator('#name').fill('blocked', {timeout: 300}),
() => page.locator('#choice').selectOption('b', {timeout: 300}),
() => page.locator('#checked').check({timeout: 300}),
() => page.locator('#apply').click({timeout: 300})
]) await expect(action()).rejects.toThrow(/inert/);
await expect(page.locator('#name')).toHaveValue('');
await expect(page.locator('#choice')).toHaveValue('a');
await expect(page.locator('#checked')).not.toBeChecked();
await expect(page.locator('#count')).toHaveText('0');
await page.getByRole('button', {name: 'Unlock', exact: true}).click();
await page.locator('#name').fill('updated');
await expect(page.locator('#echo')).toHaveText('updated');
await page.locator('#choice').selectOption('b');
await expect(page.locator('#choice')).toHaveValue('b');
await page.locator('#checked').check();
await expect(page.locator('#checked')).toBeChecked();
await page.getByRole('button', {name: 'Apply Options', exact: true}).click();
await expect(page.locator('#count')).toHaveText('1');
}
expect(errors).toEqual([]);
await coverage.stop();
const records = readRecords(path.join(root, 'hits'));
expect(records).toHaveLength(1);
const entry = manifest.templates[0];
const click = id => entry.statements.find(statement => statement.binding === '@click' &&
entry.source.split('\n')[statement.start.line - 1].includes(`id="${id}"`));
expect(records[0].hits[entry.id][click('apply').id]).toBe(1);
expect(records[0].hits[entry.id][click('unused').id] || 0).toBe(0);
expect(merge(manifest, records).templates[0].unsupportedDirectives || []).toEqual([]);
expect(fs.readFileSync(path.join(source, 'app/code/controls.html'), 'utf8')).toBe(html);
} finally {
await new Promise(resolve => server.close(resolve));
fs.rmSync(root, {recursive: true, force: true});
}
});
Loading