From 32a71d6afa80ce18aa8757419054c680726062f0 Mon Sep 17 00:00:00 2001 From: Brandon Marshall Date: Thu, 7 Dec 2023 10:13:02 -0800 Subject: [PATCH] MWPW-138026 Add tags to lana logs --- blocks/faas-decode/faas-decode.js | 3 +-- blocks/tree-view/tree-view.js | 3 +-- scripts/scripts.js | 2 +- test/blocks/faas-decode/faas-decode.test.js | 6 ++++-- test/blocks/tree-view/tree-view.test.js | 7 ++++--- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/blocks/faas-decode/faas-decode.js b/blocks/faas-decode/faas-decode.js index b197cfa..70c3fac 100644 --- a/blocks/faas-decode/faas-decode.js +++ b/blocks/faas-decode/faas-decode.js @@ -6,8 +6,7 @@ export default async function init(el) { const resp = await fetch(url); if (!resp?.ok) { - // eslint-disable-next-line no-console - console.log(`Error fetching data from url: ${url}`); + window.lana?.log(`Error fetching data from url: ${url}`, { tags: 'info, faas-decode' }); return; } diff --git a/blocks/tree-view/tree-view.js b/blocks/tree-view/tree-view.js index 26aba1e..3e044a5 100644 --- a/blocks/tree-view/tree-view.js +++ b/blocks/tree-view/tree-view.js @@ -11,8 +11,7 @@ export const isCurrentPage = (link) => { if (isBacomHost && url.pathname.replace('.html', '') === currentPath) return true; } catch (e) { - // eslint-disable-next-line no-console - console.log('Tree View error:', e); + window.lana?.log(`Tree View error:${e.message}`, { tags: 'info, tree-view' }); } return false; diff --git a/scripts/scripts.js b/scripts/scripts.js index 5bd5f20..d57758d 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -189,6 +189,6 @@ const miloLibs = setLibs(LIBS); } } setConfig({ ...CONFIG, miloLibs }); - loadLana({ clientId: 'bacom' }); + loadLana({ clientId: 'bacom', tags: 'info' }); await loadArea(); }()); diff --git a/test/blocks/faas-decode/faas-decode.test.js b/test/blocks/faas-decode/faas-decode.test.js index c79a143..e643aff 100644 --- a/test/blocks/faas-decode/faas-decode.test.js +++ b/test/blocks/faas-decode/faas-decode.test.js @@ -4,9 +4,11 @@ import init from '../../../blocks/faas-decode/faas-decode.js'; import { setLibs } from '../../../scripts/utils.js'; import waitForElement from '../../helpers/waitForElement.js'; +window.lana = { log: () => {} }; + describe('FaaS Decode', () => { before(() => { - sinon.spy(console, 'log'); + sinon.stub(window.lana, 'log'); setLibs('/libs'); }); @@ -18,7 +20,7 @@ describe('FaaS Decode', () => { document.body.innerHTML = '
'; const el = document.querySelector('.faas-decode'); await init(el); - expect(console.log.args[0][0]).to.include('Error fetching data from url:'); + expect(window.lana.log.args[0][0]).to.include('Error fetching data from url:'); }); it('creates a table', async () => { diff --git a/test/blocks/tree-view/tree-view.test.js b/test/blocks/tree-view/tree-view.test.js index 1f68981..428284a 100644 --- a/test/blocks/tree-view/tree-view.test.js +++ b/test/blocks/tree-view/tree-view.test.js @@ -5,6 +5,7 @@ import { setLibs } from '../../../scripts/utils.js'; const { default: init, isCurrentPage } = await import('../../../blocks/tree-view/tree-view.js'); +window.lana = { log: () => {} }; setLibs('libs'); describe('Tree View', () => { @@ -38,10 +39,10 @@ describe('Tree View', () => { }); it('isCurrentPage catches error', () => { - sinon.spy(console, 'log'); + sinon.stub(window.lana, 'log'); isCurrentPage('/relative-link'); - expect(console.log.args[0][0]).to.equal('Tree View error:'); - console.log.restore(); + expect(window.lana.log.args[0][0]).to.contain('Tree View error:'); + window.lana.log.restore(); }); describe('accordion', () => {