[jira] [Comment Edited] (FLAGON-451) Update unit tests to accommodate session storage features
[ https://issues.apache.org/jira/browse/FLAGON-451?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16929009#comment-16929009 ] Joshua Poore edited comment on FLAGON-451 at 9/13/19 6:34 AM: -- added dom-storage 2.0.2 (should be pre- jsdom 10) as dev-dependency to Mock sessionStorage in unit tests. pushed to FLAGON-434 branch [https://www.npmjs.com/package/dom-storage/v/2.0.2] added to getInitialSettings_spec.js @ 'fetches all settings from a script tag': {code:java} import 'jsdom-global/register'; #adds global objects like windows to jsdom import { Storage } from 'dom-storage'; #storage mock {code} also added sessionStorage within test context {code:java} window.sessionStorage = new Storage(null, { strict: true }); {code} was (Author: poor...@me.com): added dom-storage 2.0.2 (should be pre- jsdom 10) as dev-dependency to Mock sessionStorage in unit tests. pushed to FLAGON-434 branch [https://www.npmjs.com/package/dom-storage/v/2.0.2] added to getInitialSettings_spec.js: {code:java} import 'jsdom-global/register'; #adds global objects like windows to jsdom import { Storage } from 'dom-storage'; #storage mock {code} also added sessionStorage within test context {code:java} window.sessionStorage = new Storage(null, { strict: true }); {code} > Update unit tests to accommodate session storage features > - > > Key: FLAGON-451 > URL: https://issues.apache.org/jira/browse/FLAGON-451 > Project: Flagon > Issue Type: Sub-task > Components: UserALE.js >Affects Versions: UserALE.js 2.1.0 >Reporter: Joshua Poore >Assignee: Joshua Poore >Priority: Major > Fix For: UserALE.js 2.1.0 > > > session storage needs to be a known object in unit tests. > exercising sessionStorage in getInitialSettings to preserve session Id at > page refresh (such as submit) performs expectedly in testing with the example > page, however breaks the following unit tests: > {code:java} > 1) getInitialSettings > getInitialSettings > fetches all settings from a script tag: > Uncaught TypeError: Cannot read property 'options' of undefined > at Object.done (test/getInitialSettings_spec.js:76:39) > at > /Users/jpoore/Documents/Apache_Flagon/test/incubator-flagon-useralejs/node_modules/jsdom/lib/jsdom.js:325:18 > at processTicksAndRejections (internal/process/task_queues.js:75:11) > 2) getInitialSettings > getInitialSettings > grabs user id from params: > Uncaught TypeError: Cannot read property 'options' of undefined > at Object.url [as done] (test/getInitialSettings_spec.js:95:39) > at > /Users/jpoore/Documents/Apache_Flagon/test/incubator-flagon-useralejs/node_modules/jsdom/lib/jsdom.js:325:18 > at processTicksAndRejections (internal/process/task_queues.js:75:11) > 3) Userale API > provides configs: > Uncaught TypeError: Cannot read property 'options' of undefined > at Object.done (test/main_spec.js:33:37) > at > /Users/jpoore/Documents/Apache_Flagon/test/incubator-flagon-useralejs/node_modules/jsdom/lib/jsdom.js:325:18 > at processTicksAndRejections (internal/process/task_queues.js:75:11) > 4) Userale API > edits configs: > Uncaught TypeError: Cannot read property 'options' of undefined > at Object.done (test/main_spec.js:58:37) > at > /Users/jpoore/Documents/Apache_Flagon/test/incubator-flagon-useralejs/node_modules/jsdom/lib/jsdom.js:325:18 > at processTicksAndRejections (internal/process/task_queues.js:75:11) > 5) Userale API > starts + stops: > Uncaught TypeError: Cannot read property 'options' of undefined > at Timeout._onTimeout (test/main_spec.js:75:24) > at listOnTimeout (internal/timers.js:531:17) > at processTimers (internal/timers.js:475:7) > 6) Userale API > sends custom logs: > Uncaught TypeError: Cannot read property 'log' of undefined > at Object.done (test/main_spec.js:93:22) > at > /Users/jpoore/Documents/Apache_Flagon/test/incubator-flagon-useralejs/node_modules/jsdom/lib/jsdom.js:325:18 > at processTicksAndRejections > (internal/process/task_queues.js:75:11){code} -- This message was sent by Atlassian Jira (v8.3.2#803003)
[jira] [Comment Edited] (FLAGON-451) Update unit tests to accommodate session storage features
[ https://issues.apache.org/jira/browse/FLAGON-451?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16929009#comment-16929009 ] Joshua Poore edited comment on FLAGON-451 at 9/13/19 6:23 AM: -- added dom-storage 2.0.2 (should be pre- jsdom 10) as dev-dependency to Mock sessionStorage in unit tests. pushed to FLAGON-434 branch [https://www.npmjs.com/package/dom-storage/v/2.0.2] added to getInitialSettings_spec.js: {code:java} import 'jsdom-global/register'; #adds global objects like windows to jsdom import { Storage } from 'dom-storage'; #storage mock {code} also added sessionStorage within test context {code:java} window.sessionStorage = new Storage(null, { strict: true }); {code} was (Author: poor...@me.com): added dom-storage 2.0.2 (should be pre- jsdom 10) as dev-dependency to Mock sessionStorage in unit tests. pushed to FLAGON-434 branch Again, added function to getInitialSettings ('getSessionId') works in testing with example page, exactly as expected. But, unit tests fail [https://www.npmjs.com/package/dom-storage/v/2.0.2] added to getInitialSettings_spec.js: {code:java} import 'jsdom-global/register'; #adds global objects like windows to jsdom import { Storage } from 'dom-storage'; #storage mock {code} also added sessionStorage within test context {code:java} window.sessionStorage = new Storage(null, { strict: true }); {code} > Update unit tests to accommodate session storage features > - > > Key: FLAGON-451 > URL: https://issues.apache.org/jira/browse/FLAGON-451 > Project: Flagon > Issue Type: Sub-task > Components: UserALE.js >Affects Versions: UserALE.js 2.1.0 >Reporter: Joshua Poore >Assignee: Joshua Poore >Priority: Major > Fix For: UserALE.js 2.1.0 > > > session storage needs to be a known object in unit tests. > exercising sessionStorage in getInitialSettings to preserve session Id at > page refresh (such as submit) performs expectedly in testing with the example > page, however breaks the following unit tests: > {code:java} > 1) getInitialSettings > getInitialSettings > fetches all settings from a script tag: > Uncaught TypeError: Cannot read property 'options' of undefined > at Object.done (test/getInitialSettings_spec.js:76:39) > at > /Users/jpoore/Documents/Apache_Flagon/test/incubator-flagon-useralejs/node_modules/jsdom/lib/jsdom.js:325:18 > at processTicksAndRejections (internal/process/task_queues.js:75:11) > 2) getInitialSettings > getInitialSettings > grabs user id from params: > Uncaught TypeError: Cannot read property 'options' of undefined > at Object.url [as done] (test/getInitialSettings_spec.js:95:39) > at > /Users/jpoore/Documents/Apache_Flagon/test/incubator-flagon-useralejs/node_modules/jsdom/lib/jsdom.js:325:18 > at processTicksAndRejections (internal/process/task_queues.js:75:11) > 3) Userale API > provides configs: > Uncaught TypeError: Cannot read property 'options' of undefined > at Object.done (test/main_spec.js:33:37) > at > /Users/jpoore/Documents/Apache_Flagon/test/incubator-flagon-useralejs/node_modules/jsdom/lib/jsdom.js:325:18 > at processTicksAndRejections (internal/process/task_queues.js:75:11) > 4) Userale API > edits configs: > Uncaught TypeError: Cannot read property 'options' of undefined > at Object.done (test/main_spec.js:58:37) > at > /Users/jpoore/Documents/Apache_Flagon/test/incubator-flagon-useralejs/node_modules/jsdom/lib/jsdom.js:325:18 > at processTicksAndRejections (internal/process/task_queues.js:75:11) > 5) Userale API > starts + stops: > Uncaught TypeError: Cannot read property 'options' of undefined > at Timeout._onTimeout (test/main_spec.js:75:24) > at listOnTimeout (internal/timers.js:531:17) > at processTimers (internal/timers.js:475:7) > 6) Userale API > sends custom logs: > Uncaught TypeError: Cannot read property 'log' of undefined > at Object.done (test/main_spec.js:93:22) > at > /Users/jpoore/Documents/Apache_Flagon/test/incubator-flagon-useralejs/node_modules/jsdom/lib/jsdom.js:325:18 > at processTicksAndRejections > (internal/process/task_queues.js:75:11){code} -- This message was sent by Atlassian Jira (v8.3.2#803003)
[jira] [Comment Edited] (FLAGON-451) Update unit tests to accommodate session storage features
[ https://issues.apache.org/jira/browse/FLAGON-451?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16928203#comment-16928203 ] Joshua Poore edited comment on FLAGON-451 at 9/12/19 5:08 AM: -- [~rf] One likely cause for unit test failure owing to sessionStorage reference in getInitialSettings is that jsdom v9 has no concept of sessionStorage. v12 does; previous versions v10,11 have used mocks or 3rd party libraries. [https://stackoverflow.com/questions/51569521/jsdom-11-12-0-how-to-mock-localstorage] I have tried to use one option: [https://www.npmjs.com/package/dom-storage/v/2.0.2] This seems simple and is well used, however, I haven't had success with it. Given how we call jsdom.env via createEnv (testUtils), I just cant figure out where to inject a mocked sessionStorage variable. Another option is to update our unit tests for jsdom v12. This is sensible, as we're now 3 major versions behind. However, this is also tricky given that jsdom now uses a constructor and new resource loading options. I have made an attempt, but am stuck on how to pull in our resource loader. jsdom has a new customizable resource loader, but it doesnt seem to have the options we need: [https://github.com/jsdom/jsdom#loading-subresources] Here is an example of some my experiments (not pushed): Old createEnv: {code:java} export function createEnv(html, doneCallback, extraConfig) { let extra = (typeof extraConfig === 'undefined') ? {} : extraConfig; return jsdom.env(Object.assign({}, { html : html, url : 'http://localhost:8080', features : { FetchExternalResources : ['script'], ProcessExternalResources : ['script'] }, resourceLoader, done : doneCallback, }, extraConfig)); } {code} w/ new jsdom constructor: {code:java} ... return JSDOM.fromFile(html, options) .then(function (dom) { let window = dom.window, document = window.document, sessionStorage = window.sessionStorage; }); } const jsdomOptions = { url: "http://localhost:8080;, runScripts: 'dangerously', resources: "usable" };{code} was (Author: poor...@me.com): [~rf] One likely cause for unit test failure owing to sessionStorage reference in getInitialSettings is that jsdom v9 has no concept of sessionStorage. v12 does; previous versions v10,11 have used mocks or 3rd party libraries. [https://stackoverflow.com/questions/51569521/jsdom-11-12-0-how-to-mock-localstorage] I have tried to use one option: [https://www.npmjs.com/package/dom-storage/v/2.0.2] This seems simple and is well used, however, I haven't had success with it. Given how we call jsdom.env via createEnv (testUtils), I just cant figure out where to inject a mocked sessionStorage variable. Another option is to update our unit tests for jsdom v12. This is sensible, as we're now 3 major versions behind. However, this is also tricky given that jsdom now uses a constructor and new resource loading options. I have made an attempt, but am stuck on how to pull in our resource loader. jsdom has a new customizable resource loader, but it doesnt seem to have the options we need: [https://github.com/jsdom/jsdom#loading-subresources] Here is an example of some my experiments (not pushed): Old createEnv: {code:java} export function createEnv(html, doneCallback, extraConfig) { let extra = (typeof extraConfig === 'undefined') ? {} : extraConfig; return jsdom.env(Object.assign({}, { html : html, url : 'http://localhost:8080', features : { FetchExternalResources : ['script'], ProcessExternalResources : ['script'] }, resourceLoader, done : doneCallback, }, extraConfig)); {code} w/ new jsdom constructor: {code:java} ... return JSDOM.fromFile(html, options) .then(function (dom) { let window = dom.window, document = window.document, sessionStorage = window.sessionStorage; }); } const jsdomOptions = { url: "http://localhost:8080;, runScripts: 'dangerously', resources: "usable" };{code} > Update unit tests to accommodate session storage features > - > > Key: FLAGON-451 > URL: https://issues.apache.org/jira/browse/FLAGON-451 > Project: Flagon > Issue Type: Sub-task > Components: UserALE.js >Affects Versions: UserALE.js 2.1.0 >Reporter: Joshua Poore >Assignee: Joshua Poore >Priority: Major > Fix For: UserALE.js 2.1.0 > > > session storage needs to be a known object in unit tests. -- This message was sent by Atlassian Jira (v8.3.2#803003)
[jira] [Comment Edited] (FLAGON-451) Update unit tests to accommodate session storage features
[ https://issues.apache.org/jira/browse/FLAGON-451?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16928203#comment-16928203 ] Joshua Poore edited comment on FLAGON-451 at 9/12/19 5:07 AM: -- [~rf] One likely cause for unit test failure owing to sessionStorage reference in getInitialSettings is that jsdom v9 has no concept of sessionStorage. v12 does; previous versions v10,11 have used mocks or 3rd party libraries. [https://stackoverflow.com/questions/51569521/jsdom-11-12-0-how-to-mock-localstorage] I have tried to use one option: [https://www.npmjs.com/package/dom-storage/v/2.0.2] This seems simple and is well used, however, I haven't had success with it. Given how we call jsdom.env via createEnv (testUtils), I just cant figure out where to inject a mocked sessionStorage variable. Another option is to update our unit tests for jsdom v12. This is sensible, as we're now 3 major versions behind. However, this is also tricky given that jsdom now uses a constructor and new resource loading options. I have made an attempt, but am stuck on how to pull in our resource loader. jsdom has a new customizable resource loader, but it doesnt seem to have the options we need: [https://github.com/jsdom/jsdom#loading-subresources] Here is an example of some my experiments (not pushed): Old createEnv: {code:java} export function createEnv(html, doneCallback, extraConfig) { let extra = (typeof extraConfig === 'undefined') ? {} : extraConfig; return jsdom.env(Object.assign({}, { html : html, url : 'http://localhost:8080', features : { FetchExternalResources : ['script'], ProcessExternalResources : ['script'] }, resourceLoader, done : doneCallback, }, extraConfig)); {code} w/ new jsdom constructor: {code:java} ... return JSDOM.fromFile(html, options) .then(function (dom) { let window = dom.window, document = window.document, sessionStorage = window.sessionStorage; }); } const jsdomOptions = { url: "http://localhost:8080;, runScripts: 'dangerously', resources: "usable" };{code} was (Author: poor...@me.com): One likely cause for unit test failure owing to sessionStorage reference in getInitialSettings is that jsdom v9 has no concept of sessionStorage. v12 does; previous versions v10,11 have used mocks or 3rd party libraries. [https://stackoverflow.com/questions/51569521/jsdom-11-12-0-how-to-mock-localstorage] I have tried to use one option: [https://www.npmjs.com/package/dom-storage/v/2.0.2] This seems simple and is well used, however, I haven't had success with it. Given how we call jsdom.env via createEnv (testUtils), I just cant figure out where to inject a mocked sessionStorage variable. Another option is to update our unit tests for jsdom v12. This is sensible, as we're now 3 major versions behind. However, this is also tricky given that jsdom now uses a constructor and new resource loading options. I have made an attempt, but am stuck on how to pull in our resource loader. jsdom has a new customizable resource loader, but it doesnt seem to have the options we need: [https://github.com/jsdom/jsdom#loading-subresources] Here is an example of some my experiments (not pushed): Old createEnv: {code:java} export function createEnv(html, doneCallback, extraConfig) { let extra = (typeof extraConfig === 'undefined') ? {} : extraConfig; return jsdom.env(Object.assign({}, { html : html, url : 'http://localhost:8080', features : { FetchExternalResources : ['script'], ProcessExternalResources : ['script'] }, resourceLoader, done : doneCallback, }, extraConfig)); {code} w/ new jsdom constructor: {code:java} ... return JSDOM.fromFile(html, options) .then(function (dom) { let window = dom.window, document = window.document, sessionStorage = window.sessionStorage; }); } const jsdomOptions = { url: "http://localhost:8080;, runScripts: 'dangerously', resources: "usable" };{code} > Update unit tests to accommodate session storage features > - > > Key: FLAGON-451 > URL: https://issues.apache.org/jira/browse/FLAGON-451 > Project: Flagon > Issue Type: Sub-task > Components: UserALE.js >Affects Versions: UserALE.js 2.1.0 >Reporter: Joshua Poore >Assignee: Joshua Poore >Priority: Major > Fix For: UserALE.js 2.1.0 > > > session storage needs to be a known object in unit tests. -- This message was sent by Atlassian Jira (v8.3.2#803003)