Skip to content

Commit 8b30e05

Browse files
committed
add test coverage
1 parent 411345d commit 8b30e05

File tree

4 files changed

+299
-6
lines changed

4 files changed

+299
-6
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"lint": "yarn workspaces run lint",
1818
"prepare": "node .husky/install.mjs || true",
1919
"typecheck": "yarn workspaces run typecheck",
20-
"test:unit": "cross-env RunEnvironment='dev' vitest run tests/unit --config tests/unit/vitest.config.ts && yarn workspace infra-core-ui run test:unit",
20+
"test:unit": "cross-env RunEnvironment='dev' vitest run --coverage tests/unit --config tests/unit/vitest.config.ts && yarn workspace infra-core-ui run test:unit",
2121
"test:unit-ui": "yarn test:unit --ui",
2222
"test:unit-watch": "vitest tests/unit",
2323
"test:live": "vitest tests/live",
@@ -38,6 +38,7 @@
3838
"@typescript-eslint/eslint-plugin": "^8.0.1",
3939
"@typescript-eslint/parser": "^8.0.1",
4040
"@vitejs/plugin-react": "^4.3.1",
41+
"@vitest/coverage-istanbul": "2.1.9",
4142
"@vitest/ui": "^2.0.5",
4243
"aws-sdk-client-mock": "^4.1.0",
4344
"concurrently": "^9.1.2",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect, test, describe } from "vitest";
2+
import { parseSQSPayload } from "../../../src/common/types/sqsMessage.js";
3+
import { ZodError } from "zod";
4+
5+
describe("SQS Message Parsing Tests", () => {
6+
test("Ping message parses correctly", () => {
7+
const payload = {
8+
metadata: {
9+
reqId: "12345",
10+
initiator: "unit-test",
11+
},
12+
function: "ping",
13+
payload: {},
14+
};
15+
const response = parseSQSPayload(payload);
16+
expect(response).toStrictEqual(payload);
17+
});
18+
test("Invalid function doesn't parse", () => {
19+
const payload = {
20+
metadata: {
21+
reqId: "12345",
22+
initiator: "unit-test",
23+
},
24+
function: "invalid_function",
25+
payload: {},
26+
};
27+
expect(parseSQSPayload(payload)).toBeInstanceOf(ZodError);
28+
});
29+
});

tests/unit/vitest.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const __dirname = path.dirname(__filename);
88
export default defineConfig({
99
test: {
1010
setupFiles: "./tests/unit/vitest.setup.ts",
11+
coverage: {
12+
provider: "istanbul",
13+
include: ["src/api/**/*.ts", "src/common/**/*.ts"],
14+
},
1115
},
1216
resolve: {
1317
alias: {

0 commit comments

Comments
 (0)