b8686aeff0
* set up jest dependencies * add parser option to eslint to support es6 * migrate first test to jest * migrate the argv test to shpec * convert the env and literal store tests * convert the file-store tests * convert the memory-store tests * convert the hierarchy tests * convert the provider-save test * convert the complete test * convert the provider test * convert the conf test * tweak a test that was no longer working (context changed) * replace in place the helpers file * remove vows dependency * update the test invocation to rely on jest * update the argv test to be able to use the jest --verbose option * Some tweaks to the test to have them working * Update node version tested (+10 +12 -9) * Replace const by var until we drop 0.10/0.12/4 node * Replace let by var until we drop 0.10/0.12/4 node
66 lines
1.6 KiB
JavaScript
66 lines
1.6 KiB
JavaScript
/*
|
|
* helpers.js: Test helpers for nconf.
|
|
*
|
|
* (C) 2011, Charlie Robbins and the Contributors.
|
|
*
|
|
*/
|
|
|
|
var spawn = require('child_process').spawn;
|
|
var fs = require('fs');
|
|
var path = require('path');
|
|
var nconf = require('../lib/nconf');
|
|
|
|
exports.assertMerged = function (err, merged) {
|
|
merged = merged instanceof nconf.Provider
|
|
? merged.store.store
|
|
: merged;
|
|
|
|
expect()
|
|
expect(err).toBeNull();
|
|
expect(typeof merged).toBe('object');
|
|
expect(merged.apples).toBeTruthy();
|
|
expect(merged.bananas).toBeTruthy();
|
|
expect(typeof merged.candy).toBe('object');
|
|
expect(merged.candy.something1).toBeTruthy();
|
|
expect(merged.candy.something2).toBeTruthy();
|
|
expect(merged.candy.something3).toBeTruthy();
|
|
expect(merged.candy.something4).toBeTruthy();
|
|
expect(merged.dates).toBeTruthy();
|
|
expect(merged.elderberries).toBeTruthy();
|
|
};
|
|
|
|
//FIXME TODO
|
|
exports.assertSystemConf = function (options) {
|
|
return done => {
|
|
var env = null;
|
|
|
|
if (options.env) {
|
|
env = {}
|
|
Object.keys(process.env).forEach(function (key) {
|
|
env[key] = process.env[key];
|
|
});
|
|
|
|
Object.keys(options.env).forEach(function (key) {
|
|
env[key] = options.env[key];
|
|
});
|
|
}
|
|
|
|
var child = spawn('node', [options.script].concat(options.argv), {env: env});
|
|
child.stdout.once('data', data => {
|
|
expect(data.toString()).toEqual('foobar');
|
|
done();
|
|
});
|
|
}
|
|
}
|
|
|
|
// copy a file
|
|
exports.cp = function (from, to, callback) {
|
|
fs.readFile(from, function (err, data) {
|
|
if (err) return callback(err);
|
|
fs.writeFile(to, data, callback);
|
|
});
|
|
};
|
|
|
|
exports.fixture = function (file) {
|
|
return path.join(__dirname, 'fixtures', file);
|
|
};
|