Best JavaScript code snippet using wpt
blob-url.any.js
Source:blob-url.any.js
1// META: global=window,dedicatedworker,sharedworker,dedicatedworker-module,sharedworker-module2function objectUrlFromModule(module) {3 const blob = new Blob([module], { type: "text/javascript" });4 return URL.createObjectURL(blob);5}6const moduleText = `export const foo = "bar";`;7promise_test(async (t) => {8 const moduleBlobUrl = objectUrlFromModule(moduleText);9 t.add_cleanup(() => URL.revokeObjectURL(moduleBlobUrl));10 const module = await import(moduleBlobUrl);11 assert_equals(module.foo, "bar");12}, "Blob URLs are supported in dynamic imports");13promise_test(async (t) => {14 const moduleBlobUrl = objectUrlFromModule(moduleText);15 t.add_cleanup(() => URL.revokeObjectURL(moduleBlobUrl));16 const module1 = await import(moduleBlobUrl);17 const module2 = await import(moduleBlobUrl);18 assert_equals(module1, module2);19}, "Identical blob URLs resolve to the same module");20promise_test(async (t) => {21 const moduleBlob = new Blob([moduleText], { type: "text/javascript" });22 const moduleBlobUrl1 = URL.createObjectURL(moduleBlob);23 const moduleBlobUrl2 = URL.createObjectURL(moduleBlob);24 t.add_cleanup(() => {25 URL.revokeObjectURL(moduleBlobUrl1);26 URL.revokeObjectURL(moduleBlobUrl2);27 });28 const module1 = await import(moduleBlobUrl1);29 const module2 = await import(moduleBlobUrl2);30 assert_not_equals(module1, module2);31}, "Different blob URLs pointing to the same blob resolve to different modules");32promise_test(async (t) => {33 const moduleBlobUrl = objectUrlFromModule(moduleText);34 URL.revokeObjectURL(moduleBlobUrl);35 await promise_rejects_js(t, TypeError, import(moduleBlobUrl));36}, "A revoked blob URL will not resolve");37promise_test(async () => {38 const moduleBlobUrl = objectUrlFromModule(moduleText);39 const module1 = await import(moduleBlobUrl);40 URL.revokeObjectURL(moduleBlobUrl);41 const module2 = await import(moduleBlobUrl);42 assert_equals(module1, module2);43}, "A revoked blob URL will resolve if it's already in the module graph");44promise_test(async () => {45 const moduleBlobUrl = objectUrlFromModule(moduleText);46 const importPromise = import(moduleBlobUrl);47 URL.revokeObjectURL(moduleBlobUrl);48 const module = await importPromise;49 assert_equals(module.foo, "bar");...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!