How to use makeTestUrl method in wpt

Best JavaScript code snippet using wpt

analysis.spec.ts

Source:analysis.spec.ts Github

copy

Full Screen

...15} from "../../../src";16import { DocumentDateField, DocumentSelectionMarkField } from "../../../src/models/fields";17import { createRecorder, makeCredential, testPollingOptions } from "../../utils/recordedClients";18const endpoint = (): string => env.FORM_RECOGNIZER_ENDPOINT;19function makeTestUrl(urlPath: string): string {20 const testingContainerUrl = env.FORM_RECOGNIZER_TESTING_CONTAINER_SAS_URL;21 const parts = testingContainerUrl.split("?");22 return `${parts[0]}${urlPath}?${parts[1]}`;23}24function assertDefined(value: unknown, message?: string): asserts value {25 return assert.ok(value, message);26}27matrix([[true, false]] as const, async (useAad) => {28 describe(`[${useAad ? "AAD" : "API Key"}] FormRecognizerClient NodeJS only`, () => {29 const ASSET_PATH = path.resolve(path.join(process.cwd(), "assets"));30 let client: DocumentAnalysisClient;31 let recorder: Recorder;32 beforeEach(function (this: Context) {33 recorder = createRecorder(this);34 client = new DocumentAnalysisClient(endpoint(), makeCredential(useAad));35 });36 afterEach(async function () {37 if (recorder) {38 await recorder.stop();39 }40 });41 describe("content analysis", () => {42 it("pdf file stream", async () => {43 const filePath = path.join(ASSET_PATH, "forms", "Invoice_1.pdf");44 const stream = fs.createReadStream(filePath);45 const poller = await client.beginExtractLayout(stream, testPollingOptions);46 const { pages, tables } = await poller.pollUntilDone();47 assert.ok(pages && pages.length > 0, `Expected non-empty pages but got ${pages}`);48 assert.isNotEmpty(pages);49 assert.isNotEmpty(tables);50 const [table] = tables!;51 assert.ok(table.boundingRegions?.[0]);52 assert.equal(table.boundingRegions?.[0].pageNumber, 1);53 });54 it("png file stream", async () => {55 const filePath = path.join(ASSET_PATH, "receipt", "contoso-receipt.png");56 const stream = fs.createReadStream(filePath);57 const poller = await client.beginExtractLayout(stream, testPollingOptions);58 const { pages } = await poller.pollUntilDone();59 assert.ok(pages && pages.length > 0, `Expect no-empty pages but got ${pages}`);60 });61 it("jpeg file stream", async () => {62 const filePath = path.join(ASSET_PATH, "forms", "Form_1.jpg");63 const stream = fs.createReadStream(filePath);64 const poller = await client.beginExtractLayout(stream, testPollingOptions);65 const { pages, tables } = await poller.pollUntilDone();66 assert.isNotEmpty(pages);67 assert.isNotEmpty(tables);68 const [table] = tables;69 assert.ok(table.boundingRegions?.[0].boundingBox);70 assert.equal(table.boundingRegions?.[0].pageNumber, 1);71 });72 it("tiff file stream", async () => {73 const filePath = path.join(ASSET_PATH, "forms", "Invoice_1.tiff");74 const stream = fs.createReadStream(filePath);75 const poller = await client.beginExtractLayout(stream, testPollingOptions);76 const { pages, tables } = await poller.pollUntilDone();77 assert.isNotEmpty(pages);78 assert.isNotEmpty(tables);79 const [table] = tables;80 assert.ok(table.boundingRegions?.[0].boundingBox);81 assert.equal(table.boundingRegions?.[0].pageNumber, 1);82 });83 it("pdf file stream without passing content type", async () => {84 const filePath = path.join(ASSET_PATH, "forms", "Invoice_1.pdf");85 const stream = fs.createReadStream(filePath);86 const poller = await client.beginExtractLayout(stream, testPollingOptions);87 const { pages, tables } = await poller.pollUntilDone();88 assert.isNotEmpty(pages);89 assert.isNotEmpty(tables);90 const [table] = tables;91 assert.ok(table.boundingRegions?.[0].boundingBox);92 assert.equal(table.boundingRegions?.[0].pageNumber, 1);93 });94 it("url", async () => {95 const url = makeTestUrl("/Invoice_1.pdf");96 const poller = await client.beginExtractLayout(url, testPollingOptions);97 const { pages, tables } = await poller.pollUntilDone();98 assert.isNotEmpty(pages);99 assert.isNotEmpty(tables);100 const [table] = tables;101 assert.ok(table.boundingRegions?.[0].boundingBox);102 assert.equal(table.boundingRegions?.[0].pageNumber, 1);103 });104 it("with selection marks", async () => {105 const filePath = path.join(ASSET_PATH, "forms", "selection_mark_form.pdf");106 const stream = fs.createReadStream(filePath);107 const poller = await client.beginExtractLayout(stream, testPollingOptions);108 const { pages } = await poller.pollUntilDone();109 assert.isNotEmpty(pages);110 /* There should be a table on the page, but the layout engine does not recognize it, maybe because it is too small and sparse.111 assert.isNotEmpty(tables);112 const [table] = tables;113 assert.ok(table.boundingRegions?.[0].boundingBox);114 assert.equal(table.boundingRegions?.[0].pageNumber, 1);*/115 assert.equal(pages[0].pageNumber, 1);116 assert.isNotEmpty(pages[0].selectionMarks);117 });118 it("specifying locale", async () => {119 const url = makeTestUrl("/Invoice_1.pdf");120 // Just make sure that this doesn't throw121 const poller = await client.beginExtractLayout(url, {122 locale: "en-US",123 ...testPollingOptions,124 });125 await poller.pollUntilDone();126 });127 it("invalid locale throws", async () => {128 const url = makeTestUrl("/Invoice_1.pdf");129 try {130 const poller = await client.beginExtractLayout(url, {131 locale: "thisIsNotAValidLanguage",132 ...testPollingOptions,133 });134 await poller.pollUntilDone();135 assert.fail("Expected an exception due to invalid language.");136 } catch (ex) {137 // Just make sure we didn't get a bad error message138 assert.isFalse((ex as Error).message.includes("<empty>"));139 }140 });141 it("specifying pages", async () => {142 const url = makeTestUrl("/Invoice_1.pdf");143 // Just make sure that this doesn't throw144 const poller = await client.beginExtractLayout(url, {145 pages: "1",146 ...testPollingOptions,147 });148 await poller.pollUntilDone();149 });150 it("invalid pages throws", async () => {151 const url = makeTestUrl("/Invoice_1.pdf");152 try {153 const poller = await client.beginExtractLayout(url, {154 // No page 2 in document155 pages: "2",156 ...testPollingOptions,157 });158 await poller.pollUntilDone();159 assert.fail("Expected an exception due to invalid pages.");160 } catch (ex) {161 // Just make sure we didn't get a bad error message162 assert.isFalse((ex as Error).message.includes("<empty>"));163 }164 });165 });166 describe("custom forms", () => {167 let _model: ModelInfo;168 let modelName: string;169 // We only want to create the model once, but because of the recorder's170 // precedence, we have to create it in a test, so one test will end up171 // recording the entire creation and the other tests will still be able172 // to use it.173 async function requireModel(): Promise<ModelInfo> {174 if (!_model) {175 const trainingClient = new DocumentModelAdministrationClient(176 endpoint(),177 makeCredential(useAad)178 );179 modelName = recorder.getUniqueName("customFormModelName");180 const poller = await trainingClient.beginBuildModel(181 modelName,182 env.FORM_RECOGNIZER_SELECTION_MARK_STORAGE_CONTAINER_SAS_URL,183 testPollingOptions184 );185 _model = await poller.pollUntilDone();186 assert.ok(_model.modelId);187 }188 return _model;189 }190 it("with selection marks", async () => {191 const { modelId } = await requireModel();192 const filePath = path.join(ASSET_PATH, "forms", "selection_mark_form.pdf");193 const stream = fs.createReadStream(filePath);194 const poller = await client.beginAnalyzeDocuments(modelId, stream, testPollingOptions);195 const {196 pages: [page],197 documents: [result],198 } = await poller.pollUntilDone();199 assert.ok(result);200 assert.equal(result.docType, `${modelName}:${modelName}`);201 const amexMark = result.fields["AMEX_SELECTION_MARK"] as DocumentSelectionMarkField;202 assert.equal(amexMark.kind, "selectionMark");203 assert.equal(amexMark.value, "selected");204 assert.ok(page);205 /* There should be a table in the response, but it isn't recognized (maybe because it's too small or sparse)206 assert.isNotEmpty(tables);207 const [table] = tables!;208 assert.ok(table.boundingRegions?.[0].boundingBox);209 assert.equal(table.boundingRegions?.[0].pageNumber, 1);*/210 assert.equal(page.pageNumber, 1);211 assert.isNotEmpty(page.selectionMarks);212 });213 });214 describe("receipts", () => {215 it("png file stream", async () => {216 const filePath = path.join(ASSET_PATH, "receipt", "contoso-receipt.png");217 const stream = fs.createReadStream(filePath);218 const poller = await client.beginAnalyzeDocuments(219 PrebuiltModels.Receipt,220 stream,221 testPollingOptions222 );223 const {224 documents,225 documents: [receipt],226 } = await poller.pollUntilDone();227 assert.isNotEmpty(documents);228 assert.equal(receipt.docType, "prebuilt:receipt");229 assert.equal(receipt.fields.receiptType?.value, "Itemized");230 assert.ok(receipt.fields.tax?.value, "Expecting valid 'Tax' field");231 assert.equal(receipt.fields.tax?.kind, "number");232 assert.ok(receipt.fields.total, "Expecting valid 'Total' field");233 assert.equal(receipt.fields.total?.kind, "number");234 assert.equal(receipt.fields.total?.value, 1203.39);235 });236 it("jpeg file stream", async () => {237 const filePath = path.join(ASSET_PATH, "receipt", "contoso-allinone.jpg");238 const stream = fs.createReadStream(filePath);239 const poller = await client.beginAnalyzeDocuments(240 PrebuiltModels.Receipt,241 stream,242 testPollingOptions243 );244 const {245 documents,246 documents: [receipt],247 } = await poller.pollUntilDone();248 assert.isNotEmpty(documents);249 assert.equal(receipt.docType, "prebuilt:receipt");250 });251 it("url", async () => {252 const url = makeTestUrl("/contoso-allinone.jpg");253 const poller = await client.beginAnalyzeDocuments(254 PrebuiltModels.Receipt,255 url,256 testPollingOptions257 );258 const {259 documents,260 documents: [receipt],261 } = await poller.pollUntilDone();262 assert.isNotEmpty(documents);263 assert.equal(receipt.docType, "prebuilt:receipt");264 });265 it("multi-page receipt with blank page", async () => {266 const filePath = path.join(ASSET_PATH, "receipt", "multipage_invoice1.pdf");267 const stream = fs.createReadStream(filePath);268 const poller = await client.beginAnalyzeDocuments(269 PrebuiltModels.Receipt,270 stream,271 testPollingOptions272 );273 const {274 documents,275 documents: [receipt],276 } = await poller.pollUntilDone();277 assert.isNotEmpty(documents);278 assert.equal(receipt.docType, "prebuilt:receipt");279 });280 it("specifying locale", async () => {281 const url = makeTestUrl("/contoso-allinone.jpg");282 // Just make sure that this doesn't throw283 const poller = await client.beginAnalyzeDocuments(PrebuiltModels.Receipt, url, {284 locale: "en-IN",285 ...testPollingOptions,286 });287 await poller.pollUntilDone();288 });289 it("invalid locale throws", async () => {290 const url = makeTestUrl("/contoso-allinone.jpg");291 try {292 const poller = await client.beginAnalyzeDocuments(PrebuiltModels.Receipt, url, {293 locale: "thisIsNotAValidLocaleString",294 ...testPollingOptions,295 });296 await poller.pollUntilDone();297 assert.fail("Expected an exception due to invalid locale.");298 } catch (ex) {299 // Just make sure we didn't get a bad error message300 assert.isFalse((ex as Error).message.includes("<empty>"));301 }302 });303 });304 describe("business cards", () => {305 const expectedArrayFieldValues = {306 jobTitles: "Senior Researcher",307 departments: "Cloud & Al Department",308 emails: "avery.smith@contoso.com",309 websites: "https://www.contoso.com/",310 // TODO: service bug causes phone numbers not to be normalized311 // Faxes: "+44 (0) 20 6789 2345",312 // WorkPhones: "+44 (0) 20 9876 5432",313 // MobilePhones: "+44 (0) 7911 123456",314 addresses: "2 Kingdom Street Paddington, London, W2 6BD",315 companyNames: "Contoso",316 } as const;317 it("jpg file stream", async () => {318 const filePath = path.join(ASSET_PATH, "businessCard", "business-card-english.jpg");319 const stream = fs.createReadStream(filePath);320 const poller = await client.beginAnalyzeDocuments(321 PrebuiltModels.BusinessCard,322 stream,323 testPollingOptions324 );325 const {326 documents,327 documents: [businessCard],328 } = await poller.pollUntilDone();329 assert.isNotEmpty(documents);330 const contactNames = businessCard.fields.contactNames;331 assertDefined(contactNames);332 assert.equal(contactNames.kind, "array");333 assert.equal(contactNames.values.length, 1);334 const nameItem = contactNames.values[0];335 assert.equal(nameItem.properties.firstName?.value, "Avery");336 assert.equal(nameItem.properties.lastName?.value, "Smith");337 for (const [fieldName, expectedValue] of Object.entries(expectedArrayFieldValues) as [338 keyof typeof expectedArrayFieldValues,339 string340 ][]) {341 const field = businessCard.fields[fieldName];342 assert.isNotEmpty(field?.values);343 const value = field?.values[0].value;344 assert.equal(value, expectedValue);345 }346 });347 it("url", async () => {348 const url = makeTestUrl("/businessCard.png");349 const poller = await client.beginAnalyzeDocuments(350 PrebuiltModels.BusinessCard,351 url,352 testPollingOptions353 );354 const {355 documents,356 documents: [businessCard],357 } = await poller.pollUntilDone();358 assert.isNotEmpty(documents);359 const contactNames = businessCard.fields.contactNames;360 assertDefined(contactNames);361 assert.equal(contactNames.kind, "array");362 assert.equal(contactNames.values.length, 1);363 const nameItem = contactNames.values[0];364 assert.equal(nameItem.properties.firstName?.value, "Avery");365 assert.equal(nameItem.properties.lastName?.value, "Smith");366 for (const [fieldName, expectedValue] of Object.entries(expectedArrayFieldValues) as [367 keyof typeof expectedArrayFieldValues,368 string369 ][]) {370 const field = businessCard.fields[fieldName];371 assert.isNotEmpty(field?.values);372 const value = field?.values[0].value;373 assert.equal(value, expectedValue);374 }375 });376 it("specifying locale", async () => {377 const url = makeTestUrl("/businessCard.jpg");378 // Just make sure that this doesn't throw379 const poller = await client.beginAnalyzeDocuments(PrebuiltModels.BusinessCard, url, {380 locale: "en-IN",381 ...testPollingOptions,382 });383 await poller.pollUntilDone();384 });385 it("invalid locale throws", async () => {386 const url = makeTestUrl("/businessCard.jpg");387 try {388 const poller = await client.beginAnalyzeDocuments(PrebuiltModels.BusinessCard, url, {389 locale: "thisIsNotAValidLocaleString",390 ...testPollingOptions,391 });392 await poller.pollUntilDone();393 assert.fail("Expected an exception due to invalid locale.");394 } catch (ex) {395 // Just make sure we didn't get a bad error message396 assert.isFalse((ex as Error).message.includes("<empty>"));397 }398 });399 });400 describe("invoices", () => {401 const expectedFieldValues = {402 vendorName: "Contoso",403 vendorAddress: "1 Redmond way Suite 6000 Redmond, WA 99243",404 customerAddressRecipient: "Microsoft",405 customerAddress: "1020 Enterprise Way Sunnayvale, CA 87659",406 customerName: "Microsoft",407 invoiceId: "34278587",408 // TODO: model regression409 // InvoiceTotal: 56651.49410 } as const;411 const expectedDateValues = {412 invoiceDate: new Date("June 18, 2017 00:00:00+0000"),413 dueDate: new Date("June 24, 2017 00:00:00+0000"),414 } as const;415 it("pdf file stream", async () => {416 const filePath = path.join(ASSET_PATH, "invoice", "Invoice_1.pdf");417 const stream = fs.createReadStream(filePath);418 const poller = await client.beginAnalyzeDocuments(419 PrebuiltModels.Invoice,420 stream,421 testPollingOptions422 );423 const {424 documents,425 documents: [invoice],426 pages,427 tables,428 } = await poller.pollUntilDone();429 assert.isNotEmpty(documents);430 assert.isNotEmpty(pages);431 assert.isNotEmpty(tables);432 const [table] = tables!;433 assert.ok(table.boundingRegions?.[0].boundingBox);434 assert.equal(table.boundingRegions?.[0].pageNumber, 1);435 for (const [fieldName, expectedValue] of Object.entries(expectedFieldValues) as [436 keyof typeof expectedFieldValues,437 string438 ][]) {439 const field = invoice.fields[fieldName];440 assert.equal(field?.value, expectedValue);441 }442 for (const [fieldName, expectedDate] of Object.entries(expectedDateValues) as [443 keyof typeof expectedDateValues,444 Date445 ][]) {446 const { value: date } = invoice.fields[fieldName] as DocumentDateField;447 assert.equal(date?.getDate(), expectedDate.getDate());448 assert.equal(date?.getMonth(), expectedDate.getMonth());449 assert.equal(date?.getFullYear(), expectedDate.getFullYear());450 }451 });452 it("url", async () => {453 const url = makeTestUrl("/Invoice_1.pdf");454 const poller = await client.beginAnalyzeDocuments(455 PrebuiltModels.Invoice,456 url,457 testPollingOptions458 );459 const {460 documents,461 documents: [invoice],462 pages,463 tables,464 } = await poller.pollUntilDone();465 assert.isNotEmpty(documents);466 assert.isNotEmpty(pages);467 assert.isNotEmpty(tables);468 const [table] = tables!;469 assert.ok(table.boundingRegions?.[0].boundingBox);470 assert.equal(table.boundingRegions?.[0].pageNumber, 1);471 for (const [fieldName, expectedValue] of Object.entries(expectedFieldValues) as [472 keyof typeof expectedFieldValues,473 string474 ][]) {475 const field = invoice.fields[fieldName];476 assert.equal(field?.value, expectedValue);477 }478 for (const [fieldName, expectedDate] of Object.entries(expectedDateValues) as [479 keyof typeof expectedDateValues,480 Date481 ][]) {482 const { value: date } = invoice.fields[fieldName] as DocumentDateField;483 assert.equal(date?.getDate(), expectedDate.getDate());484 assert.equal(date?.getMonth(), expectedDate.getMonth());485 assert.equal(date?.getFullYear(), expectedDate.getFullYear());486 }487 });488 it("invalid locale throws", async () => {489 const url = makeTestUrl("/Invoice_1.pdf");490 try {491 const poller = await client.beginAnalyzeDocuments(PrebuiltModels.Invoice, url, {492 locale: "thisIsNotAValidLocaleString",493 ...testPollingOptions,494 });495 await poller.pollUntilDone();496 assert.fail("Expected an exception due to invalid locale.");497 } catch (ex) {498 // Just make sure we didn't get a bad error message499 assert.isFalse((ex as Error).message.includes("<empty>"));500 }501 });502 });503 describe("identityDocuments", () => {504 const expectedFieldValues = {505 firstName: "LIAM R.",506 lastName: "TALBOT",507 documentNumber: "WDLABCD456DG",508 sex: "M",509 address: "123 STREET ADDRESS YOUR CITY WA 99999-1234",510 countryRegion: "USA",511 region: "Washington",512 } as const;513 const expectedDateValues = {514 dateOfBirth: new Date("January 6, 1958 00:00:00+0000"),515 dateOfExpiration: new Date("August 12, 2020 00:00:00+0000"),516 } as const;517 it("jpg file stream", async () => {518 const filePath = path.join(ASSET_PATH, "identityDocument", "license.jpg");519 const stream = fs.createReadStream(filePath);520 const poller = await client.beginAnalyzeDocuments(521 PrebuiltModels.IdentityDocument,522 stream,523 testPollingOptions524 );525 const {526 documents,527 documents: [idDocumentNaive],528 pages,529 } = await poller.pollUntilDone();530 assert.isNotEmpty(documents);531 assert.equal(idDocumentNaive.docType, "prebuilt:idDocument:driverLicense");532 const idDocument = idDocumentNaive as Extract<533 IdentityDocument,534 { docType: "prebuilt:idDocument:driverLicense" }535 >;536 assert.isNotEmpty(pages);537 for (const [fieldName, expectedValue] of Object.entries(expectedFieldValues) as [538 keyof typeof expectedFieldValues,539 string540 ][]) {541 const field = idDocument.fields[fieldName];542 assert.equal(field?.value, expectedValue);543 }544 for (const [fieldName, expectedDate] of Object.entries(expectedDateValues) as [545 keyof typeof expectedDateValues,546 Date547 ][]) {548 const { value: date } = idDocument.fields[fieldName] as DocumentDateField;549 assert.equal(date?.getDate(), expectedDate.getDate());550 assert.equal(date?.getMonth(), expectedDate.getMonth());551 assert.equal(date?.getFullYear(), expectedDate.getFullYear());552 }553 });554 it("url", async () => {555 const url = makeTestUrl("/license.jpg");556 const poller = await client.beginAnalyzeDocuments(557 PrebuiltModels.IdentityDocument,558 url,559 testPollingOptions560 );561 const {562 documents,563 documents: [idDocumentNaive],564 pages,565 } = await poller.pollUntilDone();566 assert.isNotEmpty(documents);567 assert.equal(idDocumentNaive.docType, "prebuilt:idDocument:driverLicense");568 const idDocument = idDocumentNaive as Extract<569 IdentityDocument,570 { docType: "prebuilt:idDocument:driverLicense" }571 >;572 assert.isNotEmpty(pages);573 for (const [fieldName, expectedValue] of Object.entries(expectedFieldValues) as [574 keyof typeof expectedFieldValues,575 string576 ][]) {577 const field = idDocument.fields[fieldName];578 assert.equal(field?.value, expectedValue);579 }580 for (const [fieldName, expectedDate] of Object.entries(expectedDateValues) as [581 keyof typeof expectedDateValues,582 Date583 ][]) {584 const { value: date } = idDocument.fields[fieldName] as DocumentDateField;585 assert.equal(date?.getDate(), expectedDate.getDate());586 assert.equal(date?.getMonth(), expectedDate.getMonth());587 assert.equal(date?.getFullYear(), expectedDate.getFullYear());588 }589 });590 it("invalid locale throws", async () => {591 const url = makeTestUrl("/license.jpg");592 try {593 const poller = await client.beginAnalyzeDocuments(PrebuiltModels.IdentityDocument, url, {594 locale: "thisIsNotAValidLocaleString",595 ...testPollingOptions,596 });597 await poller.pollUntilDone();598 assert.fail("Expected an exception due to invalid locale.");599 } catch (ex) {600 // Just make sure we didn't get a bad error message601 assert.isFalse((ex as Error).message.includes("<empty>"));602 }603 });604 });605 }).timeout(60000);...

Full Screen

Full Screen

browser_ManifestFinder_browserHasManifestLink.js

Source:browser_ManifestFinder_browserHasManifestLink.js Github

copy

Full Screen

1//Used by JSHint:2/*global Cu, BrowserTestUtils, ok, add_task, gBrowser */3"use strict";4const { ManifestFinder } = Cu.import("resource://gre/modules/ManifestFinder.jsm", {});5const defaultURL = new URL("http://example.org/browser/dom/manifest/test/resource.sjs");6defaultURL.searchParams.set("Content-Type", "text/html; charset=utf-8");7const tests = [{8 body: `9 <link rel="manifesto" href='${defaultURL}?body={"name":"fail"}'>10 <link rel="foo bar manifest bar test" href='${defaultURL}?body={"name":"value"}'>11 <link rel="manifest" href='${defaultURL}?body={"name":"fail"}'>12 `,13 run(result) {14 ok(result, "Document has a web manifest.");15 },16}, {17 body: `18 <link rel="amanifista" href='${defaultURL}?body={"name":"fail"}'>19 <link rel="foo bar manifesto bar test" href='${defaultURL}?body={"name":"pass-1"}'>20 <link rel="manifesto" href='${defaultURL}?body={"name":"fail"}'>`,21 run(result) {22 ok(!result, "Document does not have a web manifest.");23 },24}, {25 body: `26 <link rel="manifest" href="">27 <link rel="manifest" href='${defaultURL}?body={"name":"fail"}'>`,28 run(result) {29 ok(!result, "Manifest link is has empty href.");30 },31}, {32 body: `33 <link rel="manifest">34 <link rel="manifest" href='${defaultURL}?body={"name":"fail"}'>`,35 run(result) {36 ok(!result, "Manifest link is missing.");37 },38}];39function makeTestURL({ body }) {40 const url = new URL(defaultURL);41 url.searchParams.set("body", encodeURIComponent(body));42 return url.href;43}44/**45 * Test basic API error conditions46 */47add_task(function*() {48 const expected = "Invalid types should throw a TypeError.";49 for (let invalidValue of [undefined, null, 1, {}, "test"]) {50 try {51 yield ManifestFinder.contentManifestLink(invalidValue);52 ok(false, expected);53 } catch (e) {54 is(e.name, "TypeError", expected);55 }56 try {57 yield ManifestFinder.browserManifestLink(invalidValue);58 ok(false, expected);59 } catch (e) {60 is(e.name, "TypeError", expected);61 }62 }63});64add_task(function*() {65 const runningTests = tests66 .map(67 test => ({68 gBrowser,69 test,70 url: makeTestURL(test),71 })72 )73 .map(74 tabOptions => BrowserTestUtils.withNewTab(tabOptions, function*(browser) {75 const result = yield ManifestFinder.browserHasManifestLink(browser);76 tabOptions.test.run(result);77 })78 );79 yield Promise.all(runningTests);...

Full Screen

Full Screen

api.js

Source:api.js Github

copy

Full Screen

...16 for (const [method, url] of api) {17 app[method.toLowerCase()](url, async () => url);18 }19 for (const [method, url] of api) {20 const testUrl = makeTestUrl(url);21 const { res } = await simulate(app, method, testUrl);22 res.assert(200, url);23 }24 });25 }26});27/**28 * Replaces all param (:param1) in URL to random param test string.29 */30function makeTestUrl(url) {31 while (url.indexOf(':') !== -1) {32 url = url.replace(/:\w+/, randStr(1, 8));33 }34 return url;35}36function randStr(min, max) {37 return crypto.randomBytes(Math.floor(Math.random() * (max - min + 1) + min)).toString('base64')38 .replace(/=/g, '').replace(/\+/g, '').replace(/\//g, ''); // url-safe...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var wptUrl = wpt.makeTestUrl(url);3console.log(wptUrl);4var wpt = {5 makeTestUrl: function(url) {6 }7};8module.exports = wpt;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2console.log(url);3var wpt = require('wpt');4console.log(url);5var wpt = require('wpt');6console.log(url);7var wpt = require('wpt');8console.log(url);9var wpt = require('wpt');10console.log(url);11var wpt = require('wpt');12console.log(url);13var wpt = require('wpt');14console.log(url);15var wpt = require('wpt');

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const wpt = new WebPageTest('www.webpagetest.org');3const options = {4 videoParams: {5 }6};7wpt.makeTestUrl(url, options, function(err, data) {8 if (err) return console.error(err);9 console.log(data);10});11const wpt = require('webpagetest');12const wpt = new WebPageTest('www.webpagetest.org');13const options = {14 videoParams: {15 }16};17wpt.runTest(url, options, function(err, data) {18 if (err) return console.error(err);19 console.log(data);20});21const wpt = require('webpagetest');22const wpt = new WebPageTest('www.webpagetest.org');23wpt.getLocations(function(err, data) {24 if (err) return console.error(err);25 console.log(data);26});27const wpt = require('webpagetest');28const wpt = new WebPageTest('www.webpagetest.org');29wpt.getTesters(function(err, data) {30 if (err) return console.error(err);31 console.log(data);32});33const wpt = require('webpagetest');34const wpt = new WebPageTest('www.webpagetest.org');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2console.log(url);3module.exports = {4 makeTestUrl: function(url, browser, location, view) {5 }6};

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2var url = wpt.makeTestUrl('www.google.com', 'Google');3console.log(url);4exports.makeTestUrl = function(url, label) {5};6exports.makeTestUrl = function(url, label) {7 return wptUrl + '/runtest.php?url=' + url + '&label=' + label;8};9exports.getTestResults = function(url, label) {10 return wptUrl + '/result/' + label + '/';11};12var wpt = require('wpt.js');13var url = wpt.makeTestUrl('www.google.com', 'Google');14var resultsUrl = wpt.getTestResults('www.google.com', 'Google');15console.log(url);16console.log(resultsUrl);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.5d5b7c5b5e0f7c8e3b3b7c5b5e0f7c8e');3 if (err) console.error(err);4 else console.log(data);5});6 at errnoException (net.js:904:11)7 at Object.afterConnect [as oncomplete](net.js:895:19)

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