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
44 changes: 22 additions & 22 deletions packages/wrangler/src/__tests__/cloudchamber/images.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ describe("cloudchamber image list", () => {
`);
});

it("should list repos with json flag set", async () => {
it("should list repos as valid json with json flag set", async () => {
setIsTTY(false);
setWranglerConfig({});
const tags = {
Expand All @@ -331,34 +331,34 @@ describe("cloudchamber image list", () => {
);
await runWrangler("cloudchamber images list --json");
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.out).toMatchInlineSnapshot(`
"[
expect(JSON.parse(std.out)).toMatchInlineSnapshot(`
[
{
"name": "one",
"tags": [
"hundred",
"ten"
]
"ten",
],
},
{
"name": "two",
"tags": [
"thousand",
"twenty"
]
"twenty",
],
},
{
"name": "three",
"tags": [
"million",
"thirty"
]
}
]"
"thirty",
],
},
]
`);
});

it("should filter out repos with no non-sha tags in json output", async () => {
it("should filter out repos with no non-sha tags in valid json output", async () => {
setIsTTY(false);
setWranglerConfig({});
const tags = {
Expand All @@ -385,30 +385,30 @@ describe("cloudchamber image list", () => {
);
await runWrangler("cloudchamber images list --json");
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.out).toMatchInlineSnapshot(`
"[
expect(JSON.parse(std.out)).toMatchInlineSnapshot(`
[
{
"name": "one",
"tags": [
"hundred",
"ten"
]
"ten",
],
},
{
"name": "two",
"tags": [
"thousand",
"twenty"
]
"twenty",
],
},
{
"name": "three",
"tags": [
"million",
"thirty"
]
}
]"
"thirty",
],
},
]
`);
});
});
Expand Down
22 changes: 11 additions & 11 deletions packages/wrangler/src/__tests__/containers/images.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe("containers images list", () => {
`);
});

it("should list repos with json flag set", async () => {
it("should list repos as valid json with json flag set", async () => {
setWranglerConfig({});
const tags = {
one: ["hundred", "ten", "sha256:239a0dfhasdfui235"],
Expand All @@ -155,30 +155,30 @@ describe("containers images list", () => {
);
await runWrangler("containers images list --json");
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.out).toMatchInlineSnapshot(`
"[
expect(JSON.parse(std.out)).toMatchInlineSnapshot(`
[
{
"name": "one",
"tags": [
"hundred",
"ten"
]
"ten",
],
},
{
"name": "two",
"tags": [
"thousand",
"twenty"
]
"twenty",
],
},
{
"name": "three",
"tags": [
"million",
"thirty"
]
}
]"
"thirty",
],
},
]
`);
});
});
Expand Down
14 changes: 7 additions & 7 deletions packages/wrangler/src/__tests__/containers/registries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,18 +405,18 @@ describe("containers registries list", () => {
`);
});

it("should output JSON when --json flag is used", async () => {
it("should output valid JSON when --json flag is used", async () => {
const mockRegistries = [
{ domain: "123456789012.dkr.ecr.us-west-2.amazonaws.com" },
];
mockListRegistries(mockRegistries);
await runWrangler("containers registries list --json");
expect(std.out).toMatchInlineSnapshot(`
"[
{
"domain": "123456789012.dkr.ecr.us-west-2.amazonaws.com"
}
]"
expect(JSON.parse(std.out)).toMatchInlineSnapshot(`
[
{
"domain": "123456789012.dkr.ecr.us-west-2.amazonaws.com",
},
]
`);
});
});
Expand Down
9 changes: 7 additions & 2 deletions packages/wrangler/src/__tests__/d1/execute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ describe("execute", () => {
expect(std.out).toContain("1 command executed successfully");
});

it("should not show banner if --json=true", async ({ expect }) => {
it("should output valid JSON with --json flag", async ({ expect }) => {
setIsTTY(false);
writeWranglerConfig({
d1_databases: [
Expand All @@ -222,7 +222,12 @@ describe("execute", () => {
});

await runWrangler("d1 execute db --command 'select 1;' --json");
expect(std.out).not.toContain("⛅️ wrangler x.x.x");
expect(JSON.parse(std.out)).toMatchObject([
{
results: [{ "1": 1 }],
success: true,
},
]);
});

describe("duration formatting", () => {
Expand Down
42 changes: 22 additions & 20 deletions packages/wrangler/src/__tests__/d1/info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe("info", () => {
],
});
});
it("should display version when alpha", async ({ expect }) => {
it("should display version as valid json when alpha", async ({ expect }) => {
msw.use(
http.get("*/accounts/:accountId/d1/database/*", async () => {
return HttpResponse.json(
Expand All @@ -55,20 +55,22 @@ describe("info", () => {
})
);
await runWrangler("d1 info northwind --json");
expect(std.out).toMatchInlineSnapshot(`
"{
"uuid": "d5b1d127-xxxx-xxxx-xxxx-cbc69f0a9e06",
"name": "northwind",
expect(JSON.parse(std.out)).toMatchInlineSnapshot(`
{
"created_at": "2023-05-23T08:33:54.590Z",
"version": "alpha",
"database_size": 33067008,
"name": "northwind",
"num_tables": 13,
"running_in_region": "WEUR",
"database_size": 33067008
}"
"uuid": "d5b1d127-xxxx-xxxx-xxxx-cbc69f0a9e06",
"version": "alpha",
}
`);
});

it("should not display version when not alpha", async ({ expect }) => {
it("should not display version as valid json when not alpha", async ({
expect,
}) => {
msw.use(
http.get("*/accounts/:accountId/d1/database/*", async () => {
return HttpResponse.json(
Expand Down Expand Up @@ -107,22 +109,22 @@ describe("info", () => {
})
);
await runWrangler("d1 info northwind --json");
expect(std.out).toMatchInlineSnapshot(`
"{
"uuid": "d5b1d127-xxxx-xxxx-xxxx-cbc69f0a9e06",
"name": "northwind",
expect(JSON.parse(std.out)).toMatchInlineSnapshot(`
{
"created_at": "2023-05-23T08:33:54.590Z",
"database_size": 33067008,
"name": "northwind",
"num_tables": 13,
"running_in_region": "WEUR",
"read_queries_24h": 0,
"read_replication": {
"mode": "disabled"
"mode": "disabled",
},
"database_size": 33067008,
"read_queries_24h": 0,
"write_queries_24h": 0,
"rows_read_24h": 0,
"rows_written_24h": 0
}"
"rows_written_24h": 0,
"running_in_region": "WEUR",
"uuid": "d5b1d127-xxxx-xxxx-xxxx-cbc69f0a9e06",
"write_queries_24h": 0,
}
`);
});

Expand Down
22 changes: 11 additions & 11 deletions packages/wrangler/src/__tests__/d1/insights.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe("insights", () => {
);
});

it("should display the expected output", async ({ expect }) => {
it("should display valid json output", async ({ expect }) => {
setIsTTY(false);
mockGetMemberships([
{ id: "IG-88", account: { id: "1701", name: "enterprise" } },
Expand Down Expand Up @@ -201,20 +201,20 @@ describe("insights", () => {
})
);
await runWrangler("d1 insights my-database --json");
expect(std.out).toMatchInlineSnapshot(`
"[
expect(JSON.parse(std.out)).toMatchInlineSnapshot(`
[
{
"query": "sample query",
"avgDurationMs": 0,
"avgRowsRead": 0,
"totalRowsRead": 10,
"avgRowsWritten": 0,
"totalRowsWritten": 0,
"avgDurationMs": 0,
"totalDurationMs": 0,
"numberOfTimesRun": 0,
"queryEfficiency": 0
}
]"
"query": "sample query",
"queryEfficiency": 0,
"totalDurationMs": 0,
"totalRowsRead": 10,
"totalRowsWritten": 0,
},
]
`);
});
});
18 changes: 9 additions & 9 deletions packages/wrangler/src/__tests__/d1/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ describe("list", () => {
})
);
});
it("should print as json if `--json` flag is specified, without wrangler banner", async ({
it("should print valid json if `--json` flag is specified, without wrangler banner", async ({
expect,
}) => {
await runWrangler("d1 list --json");
expect(std.out).toMatchInlineSnapshot(`
"[
expect(JSON.parse(std.out)).toMatchInlineSnapshot(`
[
{
"uuid": "1",
"binding": "A",
"name": "a",
"binding": "A"
"uuid": "1",
},
{
"uuid": "2",
"binding": "B",
"name": "b",
"binding": "B"
}
]"
"uuid": "2",
},
]
`);
});

Expand Down
28 changes: 14 additions & 14 deletions packages/wrangler/src/__tests__/d1/timeTravel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ describe("time-travel", () => {
vi.useRealTimers();
});
describe("restore", () => {
it("should print as json, without wrangler banner", async ({
it("should print valid json, without wrangler banner", async ({
expect,
}) => {
await runWrangler(
`d1 time-travel restore db --timestamp=2011-09-05T14:48:00.000Z --json`
);
expect(std.out).toMatchInlineSnapshot(`
"{
"bookmark": "a"
}"
expect(JSON.parse(std.out)).toMatchInlineSnapshot(`
{
"bookmark": "a",
}
`);
});

Expand Down Expand Up @@ -213,22 +213,22 @@ describe("time-travel", () => {
});
});
describe("info", () => {
it("should print as json, without wrangler banner", async ({
it("should print valid json, without wrangler banner", async ({
expect,
}) => {
await runWrangler(
`d1 time-travel info db --timestamp=2011-09-05T14:48:00.000Z --json`
);
expect(std.out).toMatchInlineSnapshot(`
"{
"uuid": "d5b1d127-xxxx-xxxx-xxxx-cbc69f0a9e06",
"name": "db",
expect(JSON.parse(std.out)).toMatchInlineSnapshot(`
{
"created_at": "2023-05-23T08:33:54.590Z",
"version": "beta",
"num_tables": 13,
"file_size": 33067008,
"running_in_region": "WEUR"
}"
"name": "db",
"num_tables": 13,
"running_in_region": "WEUR",
"uuid": "d5b1d127-xxxx-xxxx-xxxx-cbc69f0a9e06",
"version": "beta",
}
`);
});
it("should pretty print by default", async ({ expect }) => {
Expand Down
Loading
Loading