@fframes/editor 1.3.1-rc.10 → 1.3.1-rc.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fframes/editor",
3
- "version": "1.3.1-rc.10",
3
+ "version": "1.3.1-rc.12",
4
4
  "public": true,
5
5
  "keywords": [
6
6
  "rescript"
@@ -0,0 +1,72 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { build } from "esbuild";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ // Exercise the real generated loader and TS resolvers together, with browser I/O mocked.
7
+ const bundle = await build({
8
+ stdin: {
9
+ contents: `
10
+ export { processMedia, MediaLoaderObserver } from "./src/services/mediaLoader.bs.js";
11
+ export { get as mediaAt } from "rescript/lib/es6/belt_MapString.js";
12
+ `,
13
+ resolveDir: fileURLToPath(new URL("../", import.meta.url)),
14
+ },
15
+ bundle: true,
16
+ platform: "node",
17
+ format: "esm",
18
+ write: false,
19
+ });
20
+
21
+ test("failed subtitles settle with asset errors while successful media remains usable", async t => {
22
+ globalThis.AudioContext = class {};
23
+ t.after(() => delete globalThis.AudioContext);
24
+ const { processMedia, MediaLoaderObserver, mediaAt } = await import(
25
+ `data:text/javascript;base64,${Buffer.from(bundle.outputFiles[0].text).toString("base64")}`
26
+ );
27
+ const controller = {
28
+ populate_static_fonts_db_with_static_fonts() {},
29
+ get_static_font_data_by_index() {},
30
+ get_static_audio_data_by_index() {},
31
+ add_subtitles_source: () => 2,
32
+ add_json_subtitles_source() {
33
+ throw new Error("invalid cue timing");
34
+ },
35
+ };
36
+ t.mock.method(globalThis, "fetch", async url => {
37
+ const status =
38
+ url === "/missing" ? 404 : url === "/unavailable" ? 503 : 200;
39
+ return new Response("subtitle data", { status });
40
+ });
41
+ const loading = processMedia(
42
+ {
43
+ "./missing.vtt": "/missing",
44
+ "./captions.json": "/unavailable",
45
+ "./invalid.json": "/invalid",
46
+ "./good.vtt": "/good",
47
+ },
48
+ controller,
49
+ {}
50
+ );
51
+ assert.equal(MediaLoaderObserver.get().allMediaLoaded, false);
52
+ await loading;
53
+ const state = MediaLoaderObserver.get();
54
+ assert.equal(state.allMediaLoaded, true);
55
+ for (const [file, message] of [
56
+ ["missing.vtt", /HTTP 404/],
57
+ ["captions.json", /HTTP 503/],
58
+ ["invalid.json", /invalid cue timing/],
59
+ ]) {
60
+ const asset = mediaAt(state.mediaList, file);
61
+ assert.equal(asset.TAG, 2, `${file} must be Error, not Loading`);
62
+ assert.match(asset._0, message);
63
+ }
64
+ assert.equal(mediaAt(state.mediaList, "good.vtt").TAG, 1);
65
+ const retry = processMedia({ "./missing.vtt": "/good" }, controller, {});
66
+ assert.equal(MediaLoaderObserver.get().allMediaLoaded, false);
67
+ await retry;
68
+ assert.equal(
69
+ mediaAt(MediaLoaderObserver.get().mediaList, "missing.vtt").TAG,
70
+ 1
71
+ );
72
+ });