Skip to content

Commit 8f74949

Browse files
authored
Speed up tests (hexclave#1063)
1 parent ba33dde commit 8f74949

36 files changed

Lines changed: 288 additions & 315 deletions

‎.github/workflows/check-prisma-migrations.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ jobs:
5858
run: pnpm run db:init
5959

6060
- name: Check for differences in Prisma schema and current DB
61-
run: cd apps/backend && pnpm run prisma migrate diff --from-config-datasource --to-schema ./prisma/schema.prisma --exit-code
61+
run: cd apps/backend && pnpm run prisma:dev migrate diff --from-config-datasource --to-schema ./prisma/schema.prisma --exit-code

‎apps/backend/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"analyze-bundle": "next experimental-analyze",
1717
"start": "next start --port ${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}02",
1818
"codegen-prisma": "STACK_DATABASE_CONNECTION_STRING=\"${STACK_DATABASE_CONNECTION_STRING:-placeholder-database-connection-string}\" pnpm run prisma generate",
19-
"codegen-prisma:watch": "pnpm run prisma generate --watch",
19+
"codegen-prisma:watch": "STACK_DATABASE_CONNECTION_STRING=\"${STACK_DATABASE_CONNECTION_STRING:-placeholder-database-connection-string}\" pnpm run prisma generate --watch",
2020
"codegen-route-info": "pnpm run with-env tsx scripts/generate-route-info.ts",
2121
"codegen-route-info:watch": "pnpm run with-env tsx watch --clear-screen=false scripts/generate-route-info.ts",
2222
"codegen": "pnpm run with-env pnpm run generate-migration-imports && pnpm run with-env bash -c 'if [ \"$STACK_ACCELERATE_ENABLED\" = \"true\" ]; then pnpm run prisma generate --no-engine; else pnpm run codegen-prisma; fi' && pnpm run codegen-docs && pnpm run codegen-route-info",

‎apps/backend/scripts/run-email-queue.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ async function main() {
88

99
const baseUrl = `http://localhost:${getEnvVariable('NEXT_PUBLIC_STACK_PORT_PREFIX', '81')}02`;
1010

11+
// Wait a few seconds to make sure the server is fully started
12+
await wait(5_000);
13+
1114
const run = () => runAsynchronously(async () => {
1215
// If a the server is restarted, then the existing email queue step may be cancelled prematurely. That's why we
1316
// have an extra loop here to detect and restart the email queue step if it completes too quickly.
1417
const startTime = performance.now();
1518
while (true) {
16-
1719
console.log("Running email queue step...");
1820
const res = await fetch(`${baseUrl}/api/latest/internal/email-queue-step`, {
1921
method: "GET",

‎apps/e2e/tests/backend/backend-helpers.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,12 @@ export namespace User {
13551355
accessType: "server",
13561356
body: body ?? {},
13571357
});
1358-
expect(createUserResponse.status).toBe(201);
1358+
expect(createUserResponse).toMatchObject({
1359+
status: 201,
1360+
body: {
1361+
id: expect.any(String),
1362+
},
1363+
});
13591364
return {
13601365
userId: createUserResponse.body.id,
13611366
};

‎apps/e2e/tests/backend/endpoints/api/v1/data-vault.test.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { it } from "../../../../helpers";
2-
import { Auth, Project, niceBackendFetch } from "../../../backend-helpers";
2+
import { Project, niceBackendFetch } from "../../../backend-helpers";
33

44
async function createDataVaultEnabledProject() {
55
await Project.createAndSwitch({
@@ -39,7 +39,6 @@ function hashKey(key: string): string {
3939

4040
it("can store and retrieve values from data vault", async ({ expect }: { expect: any }) => {
4141
await createDataVaultEnabledProject();
42-
await Auth.Otp.signIn();
4342

4443
const storeId = "test-store-1";
4544
const key = "my-secret-key";
@@ -78,7 +77,6 @@ it("can store and retrieve values from data vault", async ({ expect }: { expect:
7877

7978
it("can update existing values in data vault", async ({ expect }: { expect: any }) => {
8079
await createDataVaultEnabledProject();
81-
await Auth.Otp.signIn();
8280

8381
const storeId = "test-store-update";
8482
const key = "update-key";
@@ -133,7 +131,6 @@ it("can update existing values in data vault", async ({ expect }: { expect: any
133131

134132
it("returns 400 when trying to get non-existent value", async ({ expect }: { expect: any }) => {
135133
await createDataVaultEnabledProject();
136-
await Auth.Otp.signIn();
137134

138135
const storeId = "test-store-404";
139136
const hashedKey = hashKey("non-existent-key");
@@ -167,7 +164,6 @@ it("returns 400 when trying to get non-existent value", async ({ expect }: { exp
167164

168165
it("validates required fields", async ({ expect }: { expect: any }) => {
169166
await createDataVaultEnabledProject();
170-
await Auth.Otp.signIn();
171167

172168
// Test empty store ID (by using spaces which get trimmed)
173169
const emptyStoreResponse = await niceBackendFetch(`/api/latest/data-vault/stores/${encodeURIComponent(" ")}/set`, {
@@ -280,7 +276,6 @@ it("validates required fields", async ({ expect }: { expect: any }) => {
280276

281277
it("isolates data between different stores", async ({ expect }: { expect: any }) => {
282278
await createDataVaultEnabledProject();
283-
await Auth.Otp.signIn();
284279

285280
const key = "shared-key";
286281
const hashedKey = hashKey(key);
@@ -336,7 +331,6 @@ it("isolates data between different stores", async ({ expect }: { expect: any })
336331

337332
it("handles multiple keys in the same store", async ({ expect }: { expect: any }) => {
338333
await createDataVaultEnabledProject();
339-
await Auth.Otp.signIn();
340334

341335
const storeId = "multi-key-store";
342336
const key1 = "key-1";

‎apps/e2e/tests/backend/endpoints/api/v1/integrations/custom/domain.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { it } from "../../../../../../helpers";
22
import { Auth, Project, niceBackendFetch } from "../../../../../backend-helpers";
33

44
it("list domains", async ({ expect }) => {
5-
await Auth.Otp.signIn();
5+
await Auth.fastSignUp();
66
const { adminAccessToken } = await Project.createAndGetAdminToken();
77
const response = await niceBackendFetch("/api/v1/integrations/custom/domains", {
88
accessType: "admin",
@@ -23,7 +23,7 @@ it("list domains", async ({ expect }) => {
2323
});
2424

2525
it("creates domains for internal project", async ({ expect }) => {
26-
await Auth.Otp.signIn();
26+
await Auth.fastSignUp();
2727
const { adminAccessToken } = await Project.createAndGetAdminToken();
2828
const response = await niceBackendFetch("/api/v1/integrations/custom/domains", {
2929
accessType: "admin",
@@ -45,7 +45,7 @@ it("creates domains for internal project", async ({ expect }) => {
4545
});
4646

4747
it("adds two different domains", async ({ expect }) => {
48-
await Auth.Otp.signIn();
48+
await Auth.fastSignUp();
4949
const { adminAccessToken } = await Project.createAndGetAdminToken();
5050

5151
// Add first domain
@@ -96,7 +96,7 @@ it("adds two different domains", async ({ expect }) => {
9696
});
9797

9898
it("does not add if the domain has a path, query parameters, or hash", async ({ expect }) => {
99-
await Auth.Otp.signIn();
99+
await Auth.fastSignUp();
100100
const { adminAccessToken } = await Project.createAndGetAdminToken();
101101
const response = await niceBackendFetch("/api/v1/integrations/custom/domains", {
102102
accessType: "admin",
@@ -127,7 +127,7 @@ it("does not add if the domain has a path, query parameters, or hash", async ({
127127
});
128128

129129
it("adds two domains and deletes one", async ({ expect }) => {
130-
await Auth.Otp.signIn();
130+
await Auth.fastSignUp();
131131
const { adminAccessToken } = await Project.createAndGetAdminToken();
132132

133133
// Add first domain

‎apps/e2e/tests/backend/endpoints/api/v1/integrations/custom/oauth.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ async function authorize(projectId: string) {
151151
}
152152

153153
it(`should redirect to the correct callback URL`, async ({}) => {
154-
await Auth.Otp.signIn();
154+
await Auth.fastSignUp();
155155
const createdProject = await Project.create();
156156

157157
await authorize(createdProject.projectId);
158158
});
159159

160160
it(`should not redirect to the incorrect callback URL`, async ({}) => {
161-
await Auth.Otp.signIn();
161+
await Auth.fastSignUp();
162162
await Project.create();
163163

164164
const result = await authorizePart1("http://localhost:30000/api/v2/wrong-url/authorize");
@@ -190,7 +190,7 @@ it(`should not redirect to the incorrect callback URL`, async ({}) => {
190190
});
191191

192192
it(`should exchange the authorization code for an admin API key that works`, async ({}) => {
193-
await Auth.Otp.signIn();
193+
await Auth.fastSignUp();
194194
const createdProject = await Project.create();
195195

196196
const { authorizationCode } = await authorize(createdProject.projectId);
@@ -244,7 +244,7 @@ it(`should exchange the authorization code for an admin API key that works`, asy
244244
});
245245

246246
it(`should not exchange the authorization code when the client secret is incorrect`, async ({}) => {
247-
await Auth.Otp.signIn();
247+
await Auth.fastSignUp();
248248
const createdProject = await Project.create();
249249

250250
const { authorizationCode } = await authorize(createdProject.projectId);

‎apps/e2e/tests/backend/endpoints/api/v1/integrations/custom/projects/transfer.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async function provisionAndTransferProject() {
3030
const provisioned = await provisionProject();
3131
const projectId = provisioned.body.project_id;
3232
const { code } = await initiateTransfer(projectId);
33-
await Auth.Otp.signIn();
33+
await Auth.fastSignUp();
3434
const response = await niceBackendFetch(`/api/v1/integrations/custom/projects/transfer/confirm`, {
3535
method: "POST",
3636
accessType: "client",
@@ -68,7 +68,7 @@ it("should return that the project is transferrable if it is provisioned", async
6868
});
6969

7070
it("should return that the project is not transferrable if it is not provisioned", async ({ expect }) => {
71-
await Auth.Otp.signIn();
71+
await Auth.fastSignUp();
7272
const createdProject = await Project.create();
7373
const response = await niceBackendFetch(urlString`/api/v1/integrations/custom/projects/transfer?project_id=${createdProject.createProjectResponse.body.id}`, {
7474
method: "GET",
@@ -128,7 +128,7 @@ it("should initiate multiple transfers for the same project, but only one can be
128128
const projectId = provisioned.body.project_id;
129129
const { code: code1 } = await initiateTransfer(projectId);
130130
const { code: code2 } = await initiateTransfer(projectId);
131-
await Auth.Otp.signIn();
131+
await Auth.fastSignUp();
132132
const response1 = await niceBackendFetch(`/api/v1/integrations/custom/projects/transfer/confirm`, {
133133
method: "POST",
134134
accessType: "client",
@@ -163,7 +163,7 @@ it("should initiate multiple transfers for the same project, but only one can be
163163
});
164164

165165
it("should fail if the project to transfer was not provisioned by Neon", async ({ expect }) => {
166-
await Auth.Otp.signIn();
166+
await Auth.fastSignUp();
167167
const createdProject = await Project.create();
168168
const response = await niceBackendFetch("/api/v1/integrations/custom/projects/transfer/initiate", {
169169
method: "POST",
@@ -248,7 +248,7 @@ it("should check if the project exists before initiating transfer", async ({ exp
248248
const provisioned = await provisionProject();
249249
const projectId = provisioned.body.project_id;
250250
const { code } = await initiateTransfer(projectId);
251-
await Auth.Otp.signIn();
251+
await Auth.fastSignUp();
252252
const response = await niceBackendFetch(`/api/v1/integrations/custom/projects/transfer/confirm/check`, {
253253
method: "POST",
254254
accessType: "client",
@@ -269,7 +269,7 @@ it("should fail the check if project was already transferred", async ({ expect }
269269
const provisioned = await provisionProject();
270270
const projectId = provisioned.body.project_id;
271271
const { code } = await initiateTransfer(projectId);
272-
await Auth.Otp.signIn();
272+
await Auth.fastSignUp();
273273
const response = await niceBackendFetch(`/api/v1/integrations/custom/projects/transfer/confirm`, {
274274
method: "POST",
275275
accessType: "client",

‎apps/e2e/tests/backend/endpoints/api/v1/integrations/neon/api-keys.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ describe("with server access", () => {
5656

5757
describe("with admin access to the internal project", () => {
5858
it("list api keys", async ({ expect }) => {
59-
await Auth.Otp.signIn();
59+
await Auth.fastSignUp();
6060
const response = await niceBackendFetch("/api/v1/integrations/neon/api-keys", { accessType: "admin" });
6161
expect(response.status).toBe(200); // not doing snapshot as it contains all the test api keys
6262
});
6363

6464
it("creates api keys for internal project", async ({ expect }) => {
65-
await Auth.Otp.signIn();
65+
await Auth.fastSignUp();
6666
const response1 = await niceBackendFetch("/api/v1/integrations/neon/api-keys", {
6767
accessType: "admin",
6868
method: "POST",

‎apps/e2e/tests/backend/endpoints/api/v1/integrations/neon/domain.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { it } from "../../../../../../helpers";
22
import { Auth, Project, niceBackendFetch } from "../../../../../backend-helpers";
33

44
it("list domains", async ({ expect }) => {
5-
await Auth.Otp.signIn();
5+
await Auth.fastSignUp();
66
const { adminAccessToken } = await Project.createAndGetAdminToken();
77
const response = await niceBackendFetch("/api/v1/integrations/neon/domains", {
88
accessType: "admin",
@@ -23,7 +23,7 @@ it("list domains", async ({ expect }) => {
2323
});
2424

2525
it("creates domains for internal project", async ({ expect }) => {
26-
await Auth.Otp.signIn();
26+
await Auth.fastSignUp();
2727
const { adminAccessToken } = await Project.createAndGetAdminToken();
2828
const response = await niceBackendFetch("/api/v1/integrations/neon/domains", {
2929
accessType: "admin",
@@ -45,7 +45,7 @@ it("creates domains for internal project", async ({ expect }) => {
4545
});
4646

4747
it("adds two different domains", async ({ expect }) => {
48-
await Auth.Otp.signIn();
48+
await Auth.fastSignUp();
4949
const { adminAccessToken } = await Project.createAndGetAdminToken();
5050

5151
// Add first domain
@@ -96,7 +96,7 @@ it("adds two different domains", async ({ expect }) => {
9696
});
9797

9898
it("does not add if the domain has a path, query parameters, or hash", async ({ expect }) => {
99-
await Auth.Otp.signIn();
99+
await Auth.fastSignUp();
100100
const { adminAccessToken } = await Project.createAndGetAdminToken();
101101
const response = await niceBackendFetch("/api/v1/integrations/neon/domains", {
102102
accessType: "admin",
@@ -127,7 +127,7 @@ it("does not add if the domain has a path, query parameters, or hash", async ({
127127
});
128128

129129
it("adds two domains and deletes one", async ({ expect }) => {
130-
await Auth.Otp.signIn();
130+
await Auth.fastSignUp();
131131
const { adminAccessToken } = await Project.createAndGetAdminToken();
132132

133133
// Add first domain
@@ -192,7 +192,7 @@ it("adds two domains and deletes one", async ({ expect }) => {
192192
});
193193

194194
it("fails when not specifying a domain", async ({ expect }) => {
195-
await Auth.Otp.signIn();
195+
await Auth.fastSignUp();
196196
const { adminAccessToken } = await Project.createAndGetAdminToken();
197197

198198
const response = await niceBackendFetch("/api/v1/integrations/neon/domains", {

0 commit comments

Comments
 (0)