strapi/test/helpers/test-app.js
Josh 116339ad86
refactor: admin build pipeline (#18539)
* chore(admin): refactor admin develop/build pipeline

chore: remove `webpackChunkName` comments

chore: reuse admin tsconfig where possible

chore: add .strapi to gitignore

chore(admin): pack-up

feat(admin): inject commands into strapi from admin for building

feat(admin): move watch command to admin

chore: keep backward compat API available

Update packages/core/admin/_internal/cli/index.ts

docs(admin): document the build & develop process and pipeline

test(admin): fix StrapiApp tests

chore: fix build

* Update skipped_tests.yml

* test(e2e): fix e2e setup

feat: add dependency installation

fix: mjs webpack resolution

* chore: fix server exports

* fix: typescript project type generation

* fix: development watch mode

* fix: connect to hot middleware – anywhere

* Update packages/core/admin/_internal/node/core/monorepo.ts

Co-authored-by: Marc Roig <marc12info@gmail.com>

* fix(admin): theme toggle type export

* chore: fixes

* chore: pr amends

Co-Authored-By: Ben Irvin <ben@innerdvations.com>

---------

Co-authored-by: Marc Roig <marc12info@gmail.com>
Co-authored-by: Ben Irvin <ben@innerdvations.com>
2023-10-30 11:36:16 +00:00

109 lines
2.9 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: {
react: '18.2.0',
'react-dom': '18.2.0',
'react-router-dom': '5.3.4',
'styled-components': '5.3.3',
},
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,
};