Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Download tests/test_player.js from fffiloni/HF-Radio-MultiSource: direct link, hf CLI and curl.
- Browser
- Download file 3.34 kB
-
https://huggingface.co/spaces/fffiloni/HF-Radio-MultiSource/resolve/main/tests/test_player.js
- Command line
-
hf download hf://spaces/fffiloni/HF-Radio-MultiSource/tests/test_player.js
-
curl -L -o test_player.js https://huggingface.co/spaces/fffiloni/HF-Radio-MultiSource/resolve/main/tests/test_player.js
3.34 kB
| // Source-label behavior from the actual player script; no DOM/network packages needed. | |
| const assert = require('node:assert/strict'); | |
| const fs = require('node:fs'); | |
| const path = require('node:path'); | |
| const vm = require('node:vm'); | |
| const html = fs.readFileSync(path.join(__dirname, '../static/index.html'), 'utf8'); | |
| const source = html.slice(html.indexOf(' function safeSourceUrl('), html.indexOf(' function renderLiveStatus(')); | |
| class Element { | |
| constructor() { this.attributes = {}; this.children = []; this.textContent = ''; } | |
| removeAttribute(name) { delete this.attributes[name]; } | |
| set href(value) { this.attributes.href = value; } | |
| get href() { return this.attributes.href; } | |
| set title(value) { this.attributes.title = value; } | |
| replaceChildren() { this.children = []; } | |
| appendChild(element) { this.children.push(element); } | |
| } | |
| const context = { | |
| URL, trackOrigin: new Element(), trackSource: new Element(), trackSourceCaption: new Element(), | |
| sourceLinks: new Element(), renderedSourceLinks: null, | |
| document: { createElement: () => new Element() }, | |
| }; | |
| vm.createContext(context); | |
| vm.runInContext(source, context); | |
| for (const label of ['MiniMax Music 3', 'ACE-Step', 'A Future Model']) { | |
| context.renderTrackSource({ source_label: label, source_space_url: 'https://huggingface.co/spaces/owner/model' }); | |
| assert.equal(context.trackSource.textContent, label); | |
| assert.equal(context.trackSourceCaption.textContent, 'Generated with'); | |
| assert.equal(context.trackSource.href, 'https://huggingface.co/spaces/owner/model'); | |
| assert.equal(context.trackOrigin.hidden, false); | |
| } | |
| for (const [flag, label] of [['is_jingle', 'Station jingle'], ['is_segment', 'Editorial segment'], ['is_custom_track', 'Studio selection']]) { | |
| context.renderTrackSource({ [flag]: true, source_label: 'MiniMax Music 3', source_space_url: 'https://example.com' }); | |
| assert.equal(context.trackSource.textContent, label); | |
| assert.equal(context.trackSourceCaption.textContent, ''); | |
| assert.equal(context.trackSource.href, undefined); | |
| } | |
| context.renderTrackSource({ source_label: '<img src=x>', source_space_url: 'javascript:alert(1)' }); | |
| assert.equal(context.trackSource.textContent, '<img src=x>'); | |
| assert.equal(context.trackSource.href, undefined); | |
| context.renderTrackSource({}); | |
| assert.equal(context.trackSource.textContent, 'Community music'); | |
| assert.equal(context.trackSourceCaption.textContent, ''); | |
| context.renderTrackSource(null); | |
| assert.equal(context.trackOrigin.hidden, true); | |
| assert.equal(context.trackSource.textContent, ''); | |
| const sources = JSON.parse(fs.readFileSync(path.join(__dirname, '../music_sources.json'), 'utf8')).sources; | |
| context.renderSourceLinks(sources); | |
| assert.equal(context.sourceLinks.children.length, 2); | |
| context.renderSourceLinks([...sources, { id: 'future', label: 'Future Model', space_url: 'https://example.com/future' }]); | |
| assert.equal(context.sourceLinks.children.length, 3); | |
| assert.equal(context.sourceLinks.children[2].textContent, 'Create with Future Model'); | |
| context.renderSourceLinks([{ id: 'unsafe', label: 'Unsafe', space_url: 'javascript:alert(1)' }]); | |
| assert.equal(context.sourceLinks.children.length, 0); | |
| context.renderSourceLinks([]); | |
| assert.equal(context.sourceLinks.children.length, 0); | |
| console.log('Player source labels, model links, editorial transitions, future sources and empty states: OK'); | |