Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 0 additions & 197 deletions integration-tests/js-compute/fixtures/app/src/assertions-throwing.js

This file was deleted.

40 changes: 26 additions & 14 deletions integration-tests/js-compute/fixtures/app/src/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function pass(message = "") {
}

export function fail(message = "") {
return new Response(message, { status: 500 });
throw new Response(message, { status: 500 });
}

function prettyPrintSymbol(a) {
Expand All @@ -48,17 +48,27 @@ function prettyPrintSymbol(a) {
}
export function assert(actual, expected, code) {
if (!deepEqual(actual, expected)) {
return fail(
fail(
`Expected \`${code}\` to equal \`${JSON.stringify(prettyPrintSymbol(expected))}\` - Found \`${JSON.stringify(prettyPrintSymbol(actual))}\``,
);
}
}

export { assert as strictEqual }

export function ok(truthy, code) {
if (!truthy) {
fail(
`Expected ${code ? ' ' + code : ''}to be truthy - Found \`${JSON.stringify(prettyPrintSymbol(truthy))}\``,
);
}
}

export async function assertResolves(func) {
try {
await func();
} catch (error) {
return fail(
fail(
`Expected \`${func.toString()}\` to resolve - Found it rejected: ${error.name}: ${error.message}`,
);
}
Expand All @@ -67,63 +77,65 @@ export async function assertResolves(func) {
export async function assertRejects(func, errorClass, errorMessage) {
try {
await func();
return fail(
`Expected \`${func.toString()}\` to reject - Found it did not reject`,
);
} catch (error) {
if (errorClass) {
if (error instanceof errorClass === false) {
return fail(
fail(
`Expected \`${func.toString()}\` to reject instance of \`${errorClass.name}\` - Found instance of \`${error.name}\``,
);
}
}

if (errorMessage) {
if (error.message !== errorMessage) {
return fail(
fail(
`Expected \`${func.toString()}\` to reject error message of \`${errorMessage}\` - Found \`${error.message}\``,
);
}
}

return;
}
fail(`Expected \`${func.toString()}\` to reject - Found it did not reject`);
}

export function assertThrows(func, errorClass, errorMessage) {
try {
func();
return fail(
`Expected \`${func.toString()}\` to throw - Found it did not throw`,
);
} catch (error) {
if (errorClass) {
if (error instanceof errorClass === false) {
return fail(
fail(
`Expected \`${func.toString()}\` to throw instance of \`${errorClass.name}\` - Found instance of \`${error.name}\`: ${error.message}\n${error.stack}`,
);
}
}

if (errorMessage) {
if (error.message !== errorMessage) {
return fail(
fail(
`Expected \`${func.toString()}\` to throw error message of \`${errorMessage}\` - Found \`${error.message}\``,
);
}
}

return;
}
fail(`Expected \`${func.toString()}\` to throw - Found it did not throw`);
}

export function assertDoesNotThrow(func) {
try {
func();
} catch (error) {
return fail(
fail(
`Expected \`${func.toString()}\` to not throw - Found it did throw: ${error.name}: ${error.message}`,
);
}
}

export { deepEqual as deepStrictEqual }

export function deepEqual(a, b) {
var aKeys;
var bKeys;
Expand Down
22 changes: 11 additions & 11 deletions integration-tests/js-compute/fixtures/app/src/async-select.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { routes } from "./routes";
import { routes } from './routes';

routes.set("/async-select/hello", () => {
routes.set('/async-select/hello', () => {
let requestsData = [
{
url: "https://compute-sdk-test-backend.edgecompute.app/async_select_1",
backend: "TheOrigin",
header: "fooname",
url: 'https://compute-sdk-test-backend.edgecompute.app/async_select_1',
backend: 'TheOrigin',
header: 'fooname',
},
{
url: "https://compute-sdk-test-backend.edgecompute.app/async_select_2",
backend: "TheOrigin2",
header: "barname",
url: 'https://compute-sdk-test-backend.edgecompute.app/async_select_2',
backend: 'TheOrigin2',
header: 'barname',
},
];

Expand All @@ -36,17 +36,17 @@ async function processUpstreamRequests(requests, requestsData) {
let headerValue = response.headers.get(header);
if (headerValue == null) {
throw new Error(
"No header value on the response from the request with url " +
'No header value on the response from the request with url ' +
response.url +
" and with the header name: " +
' and with the header name: ' +
header,
);
}
responseHeaders.set(header, headerValue);
}

// Send our response downstream
return new Response("pong", {
return new Response('pong', {
headers: responseHeaders,
});
}
Expand Down
Loading