2019-03-06 19:19:33 +01:00
|
|
|
const path = require('path');
|
|
|
|
const { cleanTestApp, generateTestApp, startTestApp } = require('./helpers/testAppGenerator');
|
|
|
|
const execa = require('execa');
|
2019-03-12 11:41:38 +01:00
|
|
|
const waitOn = require('wait-on');
|
2019-03-06 19:19:33 +01:00
|
|
|
|
|
|
|
const appName = 'testApp';
|
|
|
|
|
|
|
|
const databases = {
|
2019-03-12 11:58:30 +01: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,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const main = async () => {
|
2019-04-02 09:50:19 +02:00
|
|
|
const database = process.argv.length > 2 ? process.argv.slice(2).join(' ') : databases.sqlite;
|
2019-03-06 19:19:33 +01:00
|
|
|
|
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-03-25 16:37:46 +01: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
|
|
|
};
|
|
|
|
|
|
|
|
main();
|