From fbdcdb5fd1ed69a0b8a3fb8444ff0e2ac9755e63 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:35:20 -0400 Subject: [PATCH 1/3] chore: update WPT (#3634) Co-authored-by: Uzlopak <5059100+Uzlopak@users.noreply.github.com> --- .../wpt/fetch/api/basic/keepalive.any.js | 36 +++++++++++++++++++ ...uest-constructor-init-body-override.any.js | 16 +++++++++ .../fetch/api/resources/keepalive-worker.js | 15 ++++++++ .../wpt/interfaces/digital-credentials.idl | 10 ++---- .../wpt/interfaces/mediaqueries-5.idl | 30 ++++++++++++++++ test/fixtures/wpt/interfaces/webauthn.idl | 2 +- test/fixtures/wpt/interfaces/webhid.idl | 10 +++--- test/fixtures/wpt/interfaces/webnn.idl | 2 +- test/fixtures/wpt/interfaces/webtransport.idl | 2 ++ test/fixtures/wpt/resources/testdriver.js | 7 ++-- 10 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 test/fixtures/wpt/fetch/api/resources/keepalive-worker.js create mode 100644 test/fixtures/wpt/interfaces/mediaqueries-5.idl diff --git a/test/fixtures/wpt/fetch/api/basic/keepalive.any.js b/test/fixtures/wpt/fetch/api/basic/keepalive.any.js index 55225e00aa0..d4e831b9631 100644 --- a/test/fixtures/wpt/fetch/api/basic/keepalive.any.js +++ b/test/fixtures/wpt/fetch/api/basic/keepalive.any.js @@ -39,3 +39,39 @@ function keepaliveSimpleRequestTest(method) { for (const method of ['GET', 'POST']) { keepaliveSimpleRequestTest(method); } + +// verifies fetch keepalive requests from a worker +function keepaliveSimpleWorkerTest() { + const desc = + `simple keepalive test for web workers`; + promise_test(async (test) => { + const TOKEN = token(); + const FRAME_ORIGIN = new URL(location.href).origin; + const TEST_URL = get_host_info().HTTP_ORIGIN + `/fetch/api/resources/stash-put.py?key=${TOKEN}&value=on` + + `&frame_origin=${FRAME_ORIGIN}`; + // start a worker which sends keepalive request and immediately terminates + const worker = new Worker(`/fetch/api/resources/keepalive-worker.js?param=${TEST_URL}`); + + const keepAliveWorkerPromise = new Promise((resolve, reject) => { + worker.onmessage = (event) => { + if (event.data === 'started') { + resolve(); + } else { + reject(new Error("Unexpected message received from worker")); + } + }; + worker.onerror = (error) => { + reject(error); + }; + }); + + // wait until the worker has been initialized (indicated by the "started" message) + await keepAliveWorkerPromise; + // verifies if the token sent in fetch request has been updated in the server + assertStashedTokenAsync(desc, TOKEN); + + }, `${desc};`); + +} + +keepaliveSimpleWorkerTest(); diff --git a/test/fixtures/wpt/fetch/api/request/request-constructor-init-body-override.any.js b/test/fixtures/wpt/fetch/api/request/request-constructor-init-body-override.any.js index 27bb991871a..c2bbf86f304 100644 --- a/test/fixtures/wpt/fetch/api/request/request-constructor-init-body-override.any.js +++ b/test/fixtures/wpt/fetch/api/request/request-constructor-init-body-override.any.js @@ -18,4 +18,20 @@ promise_test(async function () { "req2", "The body of the second request should be overridden to 'req2'." ); + }, "Check that the body of a new request can be overridden when created from an existing Request object"); + +promise_test(async function () { + const req1 = new Request("https://example.com/", { + body: "req1", + method: "POST", + }); + + const req2 = new Request("https://example.com/", req1); + const bodyText = await req2.text(); + assert_equals( + bodyText, + "req1", + "The body of the second request should be the same as the first." + ); +}, "Check that the body of a new request can be duplicated from an existing Request object"); diff --git a/test/fixtures/wpt/fetch/api/resources/keepalive-worker.js b/test/fixtures/wpt/fetch/api/resources/keepalive-worker.js new file mode 100644 index 00000000000..0808601d0d9 --- /dev/null +++ b/test/fixtures/wpt/fetch/api/resources/keepalive-worker.js @@ -0,0 +1,15 @@ +/** +* Script that sends keepalive +* fetch request and terminates immediately. +* The request URL is passed as a parameter to this worker +*/ +function sendFetchRequest() { + // Parse the query parameter from the worker's script URL + const urlString = self.location.search.replace("?param=", ""); + postMessage('started'); + fetch(`${urlString}`, { keepalive: true }); +} + +sendFetchRequest(); +// Terminate the worker +self.close(); diff --git a/test/fixtures/wpt/interfaces/digital-credentials.idl b/test/fixtures/wpt/interfaces/digital-credentials.idl index a12ce5a2ba2..2207b25dd57 100644 --- a/test/fixtures/wpt/interfaces/digital-credentials.idl +++ b/test/fixtures/wpt/interfaces/digital-credentials.idl @@ -3,21 +3,17 @@ // (https://github.com/w3c/webref) // Source: Digital Credentials (https://wicg.github.io/digital-credentials/) -partial interface Navigator { - [SecureContext, SameObject] readonly attribute CredentialsContainer identity; -}; - partial dictionary CredentialRequestOptions { DigitalCredentialRequestOptions digital; }; dictionary DigitalCredentialRequestOptions { - sequence providers; + sequence requests; }; -dictionary DigitalCredentialsProvider { +dictionary DigitalCredentialsRequest { required DOMString protocol; - required object request; + required object data; }; [Exposed=Window, SecureContext] diff --git a/test/fixtures/wpt/interfaces/mediaqueries-5.idl b/test/fixtures/wpt/interfaces/mediaqueries-5.idl new file mode 100644 index 00000000000..52154c96725 --- /dev/null +++ b/test/fixtures/wpt/interfaces/mediaqueries-5.idl @@ -0,0 +1,30 @@ +// GENERATED CONTENT - DO NOT EDIT +// Content was automatically extracted by Reffy into webref +// (https://github.com/w3c/webref) +// Source: Media Queries Level 5 (https://drafts.csswg.org/mediaqueries-5/) + +[Exposed=Window, SecureContext] +partial interface Navigator { + [SameObject] readonly attribute PreferenceManager preferences; +}; + +[Exposed=Window, SecureContext] +interface PreferenceManager { + readonly attribute PreferenceObject colorScheme; + readonly attribute PreferenceObject contrast; + readonly attribute PreferenceObject reducedMotion; + readonly attribute PreferenceObject reducedTransparency; + readonly attribute PreferenceObject reducedData; +}; + +[Exposed=Window, SecureContext] +interface PreferenceObject : EventTarget { + readonly attribute DOMString? override; + readonly attribute DOMString value; + readonly attribute FrozenArray validValues; + + undefined clearOverride(); + Promise requestOverride(DOMString? value); + + attribute EventHandler onchange; +}; diff --git a/test/fixtures/wpt/interfaces/webauthn.idl b/test/fixtures/wpt/interfaces/webauthn.idl index b4c0c2de603..2b855144650 100644 --- a/test/fixtures/wpt/interfaces/webauthn.idl +++ b/test/fixtures/wpt/interfaces/webauthn.idl @@ -302,7 +302,7 @@ enum ClientCapability { "signalUnknownCredential" }; -enum PublicKeyCredentialHints { +enum PublicKeyCredentialHint { "security-key", "client-device", "hybrid", diff --git a/test/fixtures/wpt/interfaces/webhid.idl b/test/fixtures/wpt/interfaces/webhid.idl index 03e72511d96..56e3161caed 100644 --- a/test/fixtures/wpt/interfaces/webhid.idl +++ b/test/fixtures/wpt/interfaces/webhid.idl @@ -7,12 +7,12 @@ [SameObject] readonly attribute HID hid; }; -[Exposed=ServiceWorker, SecureContext] +[Exposed=(DedicatedWorker,ServiceWorker), SecureContext] partial interface WorkerNavigator { [SameObject] readonly attribute HID hid; }; -[Exposed=(Window,ServiceWorker), SecureContext] +[Exposed=(DedicatedWorker,ServiceWorker,Window), SecureContext] interface HID : EventTarget { attribute EventHandler onconnect; attribute EventHandler ondisconnect; @@ -33,7 +33,7 @@ dictionary HIDDeviceFilter { unsigned short usage; }; -[Exposed=Window, SecureContext] +[Exposed=(DedicatedWorker,ServiceWorker,Window), SecureContext] interface HIDDevice : EventTarget { attribute EventHandler oninputreport; readonly attribute boolean opened; @@ -51,7 +51,7 @@ interface HIDDevice : EventTarget { Promise receiveFeatureReport([EnforceRange] octet reportId); }; -[Exposed=Window, SecureContext] +[Exposed=(DedicatedWorker,ServiceWorker,Window), SecureContext] interface HIDConnectionEvent : Event { constructor(DOMString type, HIDConnectionEventInit eventInitDict); [SameObject] readonly attribute HIDDevice device; @@ -61,7 +61,7 @@ dictionary HIDConnectionEventInit : EventInit { required HIDDevice device; }; -[Exposed=Window, SecureContext] +[Exposed=(DedicatedWorker,ServiceWorker,Window), SecureContext] interface HIDInputReportEvent : Event { constructor(DOMString type, HIDInputReportEventInit eventInitDict); [SameObject] readonly attribute HIDDevice device; diff --git a/test/fixtures/wpt/interfaces/webnn.idl b/test/fixtures/wpt/interfaces/webnn.idl index f8db7b0d542..9a71f73954c 100644 --- a/test/fixtures/wpt/interfaces/webnn.idl +++ b/test/fixtures/wpt/interfaces/webnn.idl @@ -90,7 +90,7 @@ enum MLOperandDataType { dictionary MLOperandDescriptor { required MLOperandDataType dataType; - sequence<[EnforceRange] unsigned long> dimensions = []; + sequence<[EnforceRange] unsigned long> shape = []; }; [SecureContext, Exposed=(Window, DedicatedWorker)] diff --git a/test/fixtures/wpt/interfaces/webtransport.idl b/test/fixtures/wpt/interfaces/webtransport.idl index 2136cad41e3..6e9d1036736 100644 --- a/test/fixtures/wpt/interfaces/webtransport.idl +++ b/test/fixtures/wpt/interfaces/webtransport.idl @@ -25,6 +25,7 @@ interface WebTransport { readonly attribute WebTransportCongestionControl congestionControl; [EnforceRange] attribute unsigned short? anticipatedConcurrentIncomingUnidirectionalStreams; [EnforceRange] attribute unsigned short? anticipatedConcurrentIncomingBidirectionalStreams; + readonly attribute DOMString protocol; readonly attribute Promise closed; readonly attribute Promise draining; @@ -64,6 +65,7 @@ dictionary WebTransportOptions { WebTransportCongestionControl congestionControl = "default"; [EnforceRange] unsigned short? anticipatedConcurrentIncomingUnidirectionalStreams = null; [EnforceRange] unsigned short? anticipatedConcurrentIncomingBidirectionalStreams = null; + sequence protocols = []; }; enum WebTransportCongestionControl { diff --git a/test/fixtures/wpt/resources/testdriver.js b/test/fixtures/wpt/resources/testdriver.js index b873b5c616a..d05be1d7df9 100644 --- a/test/fixtures/wpt/resources/testdriver.js +++ b/test/fixtures/wpt/resources/testdriver.js @@ -176,11 +176,10 @@ }, /** - * Triggers a user-initiated click + * Triggers a user-initiated mouse click. * - * If ``element`` isn't inside the - * viewport, it will be scrolled into view before the click - * occurs. + * If ``element`` isn't inside the viewport, it will be + * scrolled into view before the click occurs. * * If ``element`` is from a different browsing context, the * command will be run in that context. From e04abdd195d5dbaca1cc3c71c1aa32fd4b638f14 Mon Sep 17 00:00:00 2001 From: Livia Medeiros Date: Tue, 1 Oct 2024 19:04:48 +0900 Subject: [PATCH 2/3] test: increase bitness in `test/fixtures/*.pem` (#3659) --- test/fixtures/ca.pem | 46 ++++++++++++++++++++--------- test/fixtures/cert.pem | 47 +++++++++++++++++++---------- test/fixtures/key.pem | 67 ++++++++++++++++++++++++++++++++---------- 3 files changed, 115 insertions(+), 45 deletions(-) diff --git a/test/fixtures/ca.pem b/test/fixtures/ca.pem index c126543553d..7ceba673dd2 100644 --- a/test/fixtures/ca.pem +++ b/test/fixtures/ca.pem @@ -1,16 +1,34 @@ -----BEGIN CERTIFICATE----- -MIIChDCCAe2gAwIBAgIJAMsVOuISYJ/GMA0GCSqGSIb3DQEBCwUAMHoxCzAJBgNV -BAYTAlVTMQswCQYDVQQIDAJDQTELMAkGA1UEBwwCU0YxDzANBgNVBAoMBkpveWVu -dDEQMA4GA1UECwwHTm9kZS5qczEMMAoGA1UEAwwDY2ExMSAwHgYJKoZIhvcNAQkB -FhFyeUB0aW55Y2xvdWRzLm9yZzAgFw0xODExMTYxODQyMjBaGA8yMjkyMDgzMDE4 -NDIyMFowejELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMQswCQYDVQQHDAJTRjEP -MA0GA1UECgwGSm95ZW50MRAwDgYDVQQLDAdOb2RlLmpzMQwwCgYDVQQDDANjYTEx -IDAeBgkqhkiG9w0BCQEWEXJ5QHRpbnljbG91ZHMub3JnMIGfMA0GCSqGSIb3DQEB -AQUAA4GNADCBiQKBgQDrNdKjVKhbxKbrDRLdy45u9vsU3IH8C3qFcLF5wqf+g7OC -vMOOrFDM6mL5iYwuYaLRvAtsC0mtGPzBGyFflxGhiBYaOhi7nCKEsUkFuNYlCzX+ -FflT04JYT3qWPLL7rT32GXpABND/8DEnj5D5liYYNR05PjV1fUnGg1gPqXVxbwID -AQABoxAwDjAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4GBAHhsWFy6m6VO -AjK14n0XCSM66ltk9qMKpOryXneLhmmkOQbJd7oavueUWzMdszWLMKhrBoXjmvuW -QceutP9IUq1Kzw7a/B+lLPD90xfLMr7tNLAxZoJmq/NAUI63M3nJGpX0HkjnYwoU -ekzNkKt5TggwcqqzK+cCSG1wDvJ+wjiD +MIIF1zC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Hb/jUwXNI3keUoMKm0y8LSVCn +anJjttduMvKEY4LUBrQmIkJIijnXJqfnTzahssnhMli6TaBDhgKFXCtufS+OhPjK +6gklbY03T5oG5dpvEwIDAQABo1MwUTAdBgNVHQ4EFgQUMii3SZU8I+FEmIBfkoo/ +E3rMG+cwHwYDVR0jBBgwFoAUMii3SZU8I+FEmIBfkoo/E3rMG+cwDwYDVR0TAQH/ +BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAgEACipNr6ibOCtfvfRyCM2XMgeW7FF3 +KtNzZLqm+/0RwXiPZwxxYI2XVeTXLrZfrsBEK0oimeQhV/RCPe7t9ILGSNvPa8+Q +HqrPt90FxQGiCSrUhgIz+VhbKRd9OJaTiOR/dnqA1To9TPnxjwBX2iEGbAyX5eqy +bdeDuC0pB+2dSkJ9FtwaHjQfcBBlkk2xSHvvkWCVpd53xXBhVPRjzXPkTk1AOl9e +uDDtaUAKndofh4I17IAYHrRUgLsFf/xrHfIGHFqhkVOz+iTHdKDD8wLMZlr6DVlk +yNOdlIC1XZrvTsr4SyiMxvuNaArAePG26udlaoYznd8fU4hbp+4Nn1QCNpn3brVx +vee5+Yz8zEv3iUGl+B5rjAdW3mcpB3qijKGdBF8qROBt6qYkmuMZEJP1oeI9LItX +v6hpWRVA+9jP6Zjt56W/B+2ETKdIFg6eQBbGDkyAu7cv7OMsq/YstVN/HPxFg/p3 +rdxNVwqcnJ07cCVSnrbxdUHhL/Vcw8mBfDjez4BZUrFqen5O6r+WY1sM86Ex7IV5 +QTbRgaKiDW4SmqTu4++VOeHKp3pjm9UyFHB1jrPxJbm+P2lLn41n7LUU7Q35ce8D +xBoDu3SIeoaF/e54+o4Pn0WDjs0zTV4YDMI2Zkt/QK5fLPx0VQBrxDl4MkcN7DnC +1UV2bT78VPpeGn8= -----END CERTIFICATE----- diff --git a/test/fixtures/cert.pem b/test/fixtures/cert.pem index 664d00ca6d8..903d5f57ba2 100644 --- a/test/fixtures/cert.pem +++ b/test/fixtures/cert.p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itI+lzfOUf+e/mZrQVof +TMSynhFNnLssNqg5HKe4P45D0bWjz93+X0vYpNrKeFZSeHpTZYGESQ0A6baoGvw5 +LqgcT0aWxezzYF7IRBKvRwIDAQABo0IwQDAdBgNVHQ4EFgQUUj4+P8JxihhKlG1q +zZP9KTqQhNwwHwYDVR0jBBgwFoAUMii3SZU8I+FEmIBfkoo/E3rMG+cwDQYJKoZI +hvcNAQELBQADggIBAFwoYo6NKF9fyjI29341PQoivLT8QzD72nnoFtdemmDOPARE +AKJtOyrVc/H0w4CtolK+gjTazVvVwv5FLZsRtvqoWGuzSGdgANGskHonT8iOZLyQ +chwB0oC6iyyGmXkDnAAlsR7vp6duJRaHI9uDrO9SqRSbVF2TP5kdSzKoVK44t+bP +c7/Cp5T9PBssHpXuq2y3vxFHAjJDnwuw8mXd1CSYw6GtDYj/eVMNukOwa1wZkDH2 +o32V9c9oNceIFuI9O0F52H76U7Hnl7FGIO6BL67yeapkWTOl38j97+KHsXuMYe4f +kVJnT6uUPuwva1zSc/X8Db9ZjAPG82nI9puMYZEQugjgdIB8PnkRbgwFXUvAXJ3U +0CzymCnth0UviSsU0zluz87oOS8KH9jWI8Ul4d6wmiPRgwdt/sc/VvJ04RzM0v6s +WmsGxjc3ff5rV5Cn/EF/s8nPjoVSlimoxrlmEIKz8tI1lHyccpDK7TzYdup4Z7Oy +6Bt+7+PAyl974U4ptgSozjaKnOsw9OGIo9g6g4te9D5EDiHOC32Mja47i7UaM8en +nmGH7W0L1Fj26CELlsrs5Chm0JXCyKxPcJK7pyKLAFOhXFYp5YsFyI2fGDmrQI58 +WLChV8nOTHWo1XrzKhTNB4tLPSXa6AcRYLEHpU0kbZyTC2La9zwyHVCnPMbn -----END CERTIFICATE----- diff --git a/test/fixtures/key.pem b/test/fixtures/key.pem index fe750dee3f4..facb3118fee 100644 --- a/test/fixtures/key.pem +++ b/test/fixtures/key.pem @@ -1,15 +1,52 @@ ------BEGIN RSA PRIVATE KEY----- -MIICXQIBAAKBgQD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NBBIIGdUe7GGpoiw4jkroIpwX+7pm8qQWKGGb9Ufu +cA2fHIfUjFiLuvU3Uu3Bh47Jz4tRV8cfA3HLPczcNP29xXljXYAz4szYL/YhzwrT +V0+RFDeG1iHeydDpGU/Oen1mKoCbDm7M32bQQllpAoIBADnEK+p4gUzd3CQtYw5d +X8hc/yJDjaBsKuH6FV/vY1OgjdmF55+woYTlT7Gmvmjjghz75vsLRoISuE+5trKh +98SOr7Q09XLIH0BZjeGzx+kj8nlVlmmpgBx7le5hNbykcdWjmKShVEDoX7w/xmO5 +Jn+73558h4kb8MLD8xwCSKS1LHXtKHtJ6nE0MdM8SaSn75L2mkbJzrKXcsTXo5/7 +lRdLxDiDR1PfhppeVpf019bAO/5SJP5B61sFsCYsh5LP/xgApRGFN6pV6p5zMU9o +/hOhvvS11e2FfUt8Ef32qL07aPRQ8gU2d68K2CQ7/gBHQS+mSDSbWtD/PyHzKqY0 +xnECggEAf9IVxlK1IX2FsFbNIG1CCVDkj55w5+jHuVdYAEUYIDwQEUMYhQ3GpgsC +DgFWyddlz1ni8gGvZgwvIZTNA0vz3SEKuOAbcdKfqRspuKIksfHnYikr2UUOBH5a +2hCUirh6UC/5cN0FBC0KV9fJTqiKoUqCI4HEWD6uMPzv892rP7Q80CAkAdalm9Ui +k8ZSfwrqfvAx/iE84VrAKKRxhegyQ2+KYZGc0EMlWXz6/GjrVyUKFqDVjaidmlEj +HBXxEWVKcsTit22GsU4Pl8mZS8DRIZm+wwIp60uP98VtXXBiPPEkea1t9D4T5Gi7 +zhkPVDbGIYpzFskiOGNjvnvBhwVdVg== +-----END PRIVATE KEY----- From 2d524cf58a1dd21c1e6e7008d305e64e57018af3 Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Tue, 1 Oct 2024 19:16:54 +0200 Subject: [PATCH 3/3] mock: fix mocking of Uint8Array and ArrayBuffers as provided mock-reponses (#3662) --- lib/mock/mock-utils.js | 4 ++++ test/mock-interceptor.js | 49 ++++++++++++++++++++++++++++++++++++++++ test/mock-utils.js | 12 ++++++++++ 3 files changed, 65 insertions(+) diff --git a/lib/mock/mock-utils.js b/lib/mock/mock-utils.js index 56be2c8a06e..dddf9519d3c 100644 --- a/lib/mock/mock-utils.js +++ b/lib/mock/mock-utils.js @@ -118,6 +118,10 @@ function matchKey (mockDispatch, { path, method, body, headers }) { function getResponseData (data) { if (Buffer.isBuffer(data)) { return data + } else if (data instanceof Uint8Array) { + return data + } else if (data instanceof ArrayBuffer) { + return data } else if (typeof data === 'object') { return JSON.stringify(data) } else { diff --git a/test/mock-interceptor.js b/test/mock-interceptor.js index 0d16290f579..8364fb40415 100644 --- a/test/mock-interceptor.js +++ b/test/mock-interceptor.js @@ -6,6 +6,7 @@ const { MockInterceptor, MockScope } = require('../lib/mock/mock-interceptor') const MockAgent = require('../lib/mock/mock-agent') const { kDispatchKey } = require('../lib/mock/mock-symbols') const { InvalidArgumentError } = require('../lib/core/errors') +const { fetch } = require('../lib/web/fetch/index') describe('MockInterceptor - path', () => { test('should remove hash fragment from paths', t => { @@ -257,3 +258,51 @@ describe('MockInterceptor - replyContentLength', () => { t.ok(result instanceof MockInterceptor) }) }) + +describe('MockInterceptor - different payloads', () => { + [ + // Buffer + ['arrayBuffer', 'ArrayBuffer', 'ArrayBuffer', new TextEncoder().encode('{"test":true}').buffer, new TextEncoder().encode('{"test":true}').buffer], + ['json', 'ArrayBuffer', 'Object', new TextEncoder().encode('{"test":true}').buffer, { test: true }], + ['bytes', 'ArrayBuffer', 'Uint8Array', new TextEncoder().encode('{"test":true}').buffer, new TextEncoder().encode('{"test":true}')], + ['text', 'ArrayBuffer', 'string', new TextEncoder().encode('{"test":true}').buffer, '{"test":true}'], + + // Buffer + ['arrayBuffer', 'Buffer', 'ArrayBuffer', Buffer.from('{"test":true}'), new TextEncoder().encode('{"test":true}').buffer], + ['json', 'Buffer', 'Object', Buffer.from('{"test":true}'), { test: true }], + ['bytes', 'Buffer', 'Uint8Array', Buffer.from('{"test":true}'), new TextEncoder().encode('{"test":true}')], + ['text', 'Buffer', 'string', Buffer.from('{"test":true}'), '{"test":true}'], + + // Uint8Array + ['arrayBuffer', 'Uint8Array', 'ArrayBuffer', new TextEncoder().encode('{"test":true}'), new TextEncoder().encode('{"test":true}').buffer], + ['json', 'Uint8Array', 'Object', new TextEncoder().encode('{"test":true}'), { test: true }], + ['bytes', 'Uint8Array', 'Uint8Array', new TextEncoder().encode('{"test":true}'), new TextEncoder().encode('{"test":true}')], + ['text', 'Uint8Array', 'string', new TextEncoder().encode('{"test":true}'), '{"test":true}'], + + // string + ['arrayBuffer', 'string', 'ArrayBuffer', '{"test":true}', new TextEncoder().encode('{"test":true}').buffer], + ['json', 'string', 'Object', '{"test":true}', { test: true }], + ['bytes', 'string', 'Uint8Array', '{"test":true}', new TextEncoder().encode('{"test":true}')], + ['text', 'string', 'string', '{"test":true}', '{"test":true}'], + + // object + ['arrayBuffer', 'Object', 'ArrayBuffer', { test: true }, new TextEncoder().encode('{"test":true}').buffer], + ['json', 'Object', 'Object', { test: true }, { test: true }], + ['bytes', 'Object', 'Uint8Array', { test: true }, new TextEncoder().encode('{"test":true}')], + ['text', 'Object', 'string', { test: true }, '{"test":true}'] + ].forEach(([method, inputType, outputType, input, output]) => { + test(`${inputType} will be returned as ${outputType} via ${method}()`, async (t) => { + t = tspl(t, { plan: 1 }) + + const mockAgent = new MockAgent() + mockAgent.disableNetConnect() + mockAgent + .get('https://localhost') + .intercept({ path: '/' }).reply(200, input) + + const response = await fetch('https://localhost', { dispatcher: mockAgent }) + + t.deepStrictEqual(await response[method](), output) + }) + }) +}) diff --git a/test/mock-utils.js b/test/mock-utils.js index f27a6763ae9..b80db2a401c 100644 --- a/test/mock-utils.js +++ b/test/mock-utils.js @@ -162,6 +162,18 @@ describe('getResponseData', () => { const responseData = getResponseData(Buffer.from('test')) t.ok(Buffer.isBuffer(responseData)) }) + + test('it should return Uint8Array untouched', (t) => { + t = tspl(t, { plan: 1 }) + const responseData = getResponseData(new TextEncoder().encode('{"test":true}')) + t.ok(responseData instanceof Uint8Array) + }) + + test('it should return ArrayBuffers untouched', (t) => { + t = tspl(t, { plan: 1 }) + const responseData = getResponseData(new TextEncoder().encode('{"test":true}').buffer) + t.ok(responseData instanceof ArrayBuffer) + }) }) test('getStatusText', (t) => {