@@ -9,28 +9,10 @@ declare const newPrismaClient: NewPrismaClient<typeof PrismaClient>
99declare let Prisma : typeof PrismaNamespace
1010
1111testMatrix . setupTestSuite (
12- ( { clientRuntime, driverAdapter } , suiteMeta , clientMeta ) => {
13- // TODO: Fails with Expected PrismaClientInitError, Received Error
14- skipTestIf ( clientRuntime === 'wasm' ) ( 'PrismaClientInitializationError for missing env' , async ( ) => {
15- const prisma = newPrismaClient ( )
16-
17- try {
18- await prisma . $connect ( )
19- } catch ( e ) {
20- const message = stripAnsi ( e . message as string )
21- expect ( e ) . toBeInstanceOf ( Prisma . PrismaClientInitializationError )
22- expect ( message ) . toContain ( 'error: Environment variable not found: DATABASE_URI.' )
23- }
24- } )
25- // TODO: Fails with Expected PrismaClientInitError, Received Error
26- skipTestIf ( driverAdapter !== undefined ) (
27- 'PrismaClientInitializationError for missing env and empty override' ,
28- async ( ) => {
29- const prisma = newPrismaClient ( {
30- datasources : {
31- db : { } ,
32- } ,
33- } )
12+ ( { driverAdapter } , _suiteMeta , clientMeta ) => {
13+ describeIf ( driverAdapter === undefined ) ( 'default case: no Driver Adapter' , ( ) => {
14+ test ( 'PrismaClientInitializationError for missing env' , async ( ) => {
15+ const prisma = newPrismaClient ( )
3416
3517 try {
3618 await prisma . $connect ( )
@@ -39,62 +21,112 @@ testMatrix.setupTestSuite(
3921 expect ( e ) . toBeInstanceOf ( Prisma . PrismaClientInitializationError )
4022 expect ( message ) . toContain ( 'error: Environment variable not found: DATABASE_URI.' )
4123 }
42- } ,
43- )
4424
45- testIf ( clientMeta . dataProxy && clientMeta . runtime === 'edge' ) (
46- 'PrismaClientInitializationError for missing env on edge' ,
47- async ( ) => {
48- const prisma = newPrismaClient ( )
25+ expect . hasAssertions ( )
26+ } )
27+
28+ test ( 'PrismaClientInitializationError for missing env and empty override' , async ( ) => {
29+ const prisma = newPrismaClient ( {
30+ datasources : {
31+ db : { } ,
32+ } ,
33+ } )
4934
5035 try {
5136 await prisma . $connect ( )
5237 } catch ( e ) {
5338 const message = stripAnsi ( e . message as string )
5439 expect ( e ) . toBeInstanceOf ( Prisma . PrismaClientInitializationError )
55- expect ( message ) . toMatchInlineSnapshot ( `" error: Environment variable not found: DATABASE_URI."` )
40+ expect ( message ) . toContain ( ' error: Environment variable not found: DATABASE_URI.' )
5641 }
57- } ,
58- )
5942
60- testIf ( clientMeta . dataProxy && clientMeta . runtime === 'edge' ) (
61- 'PrismaClientInitializationError for missing env on edge on cloudflare' ,
62- async ( ) => {
63- globalThis . navigator = { userAgent : 'Cloudflare-Workers' }
43+ expect . hasAssertions ( )
44+ } )
6445
65- const prisma = newPrismaClient ( )
46+ testIf ( clientMeta . dataProxy && clientMeta . runtime === 'edge' ) (
47+ 'PrismaClientInitializationError for missing env on edge' ,
48+ async ( ) => {
49+ const prisma = newPrismaClient ( )
6650
67- try {
68- await prisma . $connect ( )
69- } catch ( e ) {
70- const message = stripAnsi ( e . message as string )
71- expect ( e ) . toBeInstanceOf ( Prisma . PrismaClientInitializationError )
72- expect ( message ) . toMatchInlineSnapshot ( `
73- "error: Environment variable not found: DATABASE_URI.
51+ try {
52+ await prisma . $connect ( )
53+ } catch ( e ) {
54+ const message = stripAnsi ( e . message as string )
55+ expect ( e ) . toBeInstanceOf ( Prisma . PrismaClientInitializationError )
56+ expect ( message ) . toMatchInlineSnapshot ( `"error: Environment variable not found: DATABASE_URI."` )
57+ }
7458
75- In Cloudflare module Workers, environment variables are available only in the Worker's \`env\` parameter of \`fetch\`.
76- To solve this, provide the connection string directly: https://pris.ly/d/cloudflare-datasource-url"
77- ` )
78- }
59+ expect . hasAssertions ( )
60+ } ,
61+ )
62+
63+ testIf ( clientMeta . dataProxy && clientMeta . runtime === 'edge' ) (
64+ 'PrismaClientInitializationError for missing env on edge on cloudflare' ,
65+ async ( ) => {
66+ globalThis . navigator = { userAgent : 'Cloudflare-Workers' }
67+
68+ const prisma = newPrismaClient ( )
69+
70+ try {
71+ await prisma . $connect ( )
72+ } catch ( e ) {
73+ const message = stripAnsi ( e . message as string )
74+ expect ( e ) . toBeInstanceOf ( Prisma . PrismaClientInitializationError )
75+ expect ( message ) . toMatchInlineSnapshot ( `
76+ "error: Environment variable not found: DATABASE_URI.
7977
80- delete globalThis . navigator
81- } ,
82- )
78+ In Cloudflare module Workers, environment variables are available only in the Worker's \`env\` parameter of \`fetch\`.
79+ To solve this, provide the connection string directly: https://pris.ly/d/cloudflare-datasource-url"
80+ ` )
81+ }
8382
84- testIf ( clientMeta . dataProxy && clientMeta . runtime === 'node' ) (
85- 'PrismaClientInitializationError for missing env with --no-engine on node' ,
86- async ( ) => {
83+ expect . hasAssertions ( )
84+ delete globalThis . navigator
85+ } ,
86+ )
87+
88+ testIf ( clientMeta . dataProxy && clientMeta . runtime === 'node' ) (
89+ 'PrismaClientInitializationError for missing env with --no-engine on node' ,
90+ async ( ) => {
91+ const prisma = newPrismaClient ( )
92+
93+ try {
94+ await prisma . $connect ( )
95+ } catch ( e ) {
96+ const message = stripAnsi ( e . message as string )
97+ expect ( e ) . toBeInstanceOf ( Prisma . PrismaClientInitializationError )
98+ expect ( message ) . toMatchInlineSnapshot ( `"error: Environment variable not found: DATABASE_URI."` )
99+ }
100+
101+ expect . hasAssertions ( )
102+ } ,
103+ )
104+ } )
105+
106+ describeIf ( driverAdapter !== undefined ) ( 'with Driver Adapters' , ( ) => {
107+ test ( 'Initialisation works even when missing env var referenced in the schema' , async ( ) => {
87108 const prisma = newPrismaClient ( )
109+ await prisma . $connect ( )
110+ } )
88111
112+ test ( 'PrismaClientInitializationError for missing env and empty override' , ( ) => {
89113 try {
90- await prisma . $connect ( )
114+ newPrismaClient ( {
115+ datasources : {
116+ db : { } ,
117+ } ,
118+ } )
91119 } catch ( e ) {
92120 const message = stripAnsi ( e . message as string )
93121 expect ( e ) . toBeInstanceOf ( Prisma . PrismaClientInitializationError )
94- expect ( message ) . toMatchInlineSnapshot ( `"error: Environment variable not found: DATABASE_URI."` )
122+ expect ( message ) . toMatchInlineSnapshot (
123+ `"Custom datasource configuration is not compatible with Prisma Driver Adapters. Please define the database connection string directly in the Driver Adapter configuration."` ,
124+ )
95125 }
96- } ,
97- )
126+
127+ expect . hasAssertions ( )
128+ } )
129+ } )
98130 } ,
99131 {
100132 skipDb : true ,
0 commit comments