fix(20): update test guards for deferred Sentry and lazy panel patterns

- sentry-beforesend.test: support extracted _sentryBeforeSend function
  (no longer inline beforeSend(event) { ... })
- live-news-panel-guard.test: match guard inside lazyPanel callback
  (no longer preceded by shouldCreatePanel)

Both tests verify the same behavioral contracts — just adapted to the
new code structure from Phase 20 dynamic imports.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sebastien Melki
2026-04-15 20:30:29 +03:00
parent 41c62686be
commit dd5565b748
2 changed files with 26 additions and 8 deletions

View File

@@ -75,7 +75,8 @@ describe('LiveNewsPanel instantiation guard', () => {
it('panel-layout.ts live-news guard checks getDefaultLiveChannels()', () => { it('panel-layout.ts live-news guard checks getDefaultLiveChannels()', () => {
const layout = src('src/app/panel-layout.ts'); const layout = src('src/app/panel-layout.ts');
const guardBlock = layout.match(/shouldCreatePanel\('live-news'\)[^}]*getDefaultLiveChannels\(\)\.length/s); // Guard may be inside a lazyPanel callback or after shouldCreatePanel — match either pattern
const guardBlock = layout.match(/['"]live-news['"][^}]*getDefaultLiveChannels\(\)\.length/s);
assert.ok( assert.ok(
guardBlock, guardBlock,
"panel-layout.ts must guard 'live-news' with getDefaultLiveChannels().length > 0", "panel-layout.ts must guard 'live-news' with getDefaultLiveChannels().length > 0",
@@ -84,7 +85,8 @@ describe('LiveNewsPanel instantiation guard', () => {
it('panel-layout.ts live-news guard also checks loadChannelsFromStorage()', () => { it('panel-layout.ts live-news guard also checks loadChannelsFromStorage()', () => {
const layout = src('src/app/panel-layout.ts'); const layout = src('src/app/panel-layout.ts');
const guardBlock = layout.match(/shouldCreatePanel\('live-news'\)[^}]*loadChannelsFromStorage\(\)\.length/s); // Guard may be inside a lazyPanel callback or after shouldCreatePanel — match either pattern
const guardBlock = layout.match(/['"]live-news['"][^}]*loadChannelsFromStorage\(\)\.length/s);
assert.ok( assert.ok(
guardBlock, guardBlock,
"panel-layout.ts must also check loadChannelsFromStorage().length > 0 so users with saved channels can use the panel on happy variant", "panel-layout.ts must also check loadChannelsFromStorage().length > 0 so users with saved channels can use the panel on happy variant",

View File

@@ -10,22 +10,38 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
// We parse it as a standalone function to avoid importing Sentry/App bootstrap. // We parse it as a standalone function to avoid importing Sentry/App bootstrap.
const mainSrc = readFileSync(resolve(__dirname, '../src/main.ts'), 'utf-8'); const mainSrc = readFileSync(resolve(__dirname, '../src/main.ts'), 'utf-8');
// Extract everything between `beforeSend(event) {` and the matching closing `},` // Extract the beforeSend function body from main.ts source.
const bsStart = mainSrc.indexOf('beforeSend(event) {'); // Supports both inline `beforeSend(event) {` and extracted `function _sentryBeforeSend(event: any): any {`.
assert.ok(bsStart !== -1, 'beforeSend must exist in src/main.ts'); const MARKERS = ['function _sentryBeforeSend(event', 'beforeSend(event) {'];
let bsStart = -1;
let markerEnd = '';
for (const marker of MARKERS) {
bsStart = mainSrc.indexOf(marker);
if (bsStart !== -1) {
// Find the opening brace after the marker
markerEnd = marker;
break;
}
}
assert.ok(bsStart !== -1, 'beforeSend / _sentryBeforeSend must exist in src/main.ts');
// Find the opening brace
const braceStart = mainSrc.indexOf('{', bsStart + markerEnd.length);
assert.ok(braceStart !== -1, 'Failed to find opening brace');
let braceDepth = 0; let braceDepth = 0;
let bsEnd = -1; let bsEnd = -1;
for (let i = bsStart + 'beforeSend(event) '.length; i < mainSrc.length; i++) { for (let i = braceStart; i < mainSrc.length; i++) {
if (mainSrc[i] === '{') braceDepth++; if (mainSrc[i] === '{') braceDepth++;
if (mainSrc[i] === '}') { if (mainSrc[i] === '}') {
braceDepth--; braceDepth--;
if (braceDepth === 0) { bsEnd = i + 1; break; } if (braceDepth === 0) { bsEnd = i + 1; break; }
} }
} }
assert.ok(bsEnd > bsStart, 'Failed to find beforeSend closing brace'); assert.ok(bsEnd > braceStart, 'Failed to find beforeSend closing brace');
// Strip TypeScript type annotations so the body can be eval'd as plain JS. // Strip TypeScript type annotations so the body can be eval'd as plain JS.
const fnBody = mainSrc.slice(bsStart + 'beforeSend(event) '.length, bsEnd) const fnBody = mainSrc.slice(braceStart, bsEnd)
.replace(/:\s*string\b/g, '') // parameter type annotations .replace(/:\s*string\b/g, '') // parameter type annotations
.replace(/:\s*any\b/g, '') // any type annotations
.replace(/:\s*_SentryFrame\[\]/g, '') // custom type annotations
.replace(/as\s+\w+(\[\])?/g, '') // type assertions .replace(/as\s+\w+(\[\])?/g, '') // type assertions
.replace(/<[A-Z]\w*>/g, ''); // generic type params .replace(/<[A-Z]\w*>/g, ''); // generic type params