Skip to content

Commit

Permalink
Allow multiple spaces in PRISMA_DIRECT_URL_REGEXP (#8001)
Browse files Browse the repository at this point in the history
* Allow multiple spaces in PRISMA_DIRECT_URL_REGEXP

Allows multiple spaces between directUrl = env, since some code formatters add these to schema.prisma.

* test: ✅ formatted directUrl test

---------

Co-authored-by: David Thyresson <dthyresson@gmail.com>
Co-authored-by: Dominic Saadi <dominiceliassaadi@gmail.com>
  • Loading branch information
3 people authored Apr 25, 2023
1 parent 531097f commit d81aa49
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions packages/testing/src/api/__tests__/directUrlHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
2 changes: 1 addition & 1 deletion packages/testing/src/api/directUrlHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /\(('|")([^)]+)('|")\)/

0 comments on commit d81aa49

Please sign in to comment.