Skip to content

Commit

Permalink
test: adopt postman-collection
Browse files Browse the repository at this point in the history
  • Loading branch information
windchime-yk committed Oct 18, 2024
1 parent 388e577 commit 7c5a696
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 63 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dev": "wrangler dev src/index.ts",
"deploy": "wrangler deploy --minify src/index.ts",
"test": "vitest",
"test:api": "tsx src/index.newman.ts",
"test:api": "tsx src/index.newman.ts && pnpm format",
"check": "biome check --unsafe .",
"format": "pnpm check --write"
},
Expand All @@ -20,7 +20,9 @@
"@cloudflare/vitest-pool-workers": "^0.5.2",
"@cloudflare/workers-types": "^4.20240529.0",
"@types/newman": "^5.3.6",
"@types/postman-collection": "^3.5.10",
"newman": "^6.2.1",
"postman-collection": "^4.5.0",
"tsx": "^4.19.1",
"vitest": "^2.0.5",
"wrangler": "^3.78.7"
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

133 changes: 132 additions & 1 deletion src/index.newman.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,137 @@
import { writeFileSync } from "node:fs";
import * as newman from "newman";
import { Collection } from "postman-collection";

// TODO: 前段処理でPostman CollectionをTypeScriptで記述して吐き出せるようにしたい(Postman Collection SDKを使う?)
const collection = new Collection({
name: "verify-cfw-drizzle-crud",
item: [
{
name: "GET",
event: [
{
listen: "test",
script: {
exec: [
'pm.test("レスポンスボディのJSONが想定通りか", () => {\r',
" const jsonData = pm.response.json();\r",
" pm.expect(jsonData.status).to.eql(200);\r",
' pm.expect(jsonData.method).to.eql("GET");\r',
' pm.expect(jsonData.text).to.eql("OK!");\r',
' pm.expect(jsonData.apiKey).to.eql("Example_0000");\r',
"});",
],
type: "text/javascript",
},
},
],
request: {
method: "GET",
header: [],
url: {
protocol: "http",
host: ["localhost"],
port: "8787",
},
},
response: [],
},
{
name: "POST",
event: [
{
listen: "test",
script: {
exec: [
'pm.test("レスポンスボディのJSONが想定通りか", () => {\r',
" const jsonData = pm.response.json();\r",
" pm.expect(jsonData.status).to.eql(200);\r",
' pm.expect(jsonData.method).to.eql("POST");\r',
' pm.expect(jsonData.text).to.eql("OK!");\r',
' pm.expect(jsonData.apiKey).to.eql("Example_0000");\r',
"});",
],
type: "text/javascript",
},
},
],
request: {
method: "POST",
header: [],
url: {
protocol: "http",
host: ["localhost"],
port: "8787",
},
},
response: [],
},
{
name: "PATCH",
event: [
{
listen: "test",
script: {
exec: [
'pm.test("レスポンスボディのJSONが想定通りか", () => {\r',
" const jsonData = pm.response.json();\r",
" pm.expect(jsonData.status).to.eql(200);\r",
' pm.expect(jsonData.method).to.eql("PATCH");\r',
' pm.expect(jsonData.text).to.eql("OK!");\r',
' pm.expect(jsonData.apiKey).to.eql("Example_0000");\r',
"});",
],
type: "text/javascript",
},
},
],
request: {
method: "PATCH",
header: [],
url: {
protocol: "http",
host: ["localhost"],
port: "8787",
},
},
response: [],
},
{
name: "DELETE",
event: [
{
listen: "test",
script: {
exec: [
'pm.test("レスポンスボディのJSONが想定通りか", () => {\r',
" const jsonData = pm.response.json();\r",
" pm.expect(jsonData.status).to.eql(200);\r",
' pm.expect(jsonData.method).to.eql("DELETE");\r',
' pm.expect(jsonData.text).to.eql("OK!");\r',
' pm.expect(jsonData.apiKey).to.eql("Example_0000");\r',
"});",
],
type: "text/javascript",
},
},
],
request: {
method: "DELETE",
header: [],
url: {
protocol: "http",
host: ["localhost"],
port: "8787",
},
},
response: [],
},
],
});

writeFileSync(
"src/verify-cfw-drizzle-crud.postman_collection.json",
JSON.stringify(collection.toJSON()),
);

newman.run(
{
Expand Down
Loading

0 comments on commit 7c5a696

Please sign in to comment.