From 0595ef719bb78e4be5f4ff5a31fb81e04ae2f1d8 Mon Sep 17 00:00:00 2001 From: dennemark Date: Mon, 3 Apr 2023 13:57:59 +0200 Subject: [PATCH 1/2] Allow multiple spaces in PRISMA_DIRECT_URL_REGEXP Allows multiple spaces between directUrl = env, since some code formatters add these to schema.prisma. --- packages/testing/src/api/directUrlHelpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/testing/src/api/directUrlHelpers.ts b/packages/testing/src/api/directUrlHelpers.ts index 7499c529c9e6..b2b12ed16adc 100644 --- a/packages/testing/src/api/directUrlHelpers.ts +++ b/packages/testing/src/api/directUrlHelpers.ts @@ -35,5 +35,5 @@ export function checkAndReplaceDirectUrl( return directUrlEnv } -const PRISMA_DIRECT_URL_REGEXP = /directUrl(\s?)=(\s?)env\(('|")(.*)('|")\)/g +const PRISMA_DIRECT_URL_REGEXP = /directUrl(\s*)=(\s*)env\(('|")(.*)('|")\)/g const BETWEEN_PARENTHESES_REGEXP = /\(('|")([^)]+)('|")\)/ From a68dd8ee0a673bc6e989e7b88081c10a863012ac Mon Sep 17 00:00:00 2001 From: dennemark Date: Tue, 4 Apr 2023 22:42:48 +0200 Subject: [PATCH 2/2] test: :white_check_mark: formatted directUrl test --- .../src/api/__tests__/directUrlHelpers.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/testing/src/api/__tests__/directUrlHelpers.test.ts b/packages/testing/src/api/__tests__/directUrlHelpers.test.ts index b6fa44990837..5d6a71004d3d 100644 --- a/packages/testing/src/api/__tests__/directUrlHelpers.test.ts +++ b/packages/testing/src/api/__tests__/directUrlHelpers.test.ts @@ -41,3 +41,19 @@ it("overwrites directUrl if it's set", () => { delete process.env.RWJS_CWD }) + +it("overwrites directUrl if it's set and formatted", () => { + const prismaSchema = `datasource db { + provider = "sqlite" + url = env("DATABASE_URL") + directUrl = env("DIRECT_URL") + shadowDatabaseUrl = env("SHADOW_DATABASE_URL") + }` + process.env.RWJS_CWD = DIRECT_URL_FIXTURE_PATH + + const defaultDb = getDefaultDb(DIRECT_URL_FIXTURE_PATH) + + const directUrlEnvVar = checkAndReplaceDirectUrl(prismaSchema, defaultDb) + + expect(process.env[directUrlEnvVar as string]).toBe(defaultDb) +})