Skip to content

Commit

Permalink
Add test to confirm Request.prototype.clone works correctly for Reque…
Browse files Browse the repository at this point in the history
…st instance which have no body
  • Loading branch information
Jake Champion committed Jul 14, 2023
1 parent ce50327 commit 9ca6dd7
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions integration-tests/js-compute/fixtures/request-clone/bin/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-env serviceworker */
/* global ReadableStream */
import { env } from 'fastly:env';
import { pass, fail, assert, assertThrows } from "../../../assertions.js";

Expand Down Expand Up @@ -45,25 +46,37 @@ routes.set("/request/clone/called-unbound", () => {
return pass()
});
routes.set("/request/clone/valid", async () => {
const request = new Request('https://www.fastly.com', {
let request = new Request('https://www.fastly.com', {
headers: {
hello: 'world'
},
body: 'te',
method: 'post'
})
const newRequest = request.clone();
let newRequest = request.clone();
let error = assert(newRequest instanceof Request, true, 'newRequest instanceof Request')
if (error) { return error }
error = assert(newRequest.method, request.method, 'newRequest.method === request.method')
error = assert(newRequest.method, request.method, 'newRequest.method')
if (error) { return error }
error = assert(newRequest.url, request.url, 'newRequest.url')
if (error) { return error }
error = assert(newRequest.headers, request.headers, 'newRequest.headers')
if (error) { return error }
error = assert(request.bodyUsed, false, 'request.bodyUsed')
if (error) { return error }
error = assert(newRequest.url, request.url, 'newRequest.url === request.url')
error = assert(newRequest.bodyUsed, false, 'newRequest.bodyUsed')
if (error) { return error }
error = assert(newRequest.headers, request.headers, 'newRequest.headers === request.headers')
error = assert(newRequest.body instanceof ReadableStream, true, 'newRequest.body instanceof ReadableStream')
if (error) { return error }
error = assert(request.bodyUsed, false, 'request.bodyUsed === false')

request = new Request('https://www.fastly.com', {
method: 'get'
})
newRequest = request.clone()

error = assert(newRequest.bodyUsed, false, 'newRequest.bodyUsed')
if (error) { return error }
error = assert(newRequest.bodyUsed, false, 'newRequest.bodyUsed === false')
error = assert(newRequest.body, null, 'newRequest.body')
if (error) { return error }
return pass()
});
Expand Down

0 comments on commit 9ca6dd7

Please sign in to comment.