This is an automated email from the ASF dual-hosted git repository. poorejc pushed a commit to branch setupStartStopRefactor in repository https://gitbox.apache.org/repos/asf/incubator-flagon-useralejs.git
commit 49a601814f9dcae8b690a22b43e00f7efce518cb Author: giterdone77 <[email protected]> AuthorDate: Wed Mar 23 22:01:53 2022 -0400 first commit --- src/configure.js | 5 +++++ src/main.js | 2 +- test/configure_spec.js | 19 +++++++++++++++++-- test/main_spec.js | 12 ++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/configure.js b/src/configure.js index fb369d9..1b25a30 100644 --- a/src/configure.js +++ b/src/configure.js @@ -22,6 +22,8 @@ * @param {Object} newConfig Configuration object to merge into the current config. */ export function configure(config, newConfig) { + const configAutostart = config['autostart']; + const newConfigAutostart = newConfig['autostart']; Object.keys(newConfig).forEach(function(option) { if (option === 'userFromParams') { const userId = getUserIdFromParams(newConfig[option]); @@ -30,6 +32,9 @@ export function configure(config, newConfig) { } } config[option] = newConfig[option]; + if (configAutostart === false || newConfigAutostart === false){ + config['autostart'] = false; + } }); } diff --git a/src/main.js b/src/main.js index f1bdfad..5ca5386 100644 --- a/src/main.js +++ b/src/main.js @@ -63,7 +63,7 @@ function setup(config) { setTimeout(function () { const state = document.readyState; - if (state === 'interactive' || state === 'complete') { + if (config.autostart && (state === 'interactive' || state === 'complete')) { attachHandlers(config); initSender(logs, config); started = config.on = true; diff --git a/test/configure_spec.js b/test/configure_spec.js index 7307484..c9086c1 100644 --- a/test/configure_spec.js +++ b/test/configure_spec.js @@ -15,8 +15,7 @@ * limitations under the License. */ import { expect } from 'chai'; -import jsdom from 'jsdom'; -import fs from 'fs'; + import { getUserIdFromParams, configure } from '../src/configure'; describe('configure', () => { @@ -28,6 +27,22 @@ describe('configure', () => { done(); }); + it('Config autostart false makes autostart false', (done) => { + const config = {autostart: false}; + const newConfig = { autostart: true }; + configure(config, newConfig); + expect(config).to.deep.equal({ autostart: false }); + done(); + }); + + it('neither autostart false makes autostart true', (done) => { + const config = {autostart: undefined}; + const newConfig = { autostart: true }; + configure(config, newConfig); + expect(config).to.deep.equal({ autostart: true }); + done(); + }); + it('includes a userid if present in the window.location', (done) => { const config = {}; const newConfig = { foo: 'bar', userFromParams: 'user', }; diff --git a/test/main_spec.js b/test/main_spec.js index 5146ec3..64ba123 100644 --- a/test/main_spec.js +++ b/test/main_spec.js @@ -57,6 +57,18 @@ describe('Userale API', () => { dom.window.close(); }); + it('autostart check', async () => { + const dom = await createEnvFromFile(htmlFileName) + const config = dom.window.userale.options(); + dom.window.userale.options({ + autostart: false + }); + const newConfig = dom.window.userale.options(); + + expect(newConfig.autostart).to.equal(false); + dom.window.close(); + }); + it('starts + stops', async () => { const dom = await createEnvFromFile(htmlFileName) setTimeout(() => {
