mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-31 18:08:11 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			99 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			99 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| const path = require('path');
 | |
| const {
 | |
|   cleanTestApp,
 | |
|   generateTestApp,
 | |
|   startTestApp,
 | |
| } = require('./helpers/testAppGenerator');
 | |
| const execa = require('execa');
 | |
| const waitOn = require('wait-on');
 | |
| const yargs = require('yargs');
 | |
| 
 | |
| const appName = 'testApp';
 | |
| 
 | |
| const databases = {
 | |
|   mongo: {
 | |
|     client: 'mongo',
 | |
|     host: '127.0.0.1',
 | |
|     port: 27017,
 | |
|     database: 'strapi_test',
 | |
|     username: 'root',
 | |
|     password: 'strapi',
 | |
|   },
 | |
|   postgres: {
 | |
|     client: 'postgres',
 | |
|     host: '127.0.0.1',
 | |
|     port: 5432,
 | |
|     database: 'strapi_test',
 | |
|     username: 'strapi',
 | |
|     password: 'strapi',
 | |
|   },
 | |
|   mysql: {
 | |
|     client: 'mysql',
 | |
|     host: '127.0.0.1',
 | |
|     port: 3306,
 | |
|     database: 'strapi_test',
 | |
|     username: 'strapi',
 | |
|     password: 'strapi',
 | |
|   },
 | |
|   sqlite: {
 | |
|     client: 'sqlite',
 | |
|     filename: './tmp/data.db',
 | |
|   },
 | |
| };
 | |
| 
 | |
| const test = async args => {
 | |
|   return execa.shell(`yarn -s test:e2e ${args}`, {
 | |
|     stdio: 'inherit',
 | |
|     cwd: path.resolve(__dirname, '..'),
 | |
|     env: {
 | |
|       CI: true,
 | |
|       FORCE_COLOR: 1,
 | |
|     },
 | |
|   });
 | |
| };
 | |
| 
 | |
| const main = async (database, args) => {
 | |
|   try {
 | |
|     await cleanTestApp(appName);
 | |
|     await generateTestApp({ appName, database });
 | |
|     const testAppProcess = startTestApp({ appName });
 | |
| 
 | |
|     await waitOn({ resources: ['http://localhost:1337'] });
 | |
| 
 | |
|     await test(args).catch(() => {
 | |
|       testAppProcess.kill();
 | |
|       process.stdout.write('Tests failed\n', () => {
 | |
|         process.exit(1);
 | |
|       });
 | |
|     });
 | |
| 
 | |
|     testAppProcess.kill();
 | |
|     process.exit(0);
 | |
|   } catch (error) {
 | |
|     console.log(error);
 | |
|     process.stdout.write('Tests failed\n', () => {
 | |
|       process.exit(1);
 | |
|     });
 | |
|   }
 | |
| };
 | |
| 
 | |
| yargs
 | |
|   .command(
 | |
|     '$0',
 | |
|     'run end to end tests',
 | |
|     yargs => {
 | |
|       yargs.option('database', {
 | |
|         alias: 'db',
 | |
|         describe: 'choose a database',
 | |
|         choices: Object.keys(databases),
 | |
|         default: 'sqlite',
 | |
|       });
 | |
|     },
 | |
|     argv => {
 | |
|       const { database, _: args } = argv;
 | |
| 
 | |
|       main(databases[database], args.join(' '));
 | |
|     }
 | |
|   )
 | |
|   .help().argv;
 | 
