| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  | const path = require('path'); | 
					
						
							| 
									
										
										
										
											2019-04-18 16:01:31 +02:00
										 |  |  | const { | 
					
						
							|  |  |  |   cleanTestApp, | 
					
						
							|  |  |  |   generateTestApp, | 
					
						
							|  |  |  |   startTestApp, | 
					
						
							|  |  |  | } = require('./helpers/testAppGenerator'); | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  | const execa = require('execa'); | 
					
						
							| 
									
										
										
										
											2019-03-12 11:41:38 +01:00
										 |  |  | const waitOn = require('wait-on'); | 
					
						
							| 
									
										
										
										
											2019-04-18 16:01:31 +02:00
										 |  |  | const yargs = require('yargs'); | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const appName = 'testApp'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const databases = { | 
					
						
							| 
									
										
										
										
											2019-05-07 16:40:10 +02:00
										 |  |  |   mongo: | 
					
						
							|  |  |  |     '--dbclient=mongo --dbhost=127.0.0.1 --dbport=27017 --dbname=strapi_test --dbusername=root --dbpassword=strapi', | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  |   postgres: | 
					
						
							|  |  |  |     '--dbclient=postgres --dbhost=127.0.0.1 --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi', | 
					
						
							|  |  |  |   mysql: | 
					
						
							| 
									
										
										
										
											2019-03-12 11:41:38 +01:00
										 |  |  |     '--dbclient=mysql --dbhost=127.0.0.1 --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi', | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  |   sqlite: '--dbclient=sqlite --dbfile=./tmp/data.db', | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const test = async () => { | 
					
						
							| 
									
										
										
										
											2019-03-12 11:41:38 +01:00
										 |  |  |   return execa.shell('npm run -s test:e2e', { | 
					
						
							|  |  |  |     stdio: 'inherit', | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  |     cwd: path.resolve(__dirname, '..'), | 
					
						
							|  |  |  |     env: { | 
					
						
							| 
									
										
										
										
											2019-03-12 11:41:38 +01:00
										 |  |  |       CI: true, | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  |       FORCE_COLOR: 1, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-18 16:01:31 +02:00
										 |  |  | const main = async database => { | 
					
						
							| 
									
										
										
										
											2019-03-12 11:41:38 +01:00
										 |  |  |   try { | 
					
						
							|  |  |  |     await cleanTestApp(appName); | 
					
						
							|  |  |  |     await generateTestApp({ appName, database }); | 
					
						
							|  |  |  |     const testAppProcess = startTestApp({ appName }); | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-12 11:41:38 +01:00
										 |  |  |     await waitOn({ resources: ['http://localhost:1337'] }); | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-12 11:41:38 +01:00
										 |  |  |     await test().catch(() => { | 
					
						
							|  |  |  |       testAppProcess.kill(); | 
					
						
							|  |  |  |       process.stdout.write('Tests failed\n', () => { | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  |         process.exit(1); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-12 11:41:38 +01:00
										 |  |  |     testAppProcess.kill(); | 
					
						
							|  |  |  |     process.exit(0); | 
					
						
							|  |  |  |   } catch (error) { | 
					
						
							| 
									
										
										
										
											2019-04-18 16:01:31 +02:00
										 |  |  |     console.log(error); | 
					
						
							| 
									
										
										
										
											2019-03-12 11:41:38 +01:00
										 |  |  |     process.stdout.write('Tests failed\n', () => { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       process.exit(1); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-03-12 11:41:38 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-18 16:01:31 +02:00
										 |  |  | yargs | 
					
						
							|  |  |  |   .command( | 
					
						
							|  |  |  |     '$0 [databaseName]', | 
					
						
							|  |  |  |     'run end to end tests', | 
					
						
							|  |  |  |     yargs => { | 
					
						
							|  |  |  |       yargs.positional('databaseName', { | 
					
						
							|  |  |  |         default: 'sqlite', | 
					
						
							|  |  |  |         choices: Object.keys(databases), | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     ({ databaseName }) => main(databases[databaseName]) | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  |   .help().argv; |