mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
Fixed random test failure due to asynchronous directory creation
- we keep seeing random failures that complain about a directory already
existing when trying to create it
- the error arises from the `fs.copySync` in this `prepareContentFolder`
function, because it tries to create the folder if it doesn't exist
- it turns out we're using the asynchronous `fs.ensureDir` without an
await just before, so it doesn't block on creating the folder
- there's a veeeery small window where the code within `copySync` thinks
the folder doesn't exist, `ensureDir` creates the folder, and
then `copySync` tries to create the folder => 💥
- it looks like we're already `await`-ing `prepareContentFolder`, so we
can just switch all the calls to the Promise-based ones and await them
- the other `prepareContentFolder` uses the sync versions of the
functions, but we can fix that in the future: 7b7767d483/ghost/core/test/utils/e2e-utils.js (L73-L79)
This commit is contained in:
parent
7b7767d483
commit
044b342de3
@ -78,20 +78,20 @@ const startGhost = async (options = {}) => {
|
||||
* Slightly simplified copy-paste from e2e-utils.
|
||||
* @param {Object} options
|
||||
*/
|
||||
const prepareContentFolder = ({contentFolder, redirectsFile = true, routesFile = true}) => {
|
||||
const prepareContentFolder = async ({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'));
|
||||
await fs.ensureDir(contentFolderForTests);
|
||||
await fs.ensureDir(path.join(contentFolderForTests, 'data'));
|
||||
await fs.ensureDir(path.join(contentFolderForTests, 'themes'));
|
||||
await fs.ensureDir(path.join(contentFolderForTests, 'images'));
|
||||
await fs.ensureDir(path.join(contentFolderForTests, 'logs'));
|
||||
await fs.ensureDir(path.join(contentFolderForTests, 'adapters'));
|
||||
await 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(
|
||||
await fs.copy(
|
||||
path.join(__dirname, 'fixtures', 'themes'),
|
||||
path.join(contentFolderForTests, 'themes')
|
||||
);
|
||||
@ -101,7 +101,7 @@ const prepareContentFolder = ({contentFolder, redirectsFile = true, routesFile =
|
||||
}
|
||||
|
||||
if (routesFile) {
|
||||
fs.copySync(
|
||||
await fs.copy(
|
||||
path.join(__dirname, 'fixtures', 'settings', 'routes.yaml'),
|
||||
path.join(contentFolderForTests, 'settings', 'routes.yaml')
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user