mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
34b0196c0f
refs https://github.com/TryGhost/Toolbox/issues/135 - Allows to turn off overwriting urls/resources JSON file caches on testing environment. This is needed to have predictable state when running multiple test suites that stop the Ghost process and try to persiste URL cache.
27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
const config = require('../../../shared/config');
|
|
const LocalFileCache = require('./LocalFileCache');
|
|
const UrlService = require('./UrlService');
|
|
|
|
// NOTE: instead of a path we could give UrlService a "data-resolver" of some sort
|
|
// so it doesn't have to contain the logic to read data at all. This would be
|
|
// a possible improvement in the future
|
|
let writeDisabled = false;
|
|
let storagePath = config.getContentPath('data');
|
|
|
|
// TODO: remove this hack in favor of loading from the content path when it's possible to do so
|
|
// by mocking content folders in pre-boot phase
|
|
if (process.env.NODE_ENV.match(/^testing/)){
|
|
storagePath = config.get('paths').urlCache;
|
|
|
|
// NOTE: prevents test suites from overwriting cache fixtures.
|
|
// A better solution would be injecting a different implementation of the
|
|
// cache based on the environment, this approach should do the trick for now
|
|
writeDisabled = true;
|
|
}
|
|
|
|
const cache = new LocalFileCache({storagePath, writeDisabled});
|
|
const urlService = new UrlService({cache});
|
|
|
|
// Singleton
|
|
module.exports = urlService;
|