forked from eemeli/dot-properties
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal.tests.js
More file actions
46 lines (42 loc) · 1.25 KB
/
external.tests.js
File metadata and controls
46 lines (42 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const fs = require('fs')
const path = require('path')
const { parse, stringify } = require('../index')
function testCase ({ name, root, srcPath, tgtPath, options: { parsePath = false } = {} }) {
test(name, () => {
const src = fs.readFileSync(path.resolve(root, srcPath), 'utf8')
const tgt = fs.readFileSync(path.resolve(root, tgtPath), 'utf8')
const exp = JSON.parse(tgt)
const res = parse(src, parsePath)
expect(res).toMatchObject(exp)
const src2 = stringify(res)
const res2 = parse(src2, parsePath)
expect(res2).toMatchObject(exp)
})
}
describe('@js.properties', () => {
const root = path.resolve(__dirname, '@js.properties')
const tests = fs.readdirSync(root).filter(name => /\.properties$/.test(name))
tests.forEach(name => {
testCase({
name,
root,
srcPath: name,
tgtPath: name + '.json'
})
})
testCase({
name: 'namespaced properties with path',
root,
srcPath: 'namespaced.properties',
tgtPath: 'namespaced.properties.namespaced.json',
options: { parsePath: true }
})
})
describe('node-properties-parser', () => {
testCase({
name: 'test',
root: path.resolve(__dirname, 'node-properties-parser'),
srcPath: 'test.properties',
tgtPath: 'test.json'
})
})