UNPKG

3.53 kBJavaScriptView Raw
1// Load modules
2
3var ChildProcess = require('child_process');
4var Fs = require('fs');
5var Lab = require('lab');
6var Path = require('path');
7
8
9// Declare internals
10
11var internals = {};
12
13
14// Test shortcuts
15
16var lab = exports.lab = Lab.script();
17var expect = Lab.expect;
18var before = lab.before;
19var after = lab.after;
20var describe = lab.experiment;
21var it = lab.test;
22
23describe('Confidence Binary', function () {
24
25 var confidencePath = Path.join(__dirname, '../', '/bin', '/confidence');
26 var configPath = Path.join(__dirname, '/config.json');
27 var tree = {
28 // Fork
29 key1: 'abc', // Value
30 key2: {
31 // Filter
32 $filter: 'env',
33 production: {
34 // Fork
35 deeper: {
36 // Value
37 $value: 'value' // Value
38 }
39 },
40 $default: {
41 // Filter
42 $filter: 'platform',
43 ios: 1, // Value
44 $default: 2 // Value
45 }
46 },
47 key3: {
48 // Fork
49 sub1: {
50 $value: 0,
51 $meta: 'something'
52 },
53 sub2: {
54 // Filter
55 $filter: 'xfactor',
56 $id: 'x_factor',
57 yes: '' // Value
58 }
59 },
60 key4: [12, 13, { $filter: 'none', x: 10, $default: 14 }],
61 key5: {},
62 ab: {
63 // Range
64 $filter: 'random.1',
65 $id: 'random_ab_test',
66 $range: [
67 { limit: 1, value: [1, 2] },
68 { limit: 2, value: { $value: 2 } },
69 { limit: 3, value: { a: 5 }, id: '3' },
70 { limit: 10, value: 4 },
71 { limit: 20, value: 5 }
72 ],
73 $default: 6
74 },
75 $meta: {
76 something: 'else'
77 }
78 };
79
80 before(function (done) {
81
82 var stream = Fs.createWriteStream(configPath);
83 stream.write(JSON.stringify(tree));
84 stream.end();
85 done();
86 });
87
88
89 after(function (done) {
90
91 Fs.unlink(configPath, done);
92 });
93
94 it('generates the correct config', function (done) {
95
96 var confidence = ChildProcess.spawn('node', [confidencePath, '-c', configPath]);
97
98 confidence.stdout.on('data', function (data) {
99
100 var result = data.toString();
101 var obj = JSON.parse('{"key1":"abc","key2":2,"key3":{"sub1":0},"key4":[12,13,14],"key5":{},"ab":6}');
102 expect(result).to.equal(JSON.stringify(obj, null, 4));
103 confidence.kill();
104 done();
105 });
106
107 confidence.stderr.on('data', function (data) {
108
109 expect(data.toString()).to.not.exist;
110 });
111 });
112
113 it('generates the correct config', function (done) {
114
115 var confidence = ChildProcess.spawn('node', [confidencePath, '-c', configPath, '--filter.env', 'production']);
116
117 confidence.stdout.on('data', function (data) {
118
119 var result = data.toString();
120 var obj = JSON.parse('{"key1":"abc","key2":{"deeper":"value"},"key3":{"sub1":0},"key4":[12,13,14],"key5":{},"ab":6}');
121 expect(result).to.equal(JSON.stringify(obj, null, 4));
122 confidence.kill();
123 done();
124 });
125
126 confidence.stderr.on('data', function (data) {
127
128 expect(data.toString()).to.not.exist;
129 });
130 });
131});