import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import path from 'node:path'; const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); describe('extension DevTools packaging', () => { it('uses extension-root paths for DevTools panel pages', () => { const source = readFileSync(path.join(ROOT, 'extension/devtools/devtools.js'), 'utf-8'); assert.match( source, /chrome\.devtools\.panels\.create\(\s*['"]Impeccable['"],\s*['"]\/icons\/icon-32\.png['"],\s*['"]\/devtools\/panel\.html['"]\s*\)/s, 'Firefox resolves DevTools URLs relative to devtools.html unless they start at the extension root', ); assert.match(source, /sidebar\.setPage\(['"]\/devtools\/sidebar\.html['"]\)/); assert.doesNotMatch(source, /['"]devtools\/(?:panel|sidebar)\.html['"]/); assert.doesNotMatch(source, /['"]icons\/icon-32\.png['"]/); }); }); describe('extension badge colors', () => { // Optional-call syntax on a method a browser does not implement returns // undefined, and .catch on undefined throws: updateBadge would abort before // it set the badge at all. Firefox's action API has no setBadgeTextColor, // so the call has to be guarded by an existence check, not by `?.`. it('guards setBadgeTextColor instead of chaining .catch onto an optional call', () => { const source = readFileSync(path.join(ROOT, 'extension/background/service-worker.js'), 'utf-8'); assert.doesNotMatch( source, /setBadgeTextColor\?\.\([^)]*\)\s*\.catch/s, 'setBadgeTextColor?.(...).catch(...) throws wherever the method is missing', ); assert.match( source, /typeof chrome\.action\.setBadgeTextColor === 'function'/, 'the call needs an existence check around it', ); assert.match( source, /typeof pending\.catch === 'function'/, 'the return value needs a promise check before .catch', ); }); it('paints the badge in kinpaku gold with ink text', () => { const source = readFileSync(path.join(ROOT, 'extension/background/service-worker.js'), 'utf-8'); assert.match(source, /setBadgeBackgroundColor\(\{ color: '#ffba00'/); assert.match(source, /setBadgeTextColor\(\{ color: '#0b0903'/); assert.doesNotMatch(source, /#d6336c/, 'the magenta badge is retired'); }); });