| 
									
										
										
										
											2020-10-27 11:27:17 +01:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-29 12:33:08 +02:00
										 |  |  | const path = require('path'); | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  | const execa = require('execa'); | 
					
						
							| 
									
										
										
										
											2019-04-18 16:01:31 +02:00
										 |  |  | const yargs = require('yargs'); | 
					
						
							| 
									
										
										
										
											2020-10-09 18:43:15 +02:00
										 |  |  | const { cleanTestApp, generateTestApp } = require('./helpers/test-app-generator'); | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const appName = 'testApp'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const databases = { | 
					
						
							| 
									
										
										
										
											2019-07-18 16:25:20 +02:00
										 |  |  |   postgres: { | 
					
						
							|  |  |  |     client: 'postgres', | 
					
						
							| 
									
										
										
										
											2021-06-29 16:27:35 +02:00
										 |  |  |     connection: { | 
					
						
							|  |  |  |       host: '127.0.0.1', | 
					
						
							|  |  |  |       port: 5432, | 
					
						
							|  |  |  |       database: 'strapi_test', | 
					
						
							|  |  |  |       username: 'strapi', | 
					
						
							|  |  |  |       password: 'strapi', | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2019-07-18 16:25:20 +02:00
										 |  |  |   }, | 
					
						
							|  |  |  |   mysql: { | 
					
						
							|  |  |  |     client: 'mysql', | 
					
						
							| 
									
										
										
										
											2021-06-29 16:27:35 +02:00
										 |  |  |     connection: { | 
					
						
							|  |  |  |       host: '127.0.0.1', | 
					
						
							|  |  |  |       port: 3306, | 
					
						
							|  |  |  |       database: 'strapi_test', | 
					
						
							|  |  |  |       username: 'strapi', | 
					
						
							|  |  |  |       password: 'strapi', | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2019-07-18 16:25:20 +02:00
										 |  |  |   }, | 
					
						
							|  |  |  |   sqlite: { | 
					
						
							|  |  |  |     client: 'sqlite', | 
					
						
							| 
									
										
										
										
											2021-06-29 16:27:35 +02:00
										 |  |  |     connecton: { | 
					
						
							|  |  |  |       filename: './tmp/data.db', | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2019-07-18 16:25:20 +02:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-25 17:22:41 +01:00
										 |  |  | const runAllTests = async args => { | 
					
						
							| 
									
										
										
										
											2021-07-08 18:15:32 +02:00
										 |  |  |   return execa('yarn', ['test:e2e', ...args], { | 
					
						
							| 
									
										
										
										
											2019-03-12 11:41:38 +01:00
										 |  |  |     stdio: 'inherit', | 
					
						
							| 
									
										
										
										
											2021-03-29 12:33:08 +02:00
										 |  |  |     cwd: path.resolve(__dirname, '..'), | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  |     env: { | 
					
						
							|  |  |  |       FORCE_COLOR: 1, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-05 09:10:00 +02:00
										 |  |  | const main = async (database, args) => { | 
					
						
							| 
									
										
										
										
											2019-03-12 11:41:38 +01:00
										 |  |  |   try { | 
					
						
							|  |  |  |     await cleanTestApp(appName); | 
					
						
							|  |  |  |     await generateTestApp({ appName, database }); | 
					
						
							| 
									
										
										
										
											2019-03-06 19:19:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 16:27:35 +02:00
										 |  |  |     await runAllTests(args).catch(()=> { | 
					
						
							| 
									
										
										
										
											2019-03-12 11:41:38 +01:00
										 |  |  |       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
										 |  |  |     process.exit(0); | 
					
						
							|  |  |  |   } catch (error) { | 
					
						
							| 
									
										
										
										
											2021-06-29 16:27:35 +02:00
										 |  |  |     console.error(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( | 
					
						
							| 
									
										
										
										
											2019-08-05 09:10:00 +02:00
										 |  |  |     '$0', | 
					
						
							| 
									
										
										
										
											2019-04-18 16:01:31 +02:00
										 |  |  |     'run end to end tests', | 
					
						
							|  |  |  |     yargs => { | 
					
						
							| 
									
										
										
										
											2019-08-05 09:10:00 +02:00
										 |  |  |       yargs.option('database', { | 
					
						
							|  |  |  |         alias: 'db', | 
					
						
							|  |  |  |         describe: 'choose a database', | 
					
						
							| 
									
										
										
										
											2019-04-18 16:01:31 +02:00
										 |  |  |         choices: Object.keys(databases), | 
					
						
							| 
									
										
										
										
											2019-08-05 09:10:00 +02:00
										 |  |  |         default: 'sqlite', | 
					
						
							| 
									
										
										
										
											2019-04-18 16:01:31 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2019-08-05 09:10:00 +02:00
										 |  |  |     argv => { | 
					
						
							|  |  |  |       const { database, _: args } = argv; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-29 12:33:08 +02:00
										 |  |  |       main(databases[database], args); | 
					
						
							| 
									
										
										
										
											2019-08-05 09:10:00 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-18 16:01:31 +02:00
										 |  |  |   ) | 
					
						
							|  |  |  |   .help().argv; |