Skip to content

Commit 2638be5

Browse files
committed
fix: vitest tests
1 parent 731c482 commit 2638be5

File tree

6 files changed

+60
-42
lines changed

6 files changed

+60
-42
lines changed

examples/ci/app/ci/ci.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { test, describe } from "vitest";
22
import { TEST_ROUTES, TEST_TIMEOUT_DURATION } from "./constants";
33
import { initiateTest } from "./utils";
4+
import { config } from "dotenv";
5+
6+
config();
47

58
describe("workflow integration tests", () => {
69
TEST_ROUTES.forEach(testConfig => {

examples/ci/app/ci/upstash/qstash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const startWorkflow = async (
2222
[ CI_ROUTE_HEADER ]: testConfig.route,
2323
...testConfig.headers
2424
},
25-
body: testConfig.payload
25+
body: testConfig.payload,
2626
})
2727
return result
2828
}

examples/ci/app/ci/upstash/redis.test.ts

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ import * as redis from "./redis"
33
import { nanoid } from "../utils";
44

55
describe("redis", () => {
6-
test("should throw on missing results", () => {
7-
expect(() =>
8-
redis.checkRedisForResults("some-route", "some-id", -1, "some-result", 1)
9-
).toThrow(
10-
"result not found for route some-route with randomTestId some-id"
6+
test("should throw on missing results", { timeout: 15000 },async () => {
7+
await expect(redis.checkRedisForResults("some-route", "some-id", -1, "some-result", 1)).rejects.toThrowError(
8+
"result not found for route some-route with randomTestId some-id"
119
)
12-
}, { timeout: 15000 })
10+
})
1311

1412
test("should throw when saving results without any increment", () => {
15-
expect(() =>
16-
redis.saveResultsWithoutContext("some-route", "some-id", "some-result")
17-
).toThrow(
13+
expect(async () =>
14+
await redis.saveResultsWithoutContext("some-route", "some-id", "some-result")
15+
).rejects.toThrowError(
1816
"callCount shouldn't be 0. It was 0 in test of the route 'some-route'"
1917
)
2018
})
@@ -32,53 +30,54 @@ describe("redis", () => {
3230
})
3331

3432
test("should throw on mismatching result", () => {
35-
expect(() =>
36-
redis.checkRedisForResults(route, randomId, 2, "not-correct")
37-
).toThrow(
33+
expect(async () =>
34+
await redis.checkRedisForResults(route, randomId, 2, "not-correct")
35+
).rejects.toThrowError(
3836
`Unexpected value.\n\tReceived \"${result}\"\n\tExpected \"not-correct\"`
3937
)
4038
})
4139

4240
test("should throw on mismatching call count", () => {
43-
expect(() =>
44-
redis.checkRedisForResults(route, randomId, 123, result)
45-
).toThrow(
41+
expect(async () =>
42+
await redis.checkRedisForResults(route, randomId, 123, result)
43+
).rejects.toThrowError(
4644
`Unexpected value.\n\tReceived \"2\"\n\tExpected \"123\"`
4745
)
4846
})
4947

5048
test("should not throw on correct results", () => {
51-
expect(() =>
52-
redis.checkRedisForResults(route, randomId, 2, result)
53-
).not.toThrow()
49+
expect(async () =>
50+
await redis.checkRedisForResults(route, randomId, 2, result)
51+
).not.toThrowError()
5452
})
5553
})
5654

57-
test("should override call count", async () => {
55+
describe("override call count", () => {
56+
test("should override call count", async () => {
57+
const route = "override-route";
58+
const randomId = `random-id-${nanoid()}`;
59+
const result = `random-result-${nanoid()}`;
60+
const override = -3;
5861

59-
const route = "override-route"
60-
const randomId = `random-id-${nanoid()}`
61-
const result = `random-result-${nanoid()}`
62-
const override = -3
63-
64-
await redis.increment(route, randomId)
65-
await redis.increment(route, randomId)
66-
await redis.increment(route, randomId)
62+
await redis.increment(route, randomId);
63+
await redis.increment(route, randomId);
64+
await redis.increment(route, randomId);
6765

68-
await redis.saveResultsWithoutContext(route, randomId, result, override)
66+
await redis.saveResultsWithoutContext(route, randomId, result, override);
6967

70-
expect(() =>
71-
redis.checkRedisForResults(route, randomId, 3, result)
72-
).toThrow(
73-
`Unexpected value.\n\tReceived \"-3\"\n\tExpected \"3\"`
74-
)
68+
expect(async () =>
69+
await redis.checkRedisForResults(route, randomId, 3, result)
70+
).rejects.toThrowError(
71+
`Unexpected value.\n\tReceived \"-3\"\n\tExpected \"3\"`
72+
);
73+
});
7574

7675
test("should not throw on correct results", () => {
77-
expect(() =>
78-
redis.checkRedisForResults(route, randomId, override, result)
79-
).not.toThrow()
80-
})
81-
})
76+
expect(async () =>
77+
await redis.checkRedisForResults("override-route", `random-id-${nanoid()}`, -3, `random-result-${nanoid()}`)
78+
).not.toThrowError();
79+
});
80+
});
8281

8382
test("should fail if marked as failed", async () => {
8483

@@ -93,7 +92,7 @@ describe("redis", () => {
9392

9493
// mark as failed and check
9594
await redis.failWithoutContext(route, randomId)
96-
expect(redis.checkRedisForResults(route, randomId, 1, result)).rejects.toThrow(redis.FAILED_TEXT)
95+
expect(redis.checkRedisForResults(route, randomId, 1, result)).rejects.toThrowError(redis.FAILED_TEXT)
9796

9897
})
9998
})

examples/ci/app/ci/utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import { test, expect } from "vitest";
22
import { expect as utilsExpect } from "./utils"
33

44
test("expect", () => {
5-
expect(() => utilsExpect("same", "same")).not.toThrow()
6-
expect(() => utilsExpect("not", "same")).toThrow(`Unexpected value.\n\tReceived "not"\n\tExpected "same"`)
5+
expect(() => utilsExpect("same", "same")).not.toThrowError()
6+
expect(() => utilsExpect("not", "same")).toThrowError()
77
})

examples/ci/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@upstash/workflow": "latest",
1616
"@vercel/functions": "^1.5.0",
1717
"clsx": "^2.1.1",
18+
"dotenv": "^16.5.0",
1819
"next": "14.2.23",
1920
"react": "^18.3.1",
2021
"react-dom": "^18.3.1",

examples/ci/vitest.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { config } from "dotenv";
2+
import { defineConfig } from "vitest/config";
3+
4+
export default defineConfig({
5+
test: {
6+
passWithNoTests: true,
7+
globals: true,
8+
coverage: {
9+
provider: "v8",
10+
},
11+
env: {
12+
...config({ path: "./.env" }).parsed,
13+
},
14+
},
15+
});

0 commit comments

Comments
 (0)