strapi/test/helpers/test-app.js
Maxime Castres 285944d4bb
feat(cloud): add strapi cloud plugin to CMS for marketing (#18209)
* Add: Strapi Plugin Cloud

* Update: first review changes

* Update: remove versioning check + add eslint

* Update: register the plugin only on development

* Update: add cloud plugin by default in package.json

* Update: make the plugin installed by default

* Update: convert plugin in typescript

* Update: package.json file

* chore: setup the project like color-picker

* chore: fix TS issue

* Add: fix utm params

* Fix: lint issue with Link compo

* chore: fix issue with strapi.name in pkg.json

* chore: fix build scripts

---------

Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>
2023-10-25 15:13:53 +01:00

104 lines
2.8 KiB
JavaScript

'use strict';
const path = require('path');
const fs = require('fs');
const rimraf = require('rimraf');
const execa = require('execa');
const generateNew = require('../../packages/generators/app/dist/generate-new');
/**
* Deletes a test app
* @param {string} appPath - name of the app / folder where the app is located
*/
const cleanTestApp = (appPath) => {
return new Promise((resolve, reject) => {
rimraf(path.resolve(appPath), (err) => {
if (err) reject(err);
resolve();
});
});
};
/**
* Runs strapi generate new
* @param {Object} options - Options
* @param {string} options.appPath - 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 ({ appPath, database, template, link = false }) => {
const scope = {
database,
rootPath: path.resolve(appPath),
name: path.basename(appPath),
// disable quickstart run app after creation
runQuickstartApp: false,
// use package version as strapiVersion (all packages have the same version);
strapiVersion: require(path.resolve(__dirname, '../../packages/core/strapi/package.json'))
.version,
debug: false,
quick: false,
uuid: undefined,
deviceId: null,
// use yarn if available and --use-npm isn't true
useYarn: true,
installDependencies: false,
strapiDependencies: [
'@strapi/strapi',
'@strapi/plugin-users-permissions',
'@strapi/plugin-graphql',
'@strapi/plugin-documentation',
'@strapi/plugin-i18n',
'@strapi/plugin-cloud',
],
additionalsDependencies: {},
template: template ? path.resolve(template) : template,
};
await generateNew(scope);
if (link) {
await linkPackages(appPath);
}
};
const linkPackages = async (appPath) => {
const rootPath = path.resolve(__dirname, '../..');
fs.writeFileSync(path.join(appPath, 'yarn.lock'), '');
await execa('yarn', ['link', '-A', rootPath], {
cwd: appPath,
stdio: 'inherit',
});
};
/**
* Runs a test app
* @param {string} appPath - name of the app / folder where the app is located
*/
const runTestApp = async (appPath) => {
const cmdContext = {
stdio: 'inherit',
cwd: path.resolve(__dirname, '../..', appPath),
env: {
// if STRAPI_LICENSE is in the env the test will run in ee automatically
STRAPI_DISABLE_EE: !process.env.STRAPI_LICENSE,
FORCE_COLOR: 1,
JWT_SECRET: 'aSecret',
},
};
try {
await execa('yarn', ['strapi', 'build'], cmdContext);
await execa('yarn', ['strapi', 'start'], cmdContext);
process.exit(0);
} catch (error) {
console.error(error);
process.exit(1);
}
};
module.exports = {
cleanTestApp,
generateTestApp,
runTestApp,
};