Skip to content

Commit

Permalink
test: testing verbose output
Browse files Browse the repository at this point in the history
  • Loading branch information
4lejandrito committed Oct 16, 2023
1 parent 0fdf106 commit 37ed0be
Show file tree
Hide file tree
Showing 3 changed files with 254 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/test-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let testServer: TestServer | undefined = undefined;

if (process.env.FETCHBOOK_TEST) {
const app = jsonServer.create();
app.disable("etag");
app.use(jsonServer.defaults({ logger: false }));
const router = jsonServer.router<{ posts: { id: number; it?: string }[] }>({
posts: [],
Expand Down
251 changes: 251 additions & 0 deletions test/__snapshots__/fetchbook.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,257 @@ exports[`fetchbook run test/pass --all 2`] = `

exports[`fetchbook run test/pass --all 3`] = `""`;

exports[`fetchbook run test/pass --all -v 1`] = `0`;

exports[`fetchbook run test/pass --all -v 2`] = `
"{
"request": {
"url": "http://localhost:3000/posts",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"body": {
"it": "works!"
}
},
"response": {
"status": 201,
"headers": {
"vary": "Origin, X-HTTP-Method-Override, Accept-Encoding",
"access-control-allow-credentials": "true",
"cache-control": "no-cache",
"pragma": "no-cache",
"expires": "-1",
"access-control-expose-headers": "Location",
"location": "http://localhost:3000/posts/2",
"x-content-type-options": "nosniff",
"content-type": "application/json; charset=utf-8",
"content-length": "31",
"x-powered-by": "Express"
},
"body": {
"it": "works!",
"id": 2
}
}
}
{
"request": {
"url": "http://localhost:3000/posts",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"body": {
"it": "works!"
}
},
"response": {
"status": 201,
"headers": {
"vary": "Origin, X-HTTP-Method-Override, Accept-Encoding",
"access-control-allow-credentials": "true",
"cache-control": "no-cache",
"pragma": "no-cache",
"expires": "-1",
"access-control-expose-headers": "Location",
"location": "http://localhost:3000/posts/2",
"x-content-type-options": "nosniff",
"content-type": "application/json; charset=utf-8",
"content-length": "31",
"x-powered-by": "Express"
},
"body": {
"it": "works!",
"id": 2
}
}
}
{
"request": {
"url": "http://localhost:3000/posts",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"body": {
"it": "works!"
}
},
"response": {
"status": 201,
"headers": {
"vary": "Origin, X-HTTP-Method-Override, Accept-Encoding",
"access-control-allow-credentials": "true",
"cache-control": "no-cache",
"pragma": "no-cache",
"expires": "-1",
"access-control-expose-headers": "Location",
"location": "http://localhost:3000/posts/3",
"x-content-type-options": "nosniff",
"content-type": "application/json; charset=utf-8",
"content-length": "31",
"x-powered-by": "Express"
},
"body": {
"it": "works!",
"id": 3
}
}
}
{
"request": {
"url": "http://localhost:3000/posts",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"body": {
"it": "works!"
}
},
"response": {
"status": 201,
"headers": {
"vary": "Origin, X-HTTP-Method-Override, Accept-Encoding",
"access-control-allow-credentials": "true",
"cache-control": "no-cache",
"pragma": "no-cache",
"expires": "-1",
"access-control-expose-headers": "Location",
"location": "http://localhost:3000/posts/4",
"x-content-type-options": "nosniff",
"content-type": "application/json; charset=utf-8",
"content-length": "31",
"x-powered-by": "Express"
},
"body": {
"it": "works!",
"id": 4
}
}
}
{
"request": {
"url": "http://localhost:3000/posts",
"method": "GET"
},
"response": {
"status": 200,
"headers": {
"vary": "Origin, Accept-Encoding",
"access-control-allow-credentials": "true",
"cache-control": "no-cache",
"pragma": "no-cache",
"expires": "-1",
"x-content-type-options": "nosniff",
"content-type": "application/json; charset=utf-8",
"content-length": "166",
"x-powered-by": "Express"
},
"body": [
{
"id": 1,
"it": "works!"
},
{
"it": "works!",
"id": 2
},
{
"it": "works!",
"id": 3
},
{
"it": "works!",
"id": 4
}
]
}
}
{
"request": {
"url": "http://localhost:3000/posts/0",
"method": "GET"
},
"response": {
"status": 404,
"headers": {
"vary": "Origin, Accept-Encoding",
"access-control-allow-credentials": "true",
"cache-control": "no-cache",
"pragma": "no-cache",
"expires": "-1",
"x-content-type-options": "nosniff",
"content-type": "application/json; charset=utf-8",
"content-length": "2",
"x-powered-by": "Express"
},
"body": {}
}
}
{
"request": {
"url": "http://localhost:3000/posts/1",
"method": "GET",
"headers": {
"Some-Header": "value"
}
},
"response": {
"status": 200,
"headers": {
"vary": "Origin, Accept-Encoding",
"access-control-allow-credentials": "true",
"cache-control": "no-cache",
"pragma": "no-cache",
"expires": "-1",
"x-content-type-options": "nosniff",
"content-type": "application/json; charset=utf-8",
"content-length": "31",
"x-powered-by": "Express"
},
"body": {
"id": 1,
"it": "works!"
}
}
}
{
"request": {
"url": "http://localhost:3000/posts",
"method": "GET",
"headers": {
"Some-Header": "value"
}
},
"response": {
"status": 200,
"headers": {
"vary": "Origin, Accept-Encoding",
"access-control-allow-credentials": "true",
"cache-control": "no-cache",
"pragma": "no-cache",
"expires": "-1",
"x-content-type-options": "nosniff",
"content-type": "application/json; charset=utf-8",
"content-length": "43",
"x-powered-by": "Express"
},
"body": [
{
"id": 1,
"it": "works!"
}
]
}
}
[?25h"
`;

exports[`fetchbook run test/pass --all -v 3`] = `""`;

exports[`fetchbook run test/fail --all 1`] = `0`;

exports[`fetchbook run test/fail --all 2`] = `
Expand Down
3 changes: 2 additions & 1 deletion test/fetchbook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function $test(command: TemplateStringsArray) {
test(command.toString(), async () => {
const { exitCode, stdout, stderr } = await $(command);
expect(exitCode).toMatchSnapshot();
expect(stdout).toMatchSnapshot();
expect(stdout.replaceAll(/\s*"date": ".+",?/g, "")).toMatchSnapshot();
expect(stderr).toMatchSnapshot();
});
}
Expand All @@ -15,6 +15,7 @@ $test`fetchbook --help`;
$test`fetchbook --version`;
$test`fetchbook run --all`;
$test`fetchbook run test/pass --all`;
$test`fetchbook run test/pass --all -v`;
$test`fetchbook run test/fail --all`;
$test`fetchbook run test --all`;
$test`fetchbook run examples --all`;
Expand Down

0 comments on commit 37ed0be

Please sign in to comment.