@@ -10,7 +10,8 @@ import drizzle from '../../drizzle/index.ts';
1010import { pageServer , pageComp } from './fixtures.ts' ;
1111
1212// only linux is supported for running docker containers in github runners
13- const noDocker = process . env . CI && process . platform !== 'linux' ;
13+ const MUST_HAVE_DOCKER = process . env . CI && process . platform === 'linux' ;
14+ let dockerInstalled = false ;
1415
1516const { test, testCases, prepareServer } = setupTest (
1617 { drizzle } ,
@@ -38,44 +39,67 @@ const { test, testCases, prepareServer } = setupTest(
3839) ;
3940
4041beforeAll ( ( ) => {
41- if ( noDocker ) return ;
42+ if ( ! MUST_HAVE_DOCKER ) return ;
4243 const cwd = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
43- execSync ( 'docker compose up --detach' , { cwd, stdio : 'pipe' } ) ;
44+
45+ try {
46+ execSync ( 'docker --version' , { cwd, stdio : 'pipe' } ) ;
47+ dockerInstalled = true ;
48+ } catch {
49+ dockerInstalled = false ;
50+ }
51+
52+ if ( dockerInstalled ) execSync ( 'docker compose up --detach' , { cwd, stdio : 'pipe' } ) ;
4453
4554 // cleans up the containers on interrupts (ctrl+c)
4655 process . addListener ( 'SIGINT' , ( ) => {
47- execSync ( 'docker compose down --volumes' , { cwd, stdio : 'pipe' } ) ;
56+ if ( dockerInstalled ) execSync ( 'docker compose down --volumes' , { cwd, stdio : 'pipe' } ) ;
4857 } ) ;
4958
5059 return ( ) => {
51- execSync ( 'docker compose down --volumes' , { cwd, stdio : 'pipe' } ) ;
60+ if ( dockerInstalled ) execSync ( 'docker compose down --volumes' , { cwd, stdio : 'pipe' } ) ;
5261 } ;
5362} ) ;
5463
5564test . concurrent . for ( testCases ) (
5665 'drizzle $kind.type $variant' ,
5766 async ( testCase , { page, ...ctx } ) => {
58- if ( testCase . kind . options . drizzle . docker && noDocker ) ctx . skip ( ) ;
5967 const cwd = ctx . cwd ( testCase ) ;
6068
61- const ts = testCase . variant === 'kit- ts';
69+ const ts = testCase . variant . endsWith ( ' ts') ;
6270 const drizzleConfig = path . resolve ( cwd , `drizzle.config.${ ts ? 'ts' : 'js' } ` ) ;
63- const content = fs . readFileSync ( drizzleConfig , 'utf8' ) . replace ( / s t r i c t : t r u e [ , \s ] / , '' ) ;
64- fs . writeFileSync ( drizzleConfig , content , 'utf8' ) ;
71+ const content = fs . readFileSync ( drizzleConfig , 'utf8' ) ;
72+
73+ expect ( content . length , 'drizzle config should have content' ) . toBeGreaterThan ( 0 ) ;
74+
75+ if ( MUST_HAVE_DOCKER ) expect ( dockerInstalled , 'docker must be installed' ) . toBe ( true ) ;
76+
77+ if ( testCase . kind . options . drizzle . docker ) {
78+ const dockerCompose = path . resolve ( cwd , 'compose.yaml' ) ;
79+ expect ( fs . existsSync ( dockerCompose ) , 'file should exist' ) . toBe ( true ) ;
80+ }
81+
82+ const db_can_be_tested =
83+ ! testCase . kind . options . drizzle . docker ||
84+ ( testCase . kind . options . drizzle . docker && dockerInstalled ) ;
85+
86+ if ( db_can_be_tested ) {
87+ fs . writeFileSync ( drizzleConfig , content . replace ( / s t r i c t : t r u e [ , \s ] / , '' ) , 'utf8' ) ;
6588
66- const routes = path . resolve ( cwd , 'src' , 'routes' ) ;
67- const pagePath = path . resolve ( routes , '+page.svelte' ) ;
68- fs . writeFileSync ( pagePath , pageComp , 'utf8' ) ;
89+ const routes = path . resolve ( cwd , 'src' , 'routes' ) ;
90+ const pagePath = path . resolve ( routes , '+page.svelte' ) ;
91+ fs . writeFileSync ( pagePath , pageComp , 'utf8' ) ;
6992
70- const pageServerPath = path . resolve ( routes , `+page.server.${ ts ? 'ts' : 'js' } ` ) ;
71- fs . writeFileSync ( pageServerPath , pageServer , 'utf8' ) ;
93+ const pageServerPath = path . resolve ( routes , `+page.server.${ ts ? 'ts' : 'js' } ` ) ;
94+ fs . writeFileSync ( pageServerPath , pageServer , 'utf8' ) ;
7295
73- execSync ( 'npm run db:push' , { cwd, stdio : 'pipe' } ) ;
96+ execSync ( 'npm run db:push' , { cwd, stdio : 'pipe' } ) ;
7497
75- const { close } = await prepareServer ( { cwd, page } ) ;
76- // kill server process when we're done
77- ctx . onTestFinished ( async ( ) => await close ( ) ) ;
98+ const { close } = await prepareServer ( { cwd, page } ) ;
99+ // kill server process when we're done
100+ ctx . onTestFinished ( async ( ) => await close ( ) ) ;
78101
79- expect ( page . locator ( '[data-testid]' ) ) . toBeTruthy ( ) ;
102+ expect ( page . locator ( '[data-testid]' ) ) . toBeTruthy ( ) ;
103+ }
80104 }
81105) ;
0 commit comments