]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/config-chain/test/save.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / config-chain / test / save.js
1 var CC = require('../index.js').ConfigChain
2 var test = require('tap').test
3
4 var f1 = '/tmp/f1.ini'
5 var f2 = '/tmp/f2.json'
6
7 var ini = require('ini')
8
9 var f1data = {foo: {bar: 'baz'}, bloo: 'jaus'}
10 var f2data = {oof: {rab: 'zab'}, oolb: 'suaj'}
11
12 var fs = require('fs')
13
14 fs.writeFileSync(f1, ini.stringify(f1data), 'utf8')
15 fs.writeFileSync(f2, JSON.stringify(f2data), 'utf8')
16
17 test('test saving and loading ini files', function (t) {
18   new CC()
19     .add({grelb:'blerg'}, 'opt')
20     .addFile(f1, 'ini', 'inifile')
21     .addFile(f2, 'json', 'jsonfile')
22     .on('load', function (cc) {
23
24       t.same(cc.snapshot, { grelb: 'blerg',
25                             bloo: 'jaus',
26                             foo: { bar: 'baz' },
27                             oof: { rab: 'zab' },
28                             oolb: 'suaj' })
29
30       t.same(cc.list, [ { grelb: 'blerg' },
31                         { bloo: 'jaus', foo: { bar: 'baz' } },
32                         { oof: { rab: 'zab' }, oolb: 'suaj' } ])
33
34       cc.set('grelb', 'brelg', 'opt')
35         .set('foo', 'zoo', 'inifile')
36         .set('oof', 'ooz', 'jsonfile')
37         .save('inifile')
38         .save('jsonfile')
39         .on('save', function () {
40           t.equal(fs.readFileSync(f1, 'utf8'),
41                   "bloo=jaus\nfoo=zoo\n")
42           t.equal(fs.readFileSync(f2, 'utf8'),
43                   "{\"oof\":\"ooz\",\"oolb\":\"suaj\"}")
44
45           t.same(cc.snapshot, { grelb: 'brelg',
46                                 bloo: 'jaus',
47                                 foo: 'zoo',
48                                 oof: 'ooz',
49                                 oolb: 'suaj' })
50
51           t.same(cc.list, [ { grelb: 'brelg' },
52                             { bloo: 'jaus', foo: 'zoo' },
53                             { oof: 'ooz', oolb: 'suaj' } ])
54
55           t.pass('ok')
56           t.end()
57         })
58     })
59 })