18 lines
1.3 KiB
JavaScript
18 lines
1.3 KiB
JavaScript
const {test}=require('node:test');
|
|
const assert=require('node:assert/strict');
|
|
const {findLogSource}=require('../out/logSource');
|
|
const expression='sensor.target_temperature_heatpump + 0.5';
|
|
const entry={app:'living_room_heatpump',message:`Error parsing string "${expression}" at character 0:Unknown variable : sensor.target_temperature_heatpump`};
|
|
test('resolves the failing expression inside the matching app rather than another app',()=>{
|
|
const docs=[{path:'/conf/apps/heating.yaml',text:`bedroom_heatpump:\n target_temperature: ${expression}\nliving_room_heatpump:\n target_temperature: ${expression}\n`}];
|
|
assert.deepEqual(findLogSource(entry,docs),{path:'/conf/apps/heating.yaml',line:4});
|
|
});
|
|
test('resolves a unique expression in a shared template and ignores comments',()=>{
|
|
assert.deepEqual(findLogSource(entry,[{path:'/conf/apps/templates.yml',text:`# ${expression}\nlibrary:\n value: ${expression}`}]),{path:'/conf/apps/templates.yml',line:3});
|
|
});
|
|
test('does not guess when a source is missing or ambiguous',()=>{
|
|
assert.equal(findLogSource(entry,[]),undefined);
|
|
assert.equal(findLogSource(entry,[{path:'a.yaml',text:`living_room_heatpump:\n a: ${expression}\n b: ${expression}`}]),undefined);
|
|
assert.equal(findLogSource({...entry,message:'Initialization failed'},[]),undefined);
|
|
});
|