From fb2fd66f906bde9dda7e49bb1ab214e5e980e7c5 Mon Sep 17 00:00:00 2001 From: Petra Jaros Date: Fri, 30 Aug 2024 15:04:25 -0400 Subject: [PATCH] chore: Warn if mocks aren't running (#1534) It's not obvious that the mocks need to be running for tests to run. Now the output will warn you and tell you how to run them. --- .../test/helpers/receipts-server.js | 7 +++-- packages/upload-client/test/helpers/utils.js | 26 +++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/upload-client/test/helpers/receipts-server.js b/packages/upload-client/test/helpers/receipts-server.js index eae359f74..424f8b486 100644 --- a/packages/upload-client/test/helpers/receipts-server.js +++ b/packages/upload-client/test/helpers/receipts-server.js @@ -22,8 +22,11 @@ const server = createServer(async (req, res) => { res.setHeader('Access-Control-Allow-Methods', '*') res.setHeader('Access-Control-Allow-Headers', '*') - const taskCid = req.url?.split('/')[1] ?? '' - if (taskCid === 'unavailable') { + const taskCid = req.url?.split('/')[1] + if (!taskCid) { + res.writeHead(204) + res.end() + } else if (taskCid === 'unavailable') { res.writeHead(404) res.end() } else if (taskCid === 'failed') { diff --git a/packages/upload-client/test/helpers/utils.js b/packages/upload-client/test/helpers/utils.js index e6ac53c87..5ab28080b 100644 --- a/packages/upload-client/test/helpers/utils.js +++ b/packages/upload-client/test/helpers/utils.js @@ -12,6 +12,22 @@ import { randomCAR } from './random.js' export const validateAuthorization = () => ({ ok: {} }) export const receiptsEndpoint = 'http://localhost:9201' +export const bucket200Endpoint = 'http://localhost:9200' +export const bucket400Endpoint = 'http://localhost:9400' +export const bucket500Endpoint = 'http://localhost:9500' + +Object.entries({ + receiptsEndpoint, + bucket200Endpoint, + bucket400Endpoint, + bucket500Endpoint, +}).forEach(([name, url]) => { + fetch(url).catch((error) => { + console.warn( + `${name} is unreachable at ${url}. If tests are failing, try running \`pnpm --filter=@web3-storage/upload-client mock\`.` + ) + }) +}) export const setupBlobAddSuccessResponse = async function ( // @ts-ignore @@ -20,7 +36,7 @@ export const setupBlobAddSuccessResponse = async function ( invocation ) { return setupBlobAddResponse( - 'http://localhost:9200', + bucket200Endpoint, options, invocation, false, @@ -35,7 +51,7 @@ export const setupBlobAdd4xxResponse = async function ( invocation ) { return setupBlobAddResponse( - 'http://localhost:9400', + bucket400Endpoint, options, invocation, false, @@ -50,7 +66,7 @@ export const setupBlobAdd5xxResponse = async function ( invocation ) { return setupBlobAddResponse( - 'http://localhost:9500', + bucket500Endpoint, options, invocation, false, @@ -65,7 +81,7 @@ export const setupBlobAddWithAcceptReceiptSuccessResponse = async function ( invocation ) { return setupBlobAddResponse( - 'http://localhost:9200', + bucket200Endpoint, options, invocation, false, @@ -80,7 +96,7 @@ export const setupBlobAddWithHttpPutReceiptSuccessResponse = async function ( invocation ) { return setupBlobAddResponse( - 'http://localhost:9200', + bucket200Endpoint, options, invocation, true,