strapi/test/helpers/testAppGenerator.js

66 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-03-06 19:19:33 +01:00
const path = require('path');
const rimraf = require('rimraf');
const execa = require('execa');
2019-04-16 18:05:12 +02:00
const STRAPI_BIN = path.resolve(
__dirname,
'../../packages/strapi/bin/strapi.js'
);
2019-03-06 19:19:33 +01:00
/**
* Delete the testApp folder
* @param {string} appName - name of the app / folder where the app is located
*/
2019-03-06 19:19:33 +01:00
const cleanTestApp = appName => {
return new Promise((resolve, reject) => {
rimraf(path.resolve(appName), err => {
if (err) reject(err);
2019-03-06 19:19:33 +01:00
resolve();
});
});
};
/**
* Runs strapi generate new
* @param {Object} options - Options
* @param {string} options.appName - Name of the app that will be created (also the name of the folder)
* @param {database} options.database - Arguments to create the testApp with the provided database params
*/
const generateTestApp = async ({ appName, database }) => {
2019-04-23 11:24:23 +02:00
await execa.shell(`node ${STRAPI_BIN} new ${appName} ${database}`, {
2019-03-06 19:19:33 +01:00
stdio: 'inherit',
});
2019-04-16 18:05:12 +02:00
await execa.shell(
'yarn add strapi-plugin-graphql strapi-plugin-documentation',
{
cwd: path.resolve(appName),
}
);
await execa.shell(
`node scripts/copy-monorepo.js ${appName} --run-once --quiet`,
{
stdio: 'inherit',
}
);
2019-03-06 19:19:33 +01:00
};
/**
* Starts the test App in the appName folder
* @param {Object} options - Options
* @param {string} options.appName - Name of the app / folder in which run the start script
*/
2019-03-06 19:19:33 +01:00
const startTestApp = ({ appName }) => {
return execa.shell('strapi dev --no-build', {
stdio: 'inherit',
2019-03-06 19:19:33 +01:00
cwd: path.resolve(appName),
});
};
module.exports = {
cleanTestApp,
generateTestApp,
startTestApp,
};