A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

test: components/engine/queue

+102 -15
+8
deno.jsonc
··· 35 35 "webamp": "npm:webamp@^2.2.0", 36 36 37 37 // Paths 38 + "@src/": "./src/", 39 + "@tests/": "./tests/", 40 + 38 41 "@common/": "./src/common/", 39 42 "@components/": "./src/components/", 40 43 "@definitions/": "./src/definitions/", ··· 50 53 "esbuild-plugin-wasm": "npm:esbuild-plugin-wasm@^1.1.0", 51 54 "lume/": "https://cdn.jsdelivr.net/gh/lumeland/lume@3.1.4/", 52 55 "lume/jsx-runtime": "https://cdn.jsdelivr.net/gh/oscarotero/ssx@0.1.14/jsx-runtime.ts", 56 + 57 + // Tests 58 + "@astral/astral": "jsr:@astral/astral", 59 + "@std/expect": "jsr:@std/expect", 60 + "@std/testing/bdd": "jsr:@std/testing/bdd", 53 61 }, 54 62 "exports": { 55 63 // .js
+5
src/common/element.js
··· 88 88 return this.#connected.promise; 89 89 } 90 90 91 + /** */ 92 + whenDefined() { 93 + return customElements.whenDefined(this.localName); 94 + } 95 + 91 96 /** 92 97 * Avoid replacing the whole subtree, 93 98 * morph the existing DOM into the new given tree.
-15
src/components/engine/queue/worker.js
··· 107 107 effect(() => announce("now", $now.value, context)); 108 108 effect(() => announce("past", $past.value, context)); 109 109 effect(() => announce("poolHash", $poolHash.value, context)); 110 - 111 - // When the pool changes, 112 - // make sure all future queue items still exist. 113 - effect(() => { 114 - const existing = new Set($lake.value.map((t) => t.id)); 115 - 116 - if ($now.value && !existing.has($now.value.id)) { 117 - // TODO: Shift queue instead? 118 - $now.value = null; 119 - } 120 - 121 - $future.value = $future.value.filter((i) => { 122 - return existing.has(i.id); 123 - }); 124 - }); 125 110 }); 126 111 127 112 ////////////////////////////////////////////
+17
src/testing/index.vto
··· 1 + --- 2 + layout: layouts/diffuse.vto 3 + 4 + base: "../" 5 + 6 + styles: 7 + - styles/base.css 8 + --- 9 + 10 + <script type="importmap"> 11 + { 12 + "imports": { 13 + "@components/": "./components/", 14 + "@src/": "./" 15 + } 16 + } 17 + </script>
+16
src/testing/sample/tracks.js
··· 1 + /** 2 + * @import { Track } from "@definitions/types.d.ts"; 3 + */ 4 + 5 + /** 6 + * @type {Track} 7 + */ 8 + const trackA = { 9 + $type: "sh.diffuse.output.tracks", 10 + id: "sample-a", 11 + uri: "http://example.com/audio-a.mp3", 12 + }; 13 + 14 + export const tracks = [ 15 + trackA, 16 + ];
+10
tests/common/index.ts
··· 1 + import { type EvaluateFunction, launch } from "@astral/astral"; 2 + 3 + export async function testWeb<T>(evalFn: EvaluateFunction<T, []>): Promise<T> { 4 + const url = "http://localhost:3000/testing/index.html"; 5 + 6 + await using browser = await launch(); 7 + await using page = await browser.newPage(url); 8 + 9 + return await page.evaluate(evalFn); 10 + }
+46
tests/components/engine/queue/test.ts
··· 1 + import { describe, it } from "@std/testing/bdd"; 2 + import { expect } from "@std/expect"; 3 + 4 + import { testWeb } from "@tests/common/index.ts"; 5 + import { tracks } from "@src/testing/sample/tracks.js"; 6 + 7 + import type { Item } from "@components/engine/queue/types.d.ts"; 8 + 9 + describe("components/engine/queue", () => { 10 + it("adds tracks", async () => { 11 + const items = await testWeb(async () => { 12 + const QueueEngine = await import("@components/engine/queue/element.js"); 13 + const engine = new QueueEngine.CLASS(); 14 + 15 + document.body.append(engine); 16 + 17 + const { tracks } = await import("@src/testing/sample/tracks.js"); 18 + 19 + await engine.add({ tracks }); 20 + return engine.future(); 21 + }); 22 + 23 + expect(items.map((i) => i.id).join("/")).toBe( 24 + tracks.map((t) => t.id).join("/"), 25 + ); 26 + }); 27 + 28 + it("pools + fills tracks and shifts the queue", async () => { 29 + const item = await testWeb(async () => { 30 + const QueueEngine = await import("@components/engine/queue/element.js"); 31 + const engine = new QueueEngine.CLASS(); 32 + 33 + document.body.append(engine); 34 + 35 + const { tracks } = await import("@src/testing/sample/tracks.js"); 36 + 37 + await engine.pool(tracks); 38 + await engine.fill({ amount: 1, shuffled: false }); 39 + await engine.shift(); 40 + 41 + return engine.now(); 42 + }); 43 + 44 + expect(item?.id).toBe(tracks[0].id); 45 + }); 46 + });