mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-06-23 05:31:47 +00:00
4bc0c3ed6b
This allows specifying a path outside of the data directory using an absolute path (e.g. /path/to/devices.yaml) or a path relative to the data directory (e.g. devices.yaml, foo/devices.yaml, ../../devices.yaml, ...). This change is backward compatible because file names and nested paths are just a special case of a relative path. Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
28 lines
1.0 KiB
JavaScript
28 lines
1.0 KiB
JavaScript
const logger = require('./stub/logger');
|
|
const data = require('../lib/util/data').default;
|
|
const path = require('path');
|
|
const tmp = require('tmp');
|
|
const fs = require('fs');
|
|
|
|
describe('Data', () => {
|
|
describe('Get path', () => {
|
|
it('Should return correct path', () => {
|
|
const expected = path.normalize(path.join(__dirname, '..', 'data'));
|
|
const actual = data.getPath();
|
|
expect(actual).toBe(expected);
|
|
});
|
|
|
|
it('Should return correct path when ZIGBEE2MQTT_DATA set', () => {
|
|
const expected = tmp.dirSync().name;
|
|
process.env.ZIGBEE2MQTT_DATA = expected;
|
|
data.testingOnlyReload();
|
|
const actual = data.getPath();
|
|
expect(actual).toBe(expected);
|
|
expect(data.joinPath('test')).toStrictEqual(path.join(expected, 'test'));
|
|
expect(data.joinPath('/test')).toStrictEqual(path.resolve(expected, '/test'));
|
|
delete process.env.ZIGBEE2MQTT_DATA;
|
|
data.testingOnlyReload();
|
|
});
|
|
});
|
|
});
|