2020-10-27 11:27:17 +01:00
|
|
|
'use strict';
|
|
|
|
|
2019-03-06 19:19:33 +01:00
|
|
|
const path = require('path');
|
|
|
|
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');
|
2020-10-27 11:27:17 +01:00
|
|
|
const { cleanTestApp, generateTestApp, startTestApp } = require('./helpers/testAppGenerator');
|
2019-03-06 19:19:33 +01:00
|
|
|
|
|
|
|
const appName = 'testApp';
|
|
|
|
|
|
|
|
const databases = {
|
2019-07-18 16:25:20 +02:00
|
|
|
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',
|
|
|
|
},
|
2019-03-06 19:19:33 +01:00
|
|
|
};
|
|
|
|
|
2019-08-05 09:10:00 +02:00
|
|
|
const test = async args => {
|
2020-01-29 15:30:53 +01:00
|
|
|
return execa('yarn', ['-s', 'test:e2e', ...args.split(' ')], {
|
2019-03-12 11:41:38 +01:00
|
|
|
stdio: 'inherit',
|
2019-03-06 19:19:33 +01:00
|
|
|
cwd: path.resolve(__dirname, '..'),
|
|
|
|
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 });
|
|
|
|
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-08-05 09:10:00 +02:00
|
|
|
await test(args).catch(() => {
|
2019-03-12 11:41:38 +01:00
|
|
|
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(
|
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;
|
|
|
|
|
|
|
|
main(databases[database], args.join(' '));
|
|
|
|
}
|
2019-04-18 16:01:31 +02:00
|
|
|
)
|
|
|
|
.help().argv;
|