From 4d3c34579dee5d3e71b4e692172bd1ef9b6f6279 Mon Sep 17 00:00:00 2001 From: Rushil Perera Date: Fri, 14 Jun 2024 17:55:18 -0400 Subject: [PATCH] test: add code snippets for generating tests --- .vscode/test.code-snippets | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .vscode/test.code-snippets diff --git a/.vscode/test.code-snippets b/.vscode/test.code-snippets new file mode 100644 index 0000000..1be900a --- /dev/null +++ b/.vscode/test.code-snippets @@ -0,0 +1,72 @@ +{ + "Test for library function": { + "scope": "typescript", + "isFileTemplate": true, + "prefix": "testLib", + "body": [ + "import { describe, expect, it } from \"bun:test\";", + "", + "import { $1 } from \"./$1\";", + "", + "describe(\"$1\", () => {", + " it(\"$2\", () => {", + " });", + "});", + "", + ], + "description": "Test for library function", + }, + "Test for route": { + "prefix": "testRoute", + "body": [ + "import { describe, expect, it } from \"bun:test\";", + "", + "import app from \"~/index\";", + "import { server } from \"~/mocks\";", + "", + "server.listen();", + "", + "describe(\"requests the /$1 route\", () => {", + " it(\"should succeed\", async () => {", + " const res = await app.request(\"/$1\");", + "", + " expect(res.json()).resolves.toEqual({ success: true });", + " expect(res.status).toBe(200);", + " });", + "});", + "", + ], + "description": "Test for route", + }, + "Test for route with DB": { + "prefix": "testRouteDB", + "body": [ + "import { beforeEach, describe, expect, it } from \"bun:test\";", + "", + "import app from \"~/index\";", + "import { server } from \"~/mocks\";", + "import { getDb, resetDb } from \"~/models/db\";", + "", + "server.listen();", + "", + "describe(\"requests the /$1 route\", () => {", + " const db = getDb({", + " TURSO_URL: process.env.TURSO_URL ?? \"http://127.0.0.1:3000\",", + " TURSO_AUTH_TOKEN: process.env.TURSO_AUTH_TOKEN ?? \"asd\",", + " });", + "", + " beforeEach(async () => {", + " await resetDb();", + " });", + "", + " it(\"should succeed\", async () => {", + " const res = await app.request(\"/$1\");", + "", + " expect(res.json()).resolves.toEqual({ success: true });", + " expect(res.status).toBe(200); ", + " });", + "});", + ], + "description": "Test for route with DB", + }, +}