Download tests/render.test.mjs from fffiloni/hf-picks: direct link, hf CLI and curl.
- Browser
- Download file 2.71 kB
-
https://huggingface.co/spaces/fffiloni/hf-picks/resolve/main/tests/render.test.mjs
- Command line
-
hf download hf://spaces/fffiloni/hf-picks/tests/render.test.mjs
-
curl -L -o render.test.mjs https://huggingface.co/spaces/fffiloni/hf-picks/resolve/main/tests/render.test.mjs
2.71 kB
| import test from 'node:test'; | |
| import assert from 'node:assert/strict'; | |
| import {writeFile,mkdir} from 'node:fs/promises'; | |
| import {facts,spineFacts,makeZip,compact,COLORS,overviewGeometry} from '../static/render.js'; | |
| test('metadata facts respect type and missing data',()=>{ | |
| assert.deepEqual(facts({kind:'model',downloads:12345,likes:42}).map(f=>[f.value,f.label]),[['12.35k','downloads / 30d'],['42 likes',undefined]]); | |
| assert.deepEqual(facts({kind:'dataset',downloads:null}),[]); | |
| assert.equal(facts({kind:'space',downloads:10000,hardware:'ZeroGPU',likes:0}).length,2); | |
| assert.equal(facts({kind:'paper',publishedAt:'2017-06-12',upvotes:150})[0].value,'2017'); | |
| assert.equal(facts({kind:'blog',publishedAt:'2024-07-30',upvotes:7})[0].value,'JUL 2024'); | |
| assert.equal(facts({kind:'paper',publishedAt:'invalid'}).length,0); | |
| assert.equal(compact(0),'0'); | |
| assert.equal(compact(null),''); | |
| assert.equal(Object.keys(COLORS).length,8); | |
| }); | |
| test('ZIP preserves order, UTF-8 names, CRC and contents (verified by Python)',async()=>{ | |
| const files=[new File(['first'],'01-model.jpg'),new File(['héllo'],'02-données.txt'),new File(['{"version":1}'],'selection.json')]; | |
| const zip=await makeZip(files); | |
| await mkdir('test-output',{recursive:true}); | |
| await writeFile('test-output/zip-test.zip',new Uint8Array(await zip.arrayBuffer())); | |
| assert.equal(zip.type,'application/zip'); | |
| }); | |
| test('overview keeps native spine proportions and caps large Wider shelves without cropping',()=>{ | |
| for(const mode of ['slim','wide','wider'])for(const count of [1,6,10,20]){ | |
| const g=overviewGeometry(count,mode); | |
| assert.ok(g.width*g.height<=12e6);assert.ok(g.width<=8192); | |
| assert.ok(Math.abs(g.width/g.height-g.logicalWidth/g.logicalHeight)<.01); | |
| assert.ok(g.scale<=1); | |
| } | |
| assert.equal(overviewGeometry(6,'wider').scale,1); | |
| assert.ok(overviewGeometry(20,'wider').scale<1); | |
| }); | |
| test('presentation slots distinguish unavailable metadata from zero and never invent hardware or dates',()=>{ | |
| for(const kind of ['space','model','dataset','paper','blog']){ | |
| const f=spineFacts({kind});assert.equal(f.primary.value,'—');assert.equal(f.community.value,'—'); | |
| } | |
| assert.equal(spineFacts({kind:'model',downloads:0,likes:0}).primary.value,'0'); | |
| assert.equal(spineFacts({kind:'model',downloads:0,likes:0}).community.value,'0'); | |
| assert.equal(spineFacts({kind:'paper',publishedAt:'invalid',upvotes:-1}).primary.value,'—'); | |
| assert.equal(spineFacts({kind:'paper',publishedAt:'invalid',upvotes:-1}).community.value,'—'); | |
| assert.equal(spineFacts({kind:'space',hardware:'CPU Upgrade'}).primary.value,'CPU Upgrade'); | |
| assert.equal(spineFacts({kind:'space',likes:999999}).community.value,'1M'); | |
| }); | |