0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Added content folder initialization to e2e-framework

refs https://github.com/TryGhost/Toolbox/issues/129

- Adds content folder creation based on fixtures for e2e tests using the e2e framework
- Mostly a copy-paste for now from existing e2e utils with some simplifications, so we can "complicate things" later only if needed
This commit is contained in:
Naz 2021-12-09 12:48:01 +04:00 committed by naz
parent 4fa9f07d66
commit eb35c64f19

View file

@ -14,13 +14,29 @@
// The output state checker is responsible for checking the response from the app after performing a request.
const _ = require('lodash');
const {sequence} = require('@tryghost/promise');
const fs = require('fs-extra');
const path = require('path');
const os = require('os');
const uuid = require('uuid');
const fixtures = require('./fixture-utils');
const redirectsUtils = require('./redirects');
const configUtils = require('./configUtils');
const boot = require('../../core/boot');
const TestAgent = require('./test-agent');
const db = require('./db-utils');
const startGhost = async () => {
/**
* We never use the root content folder for testing!
* We use a tmp folder.
*/
const contentFolder = path.join(os.tmpdir(), uuid.v4(), 'ghost-test');
await prepareContentFolder({contentFolder});
// NOTE: need to pass this config to the server instance
configUtils.set('paths:contentPath', contentFolder);
const defaults = {
backend: true,
frontend: false,
@ -30,6 +46,40 @@ const startGhost = async () => {
return boot(defaults);
};
/**
* Slightly simplified copy-paste from e2e-utils.
* @param {Object} options
*/
const prepareContentFolder = ({contentFolder, redirectsFile = true, routesFile = true}) => {
const contentFolderForTests = contentFolder;
fs.ensureDir(contentFolderForTests);
fs.ensureDir(path.join(contentFolderForTests, 'data'));
fs.ensureDir(path.join(contentFolderForTests, 'themes'));
fs.ensureDir(path.join(contentFolderForTests, 'images'));
fs.ensureDir(path.join(contentFolderForTests, 'logs'));
fs.ensureDir(path.join(contentFolderForTests, 'adapters'));
fs.ensureDir(path.join(contentFolderForTests, 'settings'));
// Copy all themes into the new test content folder. Default active theme is always casper.
// If you want to use a different theme, you have to set the active theme (e.g. stub)
fs.copySync(
path.join(__dirname, 'fixtures', 'themes'),
path.join(contentFolderForTests, 'themes')
);
if (redirectsFile) {
redirectsUtils.setupFile(contentFolderForTests, '.yaml');
}
if (routesFile) {
fs.copySync(
path.join(__dirname, 'fixtures', 'settings', 'routes.yaml'),
path.join(contentFolderForTests, 'settings', 'routes.yaml')
);
}
};
/**
* Database state builder. By default inserts an owner user into the database.
* @param {...any} [options]