Joshua Poore commented on FLAGON-451:

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. 


I have tried to use one option: 

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:


Here is an example of some my experiments (not pushed):

Old createEnv:
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'] }, 
done : doneCallback, }, 

w/ new jsdom constructor:


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"

> 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

Reply via email to