import {routingModuleUrl} from './helpers/routing.mjs'; import {test} from 'node:test'; import assert from 'node:assert/strict'; import {readFile} from 'node:fs/promises'; import ts from 'typescript'; async function moduleUrl(file,replace=code=>code){ const filename=new URL(file,import.meta.url); const {outputText}=ts.transpileModule(await readFile(filename,'utf8'),{compilerOptions:{target:ts.ScriptTarget.ES2022,module:ts.ModuleKind.ESNext}}); return 'data:text/javascript;base64,'+Buffer.from(replace(outputText).replace(/(['"])\.\.\/routing\1/g,JSON.stringify(routingModuleUrl))+'\n//# sourceURL='+filename.pathname).toString('base64'); } const protocolUrl=await moduleUrl('../src/lib/api/protocol.ts'); const renderUrl=await moduleUrl('../src/lib/client/render.ts',code=>code.replace('"../api/protocol"',JSON.stringify(protocolUrl))); const {card}=await import(renderUrl); test('poster cards keep ranking numerals, descriptive link titles and alt text, and search highlights only escaped titles',()=>{ const drama={id:7,title:'测试 <短剧>',cover:'https://cdn.example/cover.webp',totalEpisode:10}; const ranked=card(drama,false,{rank:25}); assert.ok(ranked.includes('
'));assert.ok(ranked.includes('data-rank="25"'));assert.ok(ranked.includes('第 25 名'));assert.ok(ranked.includes('>25')); assert.ok(ranked.includes('href="/detail/7/"'));assert.ok(ranked.includes('data-src="https://cdn.example/cover.webp"')); assert.ok(card(drama,false,{rank:1}).includes('>01')); assert.ok(!card(drama,false,{rank:-1}).includes('hg-card-rank')); assert.ok(ranked.includes('title="《测试 <短剧>》全10集 在线观看"'));assert.ok(ranked.includes('alt="《测试 <短剧>》海报"'));assert.ok(ranked.includes('全10集')); const search=card(drama,false,{keyword:'<短剧>'}); assert.ok(search.includes('<短剧>'));assert.ok(!search.includes('<短剧>')); assert.ok(search.includes('

')); });