/* * Create a data source */ create(source, data = {}, sort = []) { let database = this.read(source); database.push(_.merge({}, data, {id: hasher(data)})); // Sort if we have to if (!_.isEmpty(sort)) database = _.orderBy(database, ...sort); // Dump results this.yaml.dump(path.resolve(this.base, `${source}.yml`), _.uniqBy(database, 'id')); return this.read(source, {id: hasher(data)}); }
_(urls) .map(url => exports.parseUrl(url)) .map(parsedUrl => _.merge({}, parsedUrl, {id: hasher(parsedUrl)})) .uniqBy('id') .value()
it('should mirror process.env', () => { const env = config.defaults().env; expect(hasher(env)).to.equal(hasher(process.env)); process.env.NEW = 'things'; expect(hasher(env)).to.equal(hasher(process.env)); delete process.env.NEW; expect(hasher(env)).to.equal(hasher(process.env)); env.NEW2 = 'morethings'; expect(hasher(env)).to.equal(hasher(process.env)); delete env.NEW2; expect(hasher(env)).to.equal(hasher(process.env)); });
supreme: 'taylor', }; const landoMerge = hasher(config.merge(bands1, bands2)); const lodashMerge = hasher(_.merge(bands1, bands2)); expect(landoMerge).to.equal(lodashMerge); }); const bands = config.merge(theworst, thebest); expect(bands.favs).to.have.length(3); expect(hasher(bands.favs)).to.equal(hasher(['nickelback', 'abba', 'britney'])); }); const ourfavs = config.merge(myfavs, yourfavs); expect(ourfavs.favs).to.have.length(3); expect(hasher(ourfavs.favs)).to.equal(hasher(['nickelback', 'abba', 'britney'])); }); });
describe('#loadFiles', () => { it('should return an empty object if no files are specified', () => { const fileConfig = config.loadFiles(); expect(fileConfig).to.be.empty; }); it('should return data only from files that exist', () => { filesystem({'/tmp/config1.yml': 'obiwan: kenobi'}); const fileConfig = config.loadFiles(['/tmp/config1.yml', '/tmp/doesnotexist.yml']); expect(hasher(fileConfig)).to.equal(hasher({obiwan: 'kenobi'})); filesystem.restore(); }); it('should give priority to the last file loaded', () => { filesystem({ '/tmp/config1.yml': 'scoundrel: lando', '/tmp/config2.yml': 'scoundrel: solo', }); const fileConfig = config.loadFiles(['/tmp/config1.yml', '/tmp/config2.yml']); expect(hasher(fileConfig)).to.equal(hasher({scoundrel: 'solo'})); filesystem.restore(); }); });
const data = yaml.load('/tmp/config1.yml'); expect(data).to.be.an('Object'); expect(hasher(data)).to.equal(hasher({obiwan: 'kenobi', qui: ['gon', 'jinn']})); filesystem.restore(); }); yaml.dump('/tmp/test/file.yml', data); expect(fs.existsSync('/tmp/test/file.yml')).to.equal(true); expect(hasher(yaml.load('/tmp/test/file.yml'))).to.equal(hasher(data)); });