You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flagon.apache.org by "Joshua Poore (Jira)" <ji...@apache.org> on 2019/09/12 05:08:00 UTC
[jira] [Commented] (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&focusedCommentId=16928203#comment-16928203 ]
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.
[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)