import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import test from 'node:test';
import { pathToFileURL } from 'node:url';
const volverScriptUrl = pathToFileURL(path.resolve('src/scripts/volver-a-ti.js')).href;
const distDir = path.resolve('dist');
const distAssetsDir = path.resolve('dist/assets');
const ALLOWED_EMAIL = 'contactocorazoncp@gmail.com';
const ALLOWED_PHONE_DIGITS = '573215428972';
const EXPECTED_GATE_STATUS = 'Por favor marca la casilla de aceptación antes de continuar.';
const EXPECTED_ZELLE_ACCEPT_TEXT =
'he leído y acepto las condiciones de participación y el descargo de responsabilidad';
const ROUTE_SPECS = [
{
route: '/',
file: 'index.html',
title: 'El Corazón como Portal — Acompañamiento Consciente en Valledupar',
description:
'Sal del automático. Abre tu corazón, recupera tu soberanía. Barras de Access®, Procesos de Cuerpo y Mentorías de Consciencia en Valledupar.',
canonical: 'https://elcorazoncomoportal.com/',
ogImage: 'https://elcorazoncomoportal.com/img/azu-hero.jpg',
ogImageWidth: '529',
ogImageHeight: '530',
ogImageAlt: 'Azucena Sánchez, facilitadora de El Corazón como Portal',
expectedHeaderCurrentHref: '/',
},
{
route: '/kundalini/',
file: 'kundalini/index.html',
title: 'Kundalini Yoga — El Corazón como Portal',
description:
'Explora los caminos de Kundalini Yoga con Seva Surpreet Kaur: acompañamiento personalizado Volver a ti y clases grupales.',
canonical: 'https://elcorazoncomoportal.com/kundalini/',
ogImage: 'https://elcorazoncomoportal.com/img/og-kundalini.jpg',
ogImageWidth: '1200',
ogImageHeight: '630',
ogImageAlt: 'Práctica de Kundalini Yoga con Seva Surpreet Kaur',
expectedHeaderCurrentHref: '/kundalini/',
},
{
route: '/volver-a-ti/',
file: 'volver-a-ti/index.html',
title: 'Volver a ti — Acompañamiento Personalizado en Kundalini Yoga',
description:
'Volver a ti: acompañamiento personalizado de Kundalini Yoga para equilibrio físico, calma emocional y conexión interior.',
canonical: 'https://elcorazoncomoportal.com/volver-a-ti/',
ogImage: 'https://elcorazoncomoportal.com/img/og-kundalini.jpg',
ogImageWidth: '1200',
ogImageHeight: '630',
ogImageAlt: 'Volver a ti — Acompañamiento personalizado de Kundalini Yoga',
expectedHeaderCurrentHref: null,
},
{
route: '/descargo/',
file: 'descargo/index.html',
title: 'Condiciones de Participación y Descargo — El Corazón como Portal',
description:
'Condiciones de participación y descargo de responsabilidad del programa Volver a ti de El Corazón como Portal.',
canonical: 'https://elcorazoncomoportal.com/descargo/',
ogImage: 'https://elcorazoncomoportal.com/img/logo.png',
ogImageWidth: '150',
ogImageHeight: '150',
ogImageAlt: 'Emblema de El Corazón como Portal',
expectedHeaderCurrentHref: null,
},
];
function readBuiltRoute(relativeFile) {
const fullPath = path.join(distDir, relativeFile);
assert.ok(fs.existsSync(fullPath), `Expected built route dist/${relativeFile} to exist`);
return fs.readFileSync(fullPath, 'utf8');
}
function attrValue(tag, attrName) {
const match = tag.match(
new RegExp(`(?:^|\\s)${attrName}=(?:(?:"([^"]*)")|(?:'([^']*)')|([^\\s>]+))`, 'i'),
);
if (!match) {
return null;
}
return match[1] ?? match[2] ?? match[3] ?? '';
}
function metaContent(html, attrName, attrVal) {
for (const match of html.matchAll(/]*>/gi)) {
const tag = match[0];
if (attrValue(tag, attrName) === attrVal) {
return attrValue(tag, 'content');
}
}
return null;
}
function canonicalHref(html) {
for (const match of html.matchAll(/]*>/gi)) {
const tag = match[0];
if (attrValue(tag, 'rel') === 'canonical') {
return attrValue(tag, 'href');
}
}
return null;
}
function headerSection(html) {
const match = html.match(/]*>[\s\S]*?<\/header>/i);
assert.ok(match, 'Expected element in built HTML');
return match[0];
}
function sectionById(html, id) {
const pattern = new RegExp(
`<([a-z][a-z0-9]*)\\b[^>]*\\bid=(?:"${id}"|'${id}'|${id})[^>]*>[\\s\\S]*?<\\/\\1>`,
'i',
);
const match = html.match(pattern);
assert.ok(match, `Expected element with id="${id}" in built HTML`);
return match[0];
}
function anchorTags(html) {
return [...html.matchAll(/]*>[\s\S]*?<\/a>/gi)].map((match) => match[0]);
}
function bundledModuleSources(html) {
return [...html.matchAll(/