strapi/test/e2e.js

69 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-03-06 19:19:33 +01:00
const fs = require('fs');
const path = require('path');
const { cleanTestApp, generateTestApp, startTestApp } = require('./helpers/testAppGenerator');
const shelljs = require('shelljs');
const execa = require('execa');
const appName = 'testApp';
const databases = {
mongo: `--dbclient=mongo --dbhost=127.0.0.1 --dbport=27017 --dbname=strapi-test-${new Date().getTime()} --dbusername= --dbpassword=`,
postgres:
'--dbclient=postgres --dbhost=127.0.0.1 --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi',
mysql:
'--dbclient=mysql --dbhost=127.0.0.1 --dbport=3306 --dbname=strapi-test --dbusername=root --dbpassword=root',
sqlite: '--dbclient=sqlite --dbfile=./tmp/data.db',
};
const { runCLI: jest } = require('jest-cli/build/cli');
const test = async () => {
const child = execa.shell('npm run test:e2e', {
stdio: 'pipe',
cwd: path.resolve(__dirname, '..'),
env: {
FORCE_COLOR: 1,
},
});
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
return child;
};
const main = async () => {
const database = process.argv.length > 2 ? process.argv.slice(2).join(' ') : databases.postgres;
await cleanTestApp(appName);
await generateTestApp({ appName, database });
const { testApp, ready, end } = startTestApp({ appName });
await ready;
// stop tests if the testApp stops
end
.then(() => {
process.stdout.write('testApp exited before the end', () => {
process.exit(1);
});
})
.catch(err => {
process.stdout.write('testApp exited before the end with error', () => {
process.exit(1);
});
});
2019-03-09 01:06:39 +01:00
await test().catch(() => {
process.stdout.write('Tests failed', () => {
process.exit(1);
});
});
2019-03-06 19:19:33 +01:00
process.kill(testApp.pid);
2019-03-09 01:06:39 +01:00
process.exit(0);
2019-03-06 19:19:33 +01:00
};
main();