1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var assert = require('assert'),
|
9 | fs = require('fs'),
|
10 | path = require('path'),
|
11 | spawn = require('child_process').spawn,
|
12 | vows = require('vows'),
|
13 | helpers = require('./helpers'),
|
14 | nconf = require('../lib/nconf');
|
15 |
|
16 | var fixturesDir = path.join(__dirname, 'fixtures'),
|
17 | mergeFixtures = path.join(fixturesDir, 'merge'),
|
18 | files = [path.join(mergeFixtures, 'file1.json'), path.join(mergeFixtures, 'file2.json')],
|
19 | override = JSON.parse(fs.readFileSync(files[0]), 'utf8');
|
20 |
|
21 | vows.describe('nconf/provider').addBatch({
|
22 | "When using nconf": {
|
23 | "an instance of 'nconf.Provider'": {
|
24 | "calling the use() method with the same store type and different options": {
|
25 | topic: new nconf.Provider().use('file', { file: files[0] }),
|
26 | "should use a new instance of the store type": function (provider) {
|
27 | var old = provider.file;
|
28 |
|
29 | assert.equal(provider.file.file, files[0]);
|
30 | provider.use('file', { file: files[1] });
|
31 |
|
32 | assert.notStrictEqual(old, provider.file);
|
33 | assert.equal(provider.file.file, files[1]);
|
34 | }
|
35 | },
|
36 | "when 'argv' is true": helpers.assertSystemConf({
|
37 | script: path.join(fixturesDir, 'scripts', 'provider-argv.js'),
|
38 | argv: ['--something', 'foobar']
|
39 | }),
|
40 | "when 'env' is true": helpers.assertSystemConf({
|
41 | script: path.join(fixturesDir, 'scripts', 'provider-env.js'),
|
42 | env: { SOMETHING: 'foobar' }
|
43 | }),
|
44 | },
|
45 | "the default nconf provider": {
|
46 | "when 'argv' is set to true": helpers.assertSystemConf({
|
47 | script: path.join(fixturesDir, 'scripts', 'nconf-argv.js'),
|
48 | argv: ['--something', 'foobar'],
|
49 | env: { SOMETHING: true }
|
50 | }),
|
51 | "when 'env' is set to true": helpers.assertSystemConf({
|
52 | script: path.join(fixturesDir, 'scripts', 'nconf-env.js'),
|
53 | env: { SOMETHING: 'foobar' }
|
54 | }),
|
55 | "when 'argv' is set to true and process.argv is modified": helpers.assertSystemConf({
|
56 | script: path.join(fixturesDir, 'scripts', 'nconf-change-argv.js'),
|
57 | argv: ['--something', 'badValue', 'evenWorse', 'OHNOEZ', 'foobar']
|
58 | })
|
59 | }
|
60 | }
|
61 | }).addBatch({
|
62 | "When using nconf": {
|
63 | "an instance of 'nconf.Provider'": {
|
64 | "the merge() method": {
|
65 | topic: new nconf.Provider().use('file', { file: files[1] }),
|
66 | "should have the result merged in": function (provider) {
|
67 | provider.load();
|
68 | provider.merge(override);
|
69 | helpers.assertMerged(null, provider.file.store);
|
70 | }
|
71 | },
|
72 | "when sources are passed in": {
|
73 | topic: new nconf.Provider({
|
74 | sources: {
|
75 | user: {
|
76 | type: 'file',
|
77 | file: files[0]
|
78 | },
|
79 | global: {
|
80 | type: 'file',
|
81 | file: files[1]
|
82 | }
|
83 | }
|
84 | }),
|
85 | "should have the result merged in": function (provider) {
|
86 | helpers.assertMerged(null, provider.load());
|
87 | }
|
88 | }
|
89 | }
|
90 | }
|
91 | }).export(module);
|
92 |
|