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
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ services:
image: redis
ports:
- '6379:6379'
mockhttp:
image: jaredwray/mockhttp
platform: linux/amd64
ports:
- '3000:3000'
2 changes: 1 addition & 1 deletion packages/memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"dependencies": {
"@cacheable/utils": "workspace:^",
"@keyv/bigmap": "^1.3.1",
"hookified": "^1.15.0",
"hookified": "^1.15.1",
"keyv": "^5.6.0"
},
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions packages/net/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
"prepublish": "pnpm build",
"lint": "biome check --write --error-on-warnings",
"test": "pnpm lint && vitest run --coverage",
"test:ci": "biome check --error-on-warnings && vitest run --coverage",
"test": "pnpm lint && TEST_URL=http://localhost:3000 vitest run --coverage",
"test:ci": "biome check --error-on-warnings && TEST_URL=http://localhost:3000 vitest run --coverage",
"clean": "rimraf ./dist ./coverage ./node_modules"
},
"devDependencies": {
Expand Down
322 changes: 181 additions & 141 deletions packages/net/test/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,100 +320,124 @@ describe("Fetch", () => {
testTimeout,
);

test("should handle FormData in post helper", async () => {
const cache = new Cacheable();
const url = `${testUrl}/post`;
const formData = new FormData();
formData.append("test", "data");

// Since the server might not handle FormData properly, we'll just verify it doesn't crash
// The actual FormData handling is covered in the branch coverage
try {
const result = await post(url, formData, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept FormData, that's okay - we're testing the client code
expect(error).toBeDefined();
}
});
test(
"should handle FormData in post helper",
async () => {
const cache = new Cacheable();
const url = `${testUrl}/post`;
const formData = new FormData();
formData.append("test", "data");

test("should handle URLSearchParams in post helper", async () => {
const cache = new Cacheable();
const url = `${testUrl}/post`;
const params = new URLSearchParams();
params.append("key", "value");
// Since the server might not handle FormData properly, we'll just verify it doesn't crash
// The actual FormData handling is covered in the branch coverage
try {
const result = await post(url, formData, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept FormData, that's okay - we're testing the client code
expect(error).toBeDefined();
}
},
testTimeout,
);

// Since the server might not handle URLSearchParams properly, we'll just verify it doesn't crash
try {
const result = await post(url, params, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept URLSearchParams, that's okay - we're testing the client code
expect(error).toBeDefined();
}
});
test(
"should handle URLSearchParams in post helper",
async () => {
const cache = new Cacheable();
const url = `${testUrl}/post`;
const params = new URLSearchParams();
params.append("key", "value");

test("should handle Blob in post helper", async () => {
const cache = new Cacheable();
const url = `${testUrl}/post`;
const blob = new Blob(["test data"], { type: "text/plain" });
// Since the server might not handle URLSearchParams properly, we'll just verify it doesn't crash
try {
const result = await post(url, params, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept URLSearchParams, that's okay - we're testing the client code
expect(error).toBeDefined();
}
},
testTimeout,
);

// Since the server might not handle Blob properly, we'll just verify it doesn't crash
try {
const result = await post(url, blob, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept Blob, that's okay - we're testing the client code
expect(error).toBeDefined();
}
});
test(
"should handle Blob in post helper",
async () => {
const cache = new Cacheable();
const url = `${testUrl}/post`;
const blob = new Blob(["test data"], { type: "text/plain" });

test("should handle FormData in patch helper", async () => {
const cache = new Cacheable();
const url = `${testUrl}/patch`;
const formData = new FormData();
formData.append("test", "data");
// Since the server might not handle Blob properly, we'll just verify it doesn't crash
try {
const result = await post(url, blob, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept Blob, that's okay - we're testing the client code
expect(error).toBeDefined();
}
},
testTimeout,
);

// Since the server might not handle FormData properly, we'll just verify it doesn't crash
try {
const result = await patch(url, formData, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept FormData, that's okay - we're testing the client code
expect(error).toBeDefined();
}
});
test(
"should handle FormData in patch helper",
async () => {
const cache = new Cacheable();
const url = `${testUrl}/patch`;
const formData = new FormData();
formData.append("test", "data");

test("should handle URLSearchParams in patch helper", async () => {
const cache = new Cacheable();
const url = `${testUrl}/patch`;
const params = new URLSearchParams();
params.append("key", "value");
// Since the server might not handle FormData properly, we'll just verify it doesn't crash
try {
const result = await patch(url, formData, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept FormData, that's okay - we're testing the client code
expect(error).toBeDefined();
}
},
testTimeout,
);

// Since the server might not handle URLSearchParams properly, we'll just verify it doesn't crash
try {
const result = await patch(url, params, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept URLSearchParams, that's okay - we're testing the client code
expect(error).toBeDefined();
}
});
test(
"should handle URLSearchParams in patch helper",
async () => {
const cache = new Cacheable();
const url = `${testUrl}/patch`;
const params = new URLSearchParams();
params.append("key", "value");

test("should handle Blob in patch helper", async () => {
const cache = new Cacheable();
const url = `${testUrl}/patch`;
const blob = new Blob(["test data"], { type: "text/plain" });
// Since the server might not handle URLSearchParams properly, we'll just verify it doesn't crash
try {
const result = await patch(url, params, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept URLSearchParams, that's okay - we're testing the client code
expect(error).toBeDefined();
}
},
testTimeout,
);

// Since the server might not handle Blob properly, we'll just verify it doesn't crash
try {
const result = await patch(url, blob, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept Blob, that's okay - we're testing the client code
expect(error).toBeDefined();
}
});
test(
"should handle Blob in patch helper",
async () => {
const cache = new Cacheable();
const url = `${testUrl}/patch`;
const blob = new Blob(["test data"], { type: "text/plain" });

// Since the server might not handle Blob properly, we'll just verify it doesn't crash
try {
const result = await patch(url, blob, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept Blob, that's okay - we're testing the client code
expect(error).toBeDefined();
}
},
testTimeout,
);

test(
"should fetch data using delete helper",
Expand Down Expand Up @@ -515,69 +539,85 @@ describe("Fetch", () => {
testTimeout,
);

test("should handle string data in delete helper", async () => {
const cache = new Cacheable();
const url = `${testUrl}/delete`;
const data = JSON.stringify({ id: "123" });
const options = {
cache,
headers: {
"Content-Type": "application/json",
},
};
const result = await del(url, data, options);
expect(result).toBeDefined();
expect(result.data).toBeDefined();
expect(result.response).toBeDefined();
expect(result.response.status).toBe(200);
});
test(
"should handle string data in delete helper",
async () => {
const cache = new Cacheable();
const url = `${testUrl}/delete`;
const data = JSON.stringify({ id: "123" });
const options = {
cache,
headers: {
"Content-Type": "application/json",
},
};
const result = await del(url, data, options);
expect(result).toBeDefined();
expect(result.data).toBeDefined();
expect(result.response).toBeDefined();
expect(result.response.status).toBe(200);
},
testTimeout,
);

test("should handle FormData in delete helper", async () => {
const cache = new Cacheable();
const url = `${testUrl}/delete`;
const formData = new FormData();
formData.append("id", "123");
test(
"should handle FormData in delete helper",
async () => {
const cache = new Cacheable();
const url = `${testUrl}/delete`;
const formData = new FormData();
formData.append("id", "123");

// Since the server might not handle FormData properly, we'll just verify it doesn't crash
try {
const result = await del(url, formData, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept FormData, that's okay - we're testing the client code
expect(error).toBeDefined();
}
});
// Since the server might not handle FormData properly, we'll just verify it doesn't crash
try {
const result = await del(url, formData, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept FormData, that's okay - we're testing the client code
expect(error).toBeDefined();
}
},
testTimeout,
);

test("should handle URLSearchParams in delete helper", async () => {
const cache = new Cacheable();
const url = `${testUrl}/delete`;
const params = new URLSearchParams();
params.append("id", "123");
test(
"should handle URLSearchParams in delete helper",
async () => {
const cache = new Cacheable();
const url = `${testUrl}/delete`;
const params = new URLSearchParams();
params.append("id", "123");

// Since the server might not handle URLSearchParams properly, we'll just verify it doesn't crash
try {
const result = await del(url, params, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept URLSearchParams, that's okay - we're testing the client code
expect(error).toBeDefined();
}
});
// Since the server might not handle URLSearchParams properly, we'll just verify it doesn't crash
try {
const result = await del(url, params, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept URLSearchParams, that's okay - we're testing the client code
expect(error).toBeDefined();
}
},
testTimeout,
);

test("should handle Blob in delete helper", async () => {
const cache = new Cacheable();
const url = `${testUrl}/delete`;
const blob = new Blob(["test data"], { type: "text/plain" });
test(
"should handle Blob in delete helper",
async () => {
const cache = new Cacheable();
const url = `${testUrl}/delete`;
const blob = new Blob(["test data"], { type: "text/plain" });

// Since the server might not handle Blob properly, we'll just verify it doesn't crash
try {
const result = await del(url, blob, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept Blob, that's okay - we're testing the client code
expect(error).toBeDefined();
}
});
// Since the server might not handle Blob properly, we'll just verify it doesn't crash
try {
const result = await del(url, blob, { cache });
expect(result).toBeDefined();
} catch (error) {
// If server doesn't accept Blob, that's okay - we're testing the client code
expect(error).toBeDefined();
}
},
testTimeout,
);

describe("HTTP Cache Headers", () => {
test(
Expand Down
Loading