You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flagon.apache.org by rf...@apache.org on 2019/09/26 00:11:43 UTC
[incubator-flagon-useralejs] branch FLAGON-434 updated (094b872 ->
8e67a26)
This is an automated email from the ASF dual-hosted git repository.
rf pushed a change to branch FLAGON-434
in repository https://gitbox.apache.org/repos/asf/incubator-flagon-useralejs.git.
from 094b872 [FLAGON-451] updated WIP mods to unit testing framework to mock sessionStorage
new e545d8c Moved SessionId initialization to a one-time run in getInitialSettings. Changed to camelCase. Removed weird JSON.parse check
new 0c844d0 Removed storage in favor of having testUtils handle it.
new 8e67a26 Fixed missing window.sessionStorage. Added VirtualConsole to make future debugging easier
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/getInitialSettings.js | 21 ++++++++++++---------
test/getInitialSettings_spec.js | 2 --
test/testUtils.js | 21 ++++++++++++++++-----
3 files changed, 28 insertions(+), 16 deletions(-)
[incubator-flagon-useralejs] 01/03: Moved SessionId initialization
to a one-time run in getInitialSettings. Changed to camelCase. Removed
weird JSON.parse check
Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rf pushed a commit to branch FLAGON-434
in repository https://gitbox.apache.org/repos/asf/incubator-flagon-useralejs.git
commit e545d8ce81beaa690d3ba71668ecb78a3da05aaf
Author: Rob Foley <ro...@gmail.com>
AuthorDate: Wed Sep 25 19:54:45 2019 -0400
Moved SessionId initialization to a one-time run in getInitialSettings. Changed to camelCase. Removed weird JSON.parse check
---
src/getInitialSettings.js | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/getInitialSettings.js b/src/getInitialSettings.js
index d55806d..987d5c8 100644
--- a/src/getInitialSettings.js
+++ b/src/getInitialSettings.js
@@ -3,19 +3,19 @@
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
+ * (the 'License'); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
+ * distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-var SessionId = getSessionId("userAleSessionId", 'session_' + String(Date.now()));
+ var sessionId = null;
/**
* Extracts the initial configuration settings from the
@@ -25,6 +25,10 @@ var SessionId = getSessionId("userAleSessionId", 'session_' + String(Date.now())
export function getInitialSettings() {
var settings = {};
+ if (sessionId === null) {
+ sessionId = getSessionId('userAleSessionId', 'session_' + String(Date.now()));
+ }
+
var script = document.currentScript || (function () {
var scripts = document.getElementsByTagName('script');
return scripts[scripts.length - 1];
@@ -43,7 +47,7 @@ export function getInitialSettings() {
settings.toolName = get('data-tool') || null;
settings.userFromParams = get('data-user-from-params') || null;
settings.time = timeStampScale(document.createEvent('CustomEvent'));
- settings.sessionID = get('data-session') || SessionId;
+ settings.sessionID = get('data-session') || sessionId;
return settings;
}
@@ -55,13 +59,12 @@ export function getInitialSettings() {
*
*/
export function getSessionId(sessionKey, value){
- if (JSON.parse(window.sessionStorage.getItem(sessionKey) === null)) {
- var storedSession = value;
+ if (window.sessionStorage.getItem(sessionKey) === null) {
window.sessionStorage.setItem(sessionKey, JSON.stringify(value));
- } else {
- storedSession = JSON.parse(window.sessionStorage.getItem(sessionKey));
+ return JSON.stringify(value);
}
- return storedSession;
+
+ return JSON.parse(window.sessionStorage.getItem(sessionKey));
}
[incubator-flagon-useralejs] 03/03: Fixed missing
window.sessionStorage. Added VirtualConsole to make future debugging easier
Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rf pushed a commit to branch FLAGON-434
in repository https://gitbox.apache.org/repos/asf/incubator-flagon-useralejs.git
commit 8e67a261f66a8dbaa17c17111169dc4389e2a8f9
Author: Rob Foley <ro...@gmail.com>
AuthorDate: Wed Sep 25 19:55:59 2019 -0400
Fixed missing window.sessionStorage. Added VirtualConsole to make future debugging easier
---
test/testUtils.js | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/test/testUtils.js b/test/testUtils.js
index 3581f92..ece0651 100644
--- a/test/testUtils.js
+++ b/test/testUtils.js
@@ -16,6 +16,7 @@
*/
import jsdom from 'jsdom';
import fs from 'fs';
+import Storage from 'dom-storage';
import { version } from '../package.json';
@@ -26,7 +27,7 @@ export function resourceLoader(res, callback) {
scriptContent = fs.readFileSync(`build/userale-${version}.min.js`).toString();
}
- const timeout = setTimeout(function() {
+ const timeout = setTimeout(() => {
callback(null, scriptContent);
}, 0);
@@ -39,16 +40,26 @@ export function resourceLoader(res, callback) {
}
export function createEnv(html, doneCallback, extraConfig) {
- let extra = (typeof extraConfig === 'undefined') ? {} : extraConfig;
+ const extra = (typeof extraConfig === 'undefined') ? {} : extraConfig;
+ const virtualConsole = jsdom.createVirtualConsole();
+ virtualConsole.sendTo(console);
return jsdom.env(Object.assign({}, {
- html : html,
- url : 'http://localhost:8080',
+ html: html,
+ url: 'http://localhost:8080',
features : {
FetchExternalResources : ['script'],
ProcessExternalResources : ['script']
},
resourceLoader,
- done : doneCallback,
+ created: (err, window) => {
+ if (err) {
+ throw err;
+ }
+
+ window.sessionStorage = new Storage(null, { strict: true });
+ },
+ done: doneCallback,
+ virtualConsole,
}, extraConfig));
}
[incubator-flagon-useralejs] 02/03: Removed storage in favor of
having testUtils handle it.
Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rf pushed a commit to branch FLAGON-434
in repository https://gitbox.apache.org/repos/asf/incubator-flagon-useralejs.git
commit 0c844d00a307a8752db45f5dde71c665ffbb8aea
Author: Rob Foley <ro...@gmail.com>
AuthorDate: Wed Sep 25 19:55:30 2019 -0400
Removed storage in favor of having testUtils handle it.
---
test/getInitialSettings_spec.js | 2 --
1 file changed, 2 deletions(-)
diff --git a/test/getInitialSettings_spec.js b/test/getInitialSettings_spec.js
index 3f8d834..618a1a9 100644
--- a/test/getInitialSettings_spec.js
+++ b/test/getInitialSettings_spec.js
@@ -17,7 +17,6 @@
import { expect } from 'chai';
import jsdom from 'jsdom';
import 'jsdom-global/register';
-import { Storage } from 'dom-storage';
import fs from 'fs';
import { createEnv } from './testUtils';
@@ -71,7 +70,6 @@ describe('getInitialSettings', () => {
const html = fs.readFileSync(__dirname + '/getInitialSettings_fetchAll.html');
createEnv(html, (err, window) => {
- window.sessionStorage = new Storage(null, { strict: true });
const config = window.userale.options();
expect(config).to.have.property('autostart', true);
expect(config).to.have.property('url', 'http://test.com');