From 37ed0beb2f099b13d40c622aa12b2edce06a981d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Tard=C3=ADn?= Date: Mon, 16 Oct 2023 10:44:22 +0200 Subject: [PATCH] test: testing verbose output --- lib/test-server.ts | 1 + test/__snapshots__/fetchbook.test.ts.snap | 251 ++++++++++++++++++++++ test/fetchbook.test.ts | 3 +- 3 files changed, 254 insertions(+), 1 deletion(-) diff --git a/lib/test-server.ts b/lib/test-server.ts index d36a69e..52c3e3c 100644 --- a/lib/test-server.ts +++ b/lib/test-server.ts @@ -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: [], diff --git a/test/__snapshots__/fetchbook.test.ts.snap b/test/__snapshots__/fetchbook.test.ts.snap index cec126a..4f6d00c 100644 --- a/test/__snapshots__/fetchbook.test.ts.snap +++ b/test/__snapshots__/fetchbook.test.ts.snap @@ -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`] = ` diff --git a/test/fetchbook.test.ts b/test/fetchbook.test.ts index 6fba971..7b20173 100644 --- a/test/fetchbook.test.ts +++ b/test/fetchbook.test.ts @@ -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(); }); } @@ -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`;