const getSourceFilePaths = () => { return new Promise((resolve, reject) => { glob(SOURCE_PATTERN, (error, files) => { if (error) { reject(error); return; } resolve(files.map(filePath => path.join(process.cwd(), filePath))); }); }); }
loadDatabase(dbName) { const db = new Datastore({ autoload: true, filename: path.join(config.dbPath, this.user._id, 'history', `${dbName}.db`), }); this.ready = true; return db; }
function getDb(user) { const userId = user._id; if (databases.has(userId)) { return databases.get(userId); } const database = new Datastore({ autoload: true, filename: path.join(config.dbPath, userId, 'settings', 'settings.db'), }); databases.set(userId, database); return database; }
_(files) .flatMap(file => traverseUp(path.resolve(startFrom, file))) .sortBy().reverse() .filter(file => fs.existsSync(file) && path.isAbsolute(file)) .thru(files => _.isEmpty(files) ? [] : [_.first(files)]) .flatMap(dirFile => _.map(files, file => path.join(path.dirname(dirFile), file))) .filter(file => fs.existsSync(file)) .value()
constructor(prefix = 'LANDO', logLevel = 'warn', userConfRoot = path.join(os.homedir(), '.lando')) { this.prefix = prefix; this.logLevel = logLevel; this.userConfRoot = userConfRoot; }
test("utils.find", co(function* (t) { const file = "taskfile.js" const full = join(fixtures, file) const out1 = yield $.find(file, fixtures) t.true(out1.length && typeof out1 === "string", "if found returns a string") t.equal(out1, full, `via directory path finds the correct taskfile`) const out2 = yield $.find(full) t.equal(out2, full, `via file path finds the correct taskfile`) const out4 = yield $.find(file, "/fakedir123") t.equal(out4, null, "if not found returns `null`") t.end() }))
test('final works without prior logging', async ({ isNot }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'final-no-log-before.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(strip(actual).match(/WARN\s+: pino.final with prettyPrint does not support flushing/), null) isNot(strip(actual).match(/INFO\s+\(123456 on abcdefghijklmnopqr\): beforeExit/), null) })
// Copy _.forEach(buildCopy, item => { _.forEach(item.src, dir => { const dest = (item.direct) ? item.dest : path.join(item.dest, path.basename(dir)); fs.copySync(dir, dest, {overwrite: true}); log.info('Copied source from %s to %s', dir, dest); }); });
constructor({log = new Log(), cacheDir = path.join(os.tmpdir(), '.cache')} = {}) { // Get the nodecache opts super(); // Set some things this.log = log; this.cacheDir = cacheDir; // Ensure the cache dir exists mkdirp.sync(this.cacheDir); }
// Helper to get init source config const getInitSourceConfig = dirs => _(dirs) .filter(dir => fs.existsSync(dir)) .flatMap(dir => glob.sync(path.join(dir, '*.js'))) .map(file => require(file)) .flatMap(source => source.sources) .value()
test('with custom timestamp', async ({ is }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'custom-time.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') is(strip(actual).slice(0, 6), '[test]') })
loadDatabase() { const db = new Datastore({ autoload: true, filename: path.join(config.dbPath, 'users.db'), }); db.ensureIndex({fieldName: 'username', unique: true}); this.ready = true; return db; }
test('sync false logs everything when calling flushSync', async ({ isNot }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'syncfalse-flush-exit.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(actual.match(/hello/), null) isNot(actual.match(/world/), null) })