How to use scriptURL method in wpt

Best JavaScript code snippet using wpt

module-duplication-test.js

Source:module-duplication-test.js Github

copy

Full Screen

1/**2 * @license Copyright 2020 The Lighthouse Authors. All Rights Reserved.3 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.04 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.5 */6'use strict';7/* eslint-env jest */8const ModuleDuplication = require('../../computed/module-duplication.js');9const {loadSourceMapFixture} = require('../test-utils.js');10describe('ModuleDuplication computed artifact', () => {11 it('works (simple)', async () => {12 const context = {computedCache: new Map()};13 const {map, content} = loadSourceMapFixture('foo.min');14 const artifacts = {15 SourceMaps: [16 {scriptUrl: 'https://example.com/foo1.min.js', map},17 {scriptUrl: 'https://example.com/foo2.min.js', map},18 ],19 ScriptElements: [20 {src: 'https://example.com/foo1.min.js', content},21 {src: 'https://example.com/foo2.min.js', content},22 ],23 };24 const results = await ModuleDuplication.request(artifacts, context);25 expect(results).toMatchInlineSnapshot(`Map {}`);26 });27 it('works (complex)', async () => {28 const context = {computedCache: new Map()};29 const bundleData1 = loadSourceMapFixture('coursehero-bundle-1');30 const bundleData2 = loadSourceMapFixture('coursehero-bundle-2');31 const artifacts = {32 SourceMaps: [33 {scriptUrl: 'https://example.com/coursehero-bundle-1.js', map: bundleData1.map},34 {scriptUrl: 'https://example.com/coursehero-bundle-2.js', map: bundleData2.map},35 ],36 ScriptElements: [37 {src: 'https://example.com/coursehero-bundle-1.js', content: bundleData1.content},38 {src: 'https://example.com/coursehero-bundle-2.js', content: bundleData2.content},39 ],40 };41 const results = await ModuleDuplication.request(artifacts, context);42 expect(results).toMatchInlineSnapshot(`43 Map {44 "Control/assets/js/vendor/ng/select/select.js" => Array [45 Object {46 "resourceSize": 48513,47 "scriptUrl": "https://example.com/coursehero-bundle-1.js",48 },49 Object {50 "resourceSize": 48513,51 "scriptUrl": "https://example.com/coursehero-bundle-2.js",52 },53 ],54 "Control/assets/js/vendor/ng/select/angular-sanitize.js" => Array [55 Object {56 "resourceSize": 9135,57 "scriptUrl": "https://example.com/coursehero-bundle-1.js",58 },59 Object {60 "resourceSize": 9135,61 "scriptUrl": "https://example.com/coursehero-bundle-2.js",62 },63 ],64 "node_modules/@babel/runtime/helpers/inherits.js" => Array [65 Object {66 "resourceSize": 528,67 "scriptUrl": "https://example.com/coursehero-bundle-1.js",68 },69 Object {70 "resourceSize": 528,71 "scriptUrl": "https://example.com/coursehero-bundle-2.js",72 },73 ],74 "node_modules/@babel/runtime/helpers/typeof.js" => Array [75 Object {76 "resourceSize": 992,77 "scriptUrl": "https://example.com/coursehero-bundle-1.js",78 },79 Object {80 "resourceSize": 992,81 "scriptUrl": "https://example.com/coursehero-bundle-2.js",82 },83 ],84 "js/src/utils/service/amplitude-service.ts" => Array [85 Object {86 "resourceSize": 1348,87 "scriptUrl": "https://example.com/coursehero-bundle-1.js",88 },89 Object {90 "resourceSize": 1325,91 "scriptUrl": "https://example.com/coursehero-bundle-2.js",92 },93 ],94 "js/src/utils/service/gsa-inmeta-tags.ts" => Array [95 Object {96 "resourceSize": 591,97 "scriptUrl": "https://example.com/coursehero-bundle-1.js",98 },99 Object {100 "resourceSize": 563,101 "scriptUrl": "https://example.com/coursehero-bundle-2.js",102 },103 ],104 "js/src/search/results/store/filter-actions.ts" => Array [105 Object {106 "resourceSize": 956,107 "scriptUrl": "https://example.com/coursehero-bundle-2.js",108 },109 Object {110 "resourceSize": 946,111 "scriptUrl": "https://example.com/coursehero-bundle-1.js",112 },113 ],114 "js/src/search/results/store/item/resource-types.ts" => Array [115 Object {116 "resourceSize": 783,117 "scriptUrl": "https://example.com/coursehero-bundle-1.js",118 },119 Object {120 "resourceSize": 775,121 "scriptUrl": "https://example.com/coursehero-bundle-2.js",122 },123 ],124 "js/src/search/results/store/filter-store.ts" => Array [125 Object {126 "resourceSize": 12717,127 "scriptUrl": "https://example.com/coursehero-bundle-1.js",128 },129 Object {130 "resourceSize": 12650,131 "scriptUrl": "https://example.com/coursehero-bundle-2.js",132 },133 ],134 "js/src/search/results/view/filter/autocomplete-list.tsx" => Array [135 Object {136 "resourceSize": 1143,137 "scriptUrl": "https://example.com/coursehero-bundle-2.js",138 },139 Object {140 "resourceSize": 1134,141 "scriptUrl": "https://example.com/coursehero-bundle-1.js",142 },143 ],144 "js/src/search/results/view/filter/autocomplete-filter.tsx" => Array [145 Object {146 "resourceSize": 3823,147 "scriptUrl": "https://example.com/coursehero-bundle-1.js",148 },149 Object {150 "resourceSize": 3812,151 "scriptUrl": "https://example.com/coursehero-bundle-2.js",152 },153 ],154 "js/src/search/results/view/filter/autocomplete-filter-with-icon.tsx" => Array [155 Object {156 "resourceSize": 2696,157 "scriptUrl": "https://example.com/coursehero-bundle-1.js",158 },159 Object {160 "resourceSize": 2693,161 "scriptUrl": "https://example.com/coursehero-bundle-2.js",162 },163 ],164 "js/src/search/results/service/api/filter-api-service.ts" => Array [165 Object {166 "resourceSize": 554,167 "scriptUrl": "https://example.com/coursehero-bundle-1.js",168 },169 Object {170 "resourceSize": 534,171 "scriptUrl": "https://example.com/coursehero-bundle-2.js",172 },173 ],174 "js/src/common/component/school-search.tsx" => Array [175 Object {176 "resourceSize": 5840,177 "scriptUrl": "https://example.com/coursehero-bundle-2.js",178 },179 Object {180 "resourceSize": 5316,181 "scriptUrl": "https://example.com/coursehero-bundle-1.js",182 },183 ],184 "js/src/common/component/search/abstract-taxonomy-search.tsx" => Array [185 Object {186 "resourceSize": 3103,187 "scriptUrl": "https://example.com/coursehero-bundle-1.js",188 },189 Object {190 "resourceSize": 3098,191 "scriptUrl": "https://example.com/coursehero-bundle-2.js",192 },193 ],194 "js/src/common/component/search/course-search.tsx" => Array [195 Object {196 "resourceSize": 545,197 "scriptUrl": "https://example.com/coursehero-bundle-2.js",198 },199 Object {200 "resourceSize": 544,201 "scriptUrl": "https://example.com/coursehero-bundle-1.js",202 },203 ],204 }205 `);206 });207 it('normalizeSource', () => {208 const testCases = [209 ['test.js', 'test.js'],210 ['node_modules/othermodule.js', 'node_modules/othermodule.js'],211 ['node_modules/somemodule/node_modules/othermodule.js', 'node_modules/othermodule.js'],212 [213 'node_modules/somemodule/node_modules/somemodule2/node_modules/othermodule.js',214 'node_modules/othermodule.js',215 ],216 ['webpack.js?', 'webpack.js'],217 ];218 for (const [input, expected] of testCases) {219 expect(ModuleDuplication.normalizeSource(input)).toBe(expected);220 }221 });222 describe('_normalizeAggregatedData', () => {223 it('removes entries with just one value', () => {224 const data = new Map([['a.js', [{resourceSize: 100}]]]);225 ModuleDuplication._normalizeAggregatedData(data);226 expect(data).toMatchInlineSnapshot(`Map {}`);227 });228 it('sorts entries based on resource size', () => {229 const data = new Map([230 ['a.js', [{resourceSize: 250}, {resourceSize: 200}]],231 ['b.js', [{resourceSize: 200}, {resourceSize: 250}]],232 ]);233 ModuleDuplication._normalizeAggregatedData(data);234 expect(data).toMatchInlineSnapshot(`Map {}`);235 });236 it('removes data if size is much smaller than the largest', () => {237 const data = new Map([238 ['a.js', [{resourceSize: 200}, {resourceSize: 1}, {resourceSize: 250}]],239 ['b.js', [{resourceSize: 250}, {resourceSize: 1}]],240 ]);241 ModuleDuplication._normalizeAggregatedData(data);242 expect(data).toMatchInlineSnapshot(`Map {}`);243 });244 });...

Full Screen

Full Screen

ca768eresolveAssetSource.js

Source:ca768eresolveAssetSource.js Github

copy

Full Screen

1'use strict';2var AssetRegistry = require('AssetRegistry');3var AssetSourceResolver = require('AssetSourceResolver');4var NativeModules = require('NativeModules');5var _customSourceTransformer = void 0,6 _serverURL = void 0,7 _bundleSourcePath = void 0;8function getDevServerURL() {9 if (_serverURL === undefined) {10 var scriptURL = NativeModules.SourceCode.scriptURL;11 var match = scriptURL && scriptURL.match(/^https?:\/\/.*?\//);12 if (match) {13 _serverURL = match[0];14 } else {15 _serverURL = null;16 }17 }18 return _serverURL;19}20function getBundleSourcePath() {21 if (_bundleSourcePath === undefined) {22 var scriptURL = NativeModules.SourceCode.scriptURL;23 if (!scriptURL) {24 _bundleSourcePath = null;25 return _bundleSourcePath;26 }27 if (scriptURL.startsWith('assets://')) {28 _bundleSourcePath = null;29 return _bundleSourcePath;30 }31 if (scriptURL.startsWith('file://')) {32 _bundleSourcePath = scriptURL.substring(7, scriptURL.lastIndexOf('/') + 1);33 } else {34 _bundleSourcePath = scriptURL.substring(0, scriptURL.lastIndexOf('/') + 1);35 }36 }37 return _bundleSourcePath;38}39function setCustomSourceTransformer(transformer) {40 _customSourceTransformer = transformer;41}42function resolveAssetSource(source) {43 if (typeof source === 'object') {44 return source;45 }46 var asset = AssetRegistry.getAssetByID(source);47 if (!asset) {48 return null;49 }50 var resolver = new AssetSourceResolver(getDevServerURL(), getBundleSourcePath(), asset);51 if (_customSourceTransformer) {52 return _customSourceTransformer(resolver);53 }54 return resolver.defaultAsset();55}56module.exports = resolveAssetSource;57module.exports.pickScale = AssetSourceResolver.pickScale;...

Full Screen

Full Screen

ide-worker.ts

Source:ide-worker.ts Github

copy

Full Screen

1/**2 * Copyright (c) 2020 Gitpod GmbH. All rights reserved.3 * Licensed under the GNU Affero General Public License (AGPL).4 * See License-AGPL.txt in the project root for license information.5 */6/**7 * Installs the proxy (shared) worker serving from the same origin to fetch content from the blobserve origin.8 */9export function install(): void {10 if (window.Worker) {11 const Worker = window.Worker;12 window.Worker = <any>function (scriptUrl: string | URL, options?: WorkerOptions) {13 return new Worker(proxyUrl(scriptUrl), options);14 };15 }16 if (window.SharedWorker) {17 const SharedWorker = window.SharedWorker;18 window.SharedWorker = <any>function (scriptUrl: string, options?: string | SharedWorkerOptions) {19 return new SharedWorker(proxyUrl(scriptUrl), options);20 };21 }22}23function proxyUrl(scriptUrl: string | URL | TrustedScriptURL): string {24 scriptUrl = scriptUrl instanceof URL ? scriptUrl : new URL(typeof scriptUrl === 'string' ? scriptUrl : scriptUrl.toString(), document.baseURI);25 if (scriptUrl.origin !== location.origin || (scriptUrl.protocol !== 'http:' && scriptUrl.protocol !== 'https:')) {26 return scriptUrl.toString();27 }28 return new URL('_supervisor/frontend/worker-proxy.js#' + encodeURI(scriptUrl.toString()), document.baseURI).toString();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var worker = new Worker(URL.createObjectURL(new Blob(['(',2 function() {3 onmessage = function(e) {4 postMessage('Worker: Message received from main script');5 var workerResult = 'Worker: Result: ' + (e.data[0] * e.data[1]);6 console.log('Worker: Posting message back to main script');7 postMessage(workerResult);8 }9 }.toString(),10 ')()'], {type: 'application/javascript'})));11worker.onmessage = function(e) {12 console.log('Main script: Message received from worker');13 console.log(e.data);14 worker.terminate();15 done();16}17onmessage = function(e) {18 postMessage('Worker: Message received from main script');19 var workerResult = 'Worker: Result: ' + (e.data[0] * e.data[1]);20 console.log('Worker: Posting message back to main script');21 postMessage(workerResult);22}23postMessage('Hello World');

Full Screen

Using AI Code Generation

copy

Full Screen

1console.log("Test scriptURL method of wpt");2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log(data);7 }8});9console.log("Test script method of wpt");10var wpt = new WebPageTest('www.webpagetest.org');11 if (err) {12 console.log('Error: ' + err);13 } else {14 console.log(data);15 }16});17console.log("Test script method of wpt");18var wpt = new WebPageTest('www.webpagetest.org');

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful