Fix webtorrent-regression.test.mjs failures

- Added import of `setup-localstorage.mjs` to polyfill `self` required by `webtorrent.min.js`.
- Updated `MockTorrent` to simulate webseed `wire` events, ensuring `probePeers` logic (which listens for wires) functions correctly in tests.

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-02-01 16:55:15 +00:00
1 parent c82ab2d490
commit 18bb9c244e
1 file changed
+13
+13
View File
@@ -1,4 +1,5 @@
import "./test-helpers/setup-localstorage.mjs";
import { test, describe, it, after, before } from "node:test";
import assert from "node:assert";
import EventEmitter from "events";
@@ -36,6 +37,18 @@ class MockTorrent extends EventEmitter {
this.opts = opts;
this.numPeers = 0;
this.files = [];
this.wires = [];
// Simulate webseeds if provided in opts
if (opts && Array.isArray(opts.urlList) && opts.urlList.length > 0) {
// Create mock wires for webseeds
this.wires = opts.urlList.map(url => ({ type: 'webSeed' }));
// Emit wire events asynchronously to simulate connection
setTimeout(() => {
this.wires.forEach(wire => this.emit('wire', wire));
}, 5);
}
}
destroy(opts, cb) {