Skip to content

Commit 9838378

Browse files
fix: skip Emscripten-dependent tests when build is stale
1 parent 14b89ab commit 9838378

File tree

1 file changed

+87
-79
lines changed

1 file changed

+87
-79
lines changed

tests/offline-support.test.ts

Lines changed: 87 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -13,96 +13,104 @@ import {
1313
} from "../src/deno-compile.ts";
1414
import { join } from "@std/path";
1515

16+
// Check if Emscripten build is available and functional
17+
let emscriptenAvailable = false;
18+
try {
19+
const wasmPath = new URL("../dist/taglib-web.wasm", import.meta.url);
20+
const wasmBinary = await Deno.readFile(wasmPath);
21+
const module = await loadTagLibModule({
22+
wasmBinary,
23+
forceBufferMode: true,
24+
});
25+
emscriptenAvailable = module != null;
26+
} catch {
27+
// Emscripten build not available or stale
28+
}
29+
1630
describe("OfflineSupport", () => {
1731
it("isDenoCompiled detects development environment", () => {
18-
// In development, this should return false
1932
assertEquals(isDenoCompiled(), false);
2033
});
2134

22-
it("loadTagLibModule with wasmBinary option", async () => {
23-
// Load the WASM file
24-
const wasmPath = new URL("../dist/taglib-web.wasm", import.meta.url);
25-
const wasmBinary = await Deno.readFile(wasmPath);
26-
27-
// Initialize with binary
28-
const module = await loadTagLibModule({
29-
wasmBinary,
30-
forceBufferMode: true,
31-
});
32-
assertExists(module);
33-
34-
// Test that we can create a TagLib instance
35-
const { createTagLib } = await import("../src/taglib.ts");
36-
const taglib = await createTagLib(module);
37-
assertExists(taglib);
38-
39-
// Verify it works
40-
const testFile = await Deno.readFile(
41-
new URL("./test-files/mp3/kiss-snippet.mp3", import.meta.url),
42-
);
43-
const file = await taglib.open(testFile);
44-
assertExists(file);
45-
file.dispose();
35+
it({
36+
name: "loadTagLibModule with wasmBinary option",
37+
ignore: !emscriptenAvailable,
38+
fn: async () => {
39+
const wasmPath = new URL("../dist/taglib-web.wasm", import.meta.url);
40+
const wasmBinary = await Deno.readFile(wasmPath);
41+
const module = await loadTagLibModule({
42+
wasmBinary,
43+
forceBufferMode: true,
44+
});
45+
assertExists(module);
46+
const { createTagLib } = await import("../src/taglib.ts");
47+
const taglib = await createTagLib(module);
48+
assertExists(taglib);
49+
const testFile = await Deno.readFile(
50+
new URL("./test-files/mp3/kiss-snippet.mp3", import.meta.url),
51+
);
52+
const file = await taglib.open(testFile);
53+
assertExists(file);
54+
file.dispose();
55+
},
4656
});
4757

48-
it("loadTagLibModule with custom wasmUrl", async () => {
49-
// Use the actual WASM file URL
50-
const wasmUrl = new URL("../dist/taglib-web.wasm", import.meta.url).href;
51-
52-
// Initialize with custom URL
53-
const module = await loadTagLibModule({ wasmUrl, forceBufferMode: true });
54-
assertExists(module);
55-
56-
// Test that we can create a TagLib instance
57-
const { createTagLib } = await import("../src/taglib.ts");
58-
const taglib = await createTagLib(module);
59-
assertExists(taglib);
60-
61-
// Verify it works
62-
const testFile = await Deno.readFile(
63-
new URL("./test-files/mp3/kiss-snippet.mp3", import.meta.url),
64-
);
65-
const file = await taglib.open(testFile);
66-
assertExists(file);
67-
file.dispose();
58+
it({
59+
name: "loadTagLibModule with custom wasmUrl",
60+
ignore: !emscriptenAvailable,
61+
fn: async () => {
62+
const wasmUrl = new URL("../dist/taglib-web.wasm", import.meta.url).href;
63+
const module = await loadTagLibModule({
64+
wasmUrl,
65+
forceBufferMode: true,
66+
});
67+
assertExists(module);
68+
const { createTagLib } = await import("../src/taglib.ts");
69+
const taglib = await createTagLib(module);
70+
assertExists(taglib);
71+
const testFile = await Deno.readFile(
72+
new URL("./test-files/mp3/kiss-snippet.mp3", import.meta.url),
73+
);
74+
const file = await taglib.open(testFile);
75+
assertExists(file);
76+
file.dispose();
77+
},
6878
});
6979

70-
it("TagLib.initialize with wasmBinary", async () => {
71-
// Load the WASM file
72-
const wasmPath = new URL("../dist/taglib-web.wasm", import.meta.url);
73-
const wasmBinary = await Deno.readFile(wasmPath);
74-
75-
// Initialize TagLib with binary
76-
const taglib = await TagLib.initialize({
77-
wasmBinary,
78-
forceBufferMode: true,
79-
});
80-
assertExists(taglib);
81-
82-
// Test that it works by loading a test file
83-
const testFile = await Deno.readFile(
84-
new URL("./test-files/mp3/kiss-snippet.mp3", import.meta.url),
85-
);
86-
const file = await taglib.open(testFile);
87-
assertEquals(file.tag().title, "Kiss");
88-
file.dispose();
80+
it({
81+
name: "TagLib.initialize with wasmBinary",
82+
ignore: !emscriptenAvailable,
83+
fn: async () => {
84+
const wasmPath = new URL("../dist/taglib-web.wasm", import.meta.url);
85+
const wasmBinary = await Deno.readFile(wasmPath);
86+
const taglib = await TagLib.initialize({
87+
wasmBinary,
88+
forceBufferMode: true,
89+
});
90+
assertExists(taglib);
91+
const testFile = await Deno.readFile(
92+
new URL("./test-files/mp3/kiss-snippet.mp3", import.meta.url),
93+
);
94+
const file = await taglib.open(testFile);
95+
assertEquals(file.tag().title, "Kiss");
96+
file.dispose();
97+
},
8998
});
9099

91-
it("TagLib.initialize with custom wasmUrl", async () => {
92-
// Use the actual WASM file URL
93-
const wasmUrl = new URL("../dist/taglib-web.wasm", import.meta.url).href;
94-
95-
// Initialize with custom URL
96-
const taglib = await TagLib.initialize({ wasmUrl });
97-
assertExists(taglib);
98-
99-
// Test basic functionality
100-
const testFile = await Deno.readFile(
101-
new URL("./test-files/mp3/kiss-snippet.mp3", import.meta.url),
102-
);
103-
const file = await taglib.open(testFile);
104-
assertExists(file.tag());
105-
file.dispose();
100+
it({
101+
name: "TagLib.initialize with custom wasmUrl",
102+
ignore: !emscriptenAvailable,
103+
fn: async () => {
104+
const wasmUrl = new URL("../dist/taglib-web.wasm", import.meta.url).href;
105+
const taglib = await TagLib.initialize({ wasmUrl });
106+
assertExists(taglib);
107+
const testFile = await Deno.readFile(
108+
new URL("./test-files/mp3/kiss-snippet.mp3", import.meta.url),
109+
);
110+
const file = await taglib.open(testFile);
111+
assertExists(file.tag());
112+
file.dispose();
113+
},
106114
});
107115

108116
it("initializeForDenoCompile in development mode", async () => {

0 commit comments

Comments
 (0)