Changed DB path for SQLite tests

no issue

- previously for SQLite tests we were pointing to a DB file within the
  content/data folder, which would be stored on the filesystem
- by pointing this file to be under `/tmp`, the file is stored in memory
  and should be a lot quicker to access
- this works great for me! - 2x faster test suite for SQLite
- however, Windows doesn't have a `/tmp` folder so we need to rewrite that
  part to replace with `os.tmpdir()`
This commit is contained in:
Daniel Lockyer 2021-02-19 07:53:42 +00:00
parent 71521d166e
commit db1c1ce21d
2 changed files with 11 additions and 1 deletions

View File

@ -3,7 +3,7 @@
"database": {
"client": "sqlite3",
"connection": {
"filename": "content/data/ghost-test.db"
"filename": "/tmp/ghost-test.db"
},
"useNullAsDefault": true,
"debug": false

View File

@ -1,4 +1,6 @@
const Nconf = require('nconf');
const _ = require('lodash');
const os = require('os');
const path = require('path');
const _debug = require('ghost-ignition').debug._base;
const debug = _debug('ghost:config');
@ -53,6 +55,14 @@ _private.loadNconf = function loadNconf(options) {
nconf.makePathsAbsolute(nconf.get('paths'), 'paths');
if (nconf.get('database:client') === 'sqlite3') {
nconf.makePathsAbsolute(nconf.get('database:connection'), 'database:connection');
// In the default SQLite test config we set the path to /tmp/ghost-test.db,
// but this won't work on Windows, so we need to replace the /tmp bit with
// the Windows temp folder
const filename = nconf.get('database:connection:filename');
if (_.isString(filename) && filename.match(/^\/tmp/)) {
nconf.set('database:connection:filename', filename.replace(/^\/tmp/, os.tmpdir()));
}
}
/**
* Check if the URL in config has a protocol