@@ -17,13 +17,6 @@ setSkipWatching();
1717
1818const dbUrl = 'file:./app.db' ;
1919
20- async function setupAndStopDevServerForMigrations ( cwd : string , resetDb : boolean = false ) {
21- if ( resetDb ) {
22- await runCommand ( cwd , 'prisma db push --force-reset' ) ;
23- }
24- await runCommand ( cwd , 'dev' ) ;
25- }
26-
2720function getPrismaClient ( cwd : string ) {
2821 return new ( requirePrismaClient ( cwd ) . PrismaClient ) ( {
2922 datasources : { sqlite : { url : dbUrl } } ,
@@ -71,8 +64,8 @@ async function setupInitialProjectWithoutMigrations() {
7164 'keystone.js' : basicKeystoneConfig ,
7265 } ) ;
7366 const recording = recordConsole ( ) ;
74- await setupAndStopDevServerForMigrations ( tmp ) ;
7567
68+ await runCommand ( tmp , 'dev' ) ;
7669 expect ( await introspectDb ( tmp , dbUrl ) ) . toEqual ( `datasource db {
7770 provider = "sqlite"
7871 url = "file:./app.db"
@@ -104,7 +97,7 @@ describe('useMigrations: false', () => {
10497 test ( 'logs correctly when things are already up to date' , async ( ) => {
10598 const tmp = await setupInitialProjectWithoutMigrations ( ) ;
10699 const recording = recordConsole ( ) ;
107- await setupAndStopDevServerForMigrations ( tmp ) ;
100+ await runCommand ( tmp , 'dev' ) ;
108101
109102 expect ( recording ( ) ) . toMatchInlineSnapshot ( `
110103 "✨ Starting Keystone
@@ -130,7 +123,7 @@ describe('useMigrations: false', () => {
130123 const recording = recordConsole ( {
131124 'Do you want to continue? Some data will be lost.' : true ,
132125 } ) ;
133- await setupAndStopDevServerForMigrations ( tmp ) ;
126+ await runCommand ( tmp , 'dev' ) ;
134127
135128 expect ( await introspectDb ( tmp , dbUrl ) ) . toMatchInlineSnapshot ( `
136129 "datasource db {
@@ -172,7 +165,7 @@ describe('useMigrations: false', () => {
172165 const recording = recordConsole ( {
173166 'Do you want to continue? Some data will be lost.' : false ,
174167 } ) ;
175- await expect ( setupAndStopDevServerForMigrations ( tmp ) ) . rejects . toEqual ( new ExitError ( 0 ) ) ;
168+ await expect ( runCommand ( tmp , 'dev' ) ) . rejects . toEqual ( new ExitError ( 0 ) ) ;
176169
177170 expect ( await introspectDb ( tmp , dbUrl ) ) . toMatchInlineSnapshot ( `
178171 "datasource db {
@@ -202,14 +195,16 @@ describe('useMigrations: false', () => {
202195 test ( 'prisma db push --force-reset works' , async ( ) => {
203196 const tmp = await setupInitialProjectWithoutMigrations ( ) ;
204197 {
205- const prismaClient = await getPrismaClient ( tmp ) ;
198+ const prismaClient = getPrismaClient ( tmp ) ;
206199 await prismaClient . todo . create ( { data : { title : 'something' } } ) ;
207200 await prismaClient . $disconnect ( ) ;
208201 }
209202 const recording = recordConsole ( ) ;
210- await setupAndStopDevServerForMigrations ( tmp , true ) ;
203+
204+ await runCommand ( tmp , 'prisma db push --force-reset' ) ;
205+ await runCommand ( tmp , 'dev' ) ;
211206 {
212- const prismaClient = await getPrismaClient ( tmp ) ;
207+ const prismaClient = getPrismaClient ( tmp ) ;
213208 expect ( await prismaClient . todo . findMany ( ) ) . toHaveLength ( 0 ) ;
214209 await prismaClient . $disconnect ( ) ;
215210 }
@@ -241,7 +236,7 @@ async function setupInitialProjectWithMigrations() {
241236 'Name of migration' : 'init' ,
242237 'Would you like to apply this migration?' : true ,
243238 } ) ;
244- await setupAndStopDevServerForMigrations ( tmp ) ;
239+ await runCommand ( tmp , 'dev' ) ;
245240
246241 expect ( await introspectDb ( tmp , dbUrl ) ) . toEqual ( `datasource db {
247242 provider = "sqlite"
@@ -301,7 +296,7 @@ describe('useMigrations: true', () => {
301296 'Name of migration' : 'add-is-complete' ,
302297 'Would you like to apply this migration?' : true ,
303298 } ) ;
304- await setupAndStopDevServerForMigrations ( tmp ) ;
299+ await runCommand ( tmp , 'dev' ) ;
305300
306301 expect ( await introspectDb ( tmp , dbUrl ) ) . toMatchInlineSnapshot ( `
307302 "datasource db {
@@ -368,7 +363,7 @@ describe('useMigrations: true', () => {
368363 'Name of migration' : 'remove all fields except id' ,
369364 'Would you like to apply this migration?' : true ,
370365 } ) ;
371- await setupAndStopDevServerForMigrations ( tmp ) ;
366+ await runCommand ( tmp , 'dev' ) ;
372367
373368 expect ( await introspectDb ( tmp , dbUrl ) ) . toMatchInlineSnapshot ( `
374369 "datasource db {
@@ -441,7 +436,7 @@ describe('useMigrations: true', () => {
441436 'Name of migration' : 'init' ,
442437 'Would you like to apply this migration?' : true ,
443438 } ) ;
444- await setupAndStopDevServerForMigrations ( tmp ) ;
439+ await runCommand ( tmp , 'dev' ) ;
445440
446441 expect ( await introspectDb ( tmp , dbUrl ) ) . toMatchInlineSnapshot ( `
447442 "datasource db {
@@ -516,7 +511,7 @@ describe('useMigrations: true', () => {
516511 'Do you want to continue? All data will be lost.' : false ,
517512 } ) ;
518513
519- await expect ( setupAndStopDevServerForMigrations ( tmp ) ) . rejects . toEqual ( new ExitError ( 0 ) ) ;
514+ await expect ( runCommand ( tmp , 'dev' ) ) . rejects . toEqual ( new ExitError ( 0 ) ) ;
520515
521516 expect ( await fs . readFile ( `${ prevCwd } /app.db` ) ) . toEqual ( dbBuffer ) ;
522517
@@ -555,7 +550,7 @@ describe('useMigrations: true', () => {
555550 'Name of migration' : 'add-is-complete' ,
556551 'Would you like to apply this migration?' : false ,
557552 } ) ;
558- await expect ( setupAndStopDevServerForMigrations ( tmp ) ) . rejects . toEqual ( new ExitError ( 0 ) ) ;
553+ await expect ( runCommand ( tmp , 'dev' ) ) . rejects . toEqual ( new ExitError ( 0 ) ) ;
559554
560555 expect ( await introspectDb ( tmp , dbUrl ) ) . toMatchInlineSnapshot ( `
561556 "datasource db {
@@ -614,7 +609,7 @@ describe('useMigrations: true', () => {
614609 'keystone.js' : basicWithMigrations ,
615610 } ) ;
616611 const recording = recordConsole ( ) ;
617- await setupAndStopDevServerForMigrations ( tmp ) ;
612+ await runCommand ( tmp , 'dev' ) ;
618613
619614 expect ( await introspectDb ( tmp , dbUrl ) ) . toMatchInlineSnapshot ( `
620615 "datasource db {
@@ -653,7 +648,7 @@ describe('useMigrations: true', () => {
653648 test ( 'logs correctly when no migrations need to be created or applied' , async ( ) => {
654649 const tmp = await setupInitialProjectWithMigrations ( ) ;
655650 const recording = recordConsole ( ) ;
656- await setupAndStopDevServerForMigrations ( tmp ) ;
651+ await runCommand ( tmp , 'dev' ) ;
657652
658653 expect ( recording ( ) ) . toMatchInlineSnapshot ( `
659654 "✨ Starting Keystone
0 commit comments