Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade JSDOM to 15.2.1 #12704

Merged
merged 1 commit into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jenkins/common.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def buildAll(String ref, dockerContainer, Boolean contentOnlyBuild) {

def prearchive(dockerContainer, envName) {
dockerContainer.inside(DOCKER_ARGS) {
sh "cd /application && node script/prearchive.js --buildtype=${envName}"
sh "cd /application && node --max-old-space-size=4096 script/prearchive.js --buildtype=${envName}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step was failing in Jenkins, as described here. Bumping the RAM allowance the same way we do for our unit tests, makes things happy.

}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"isomorphic-fetch": "^2.2.1",
"jest": "^23.6.0",
"jest-image-snapshot": "^2.7.0",
"jsdom": "^11.1.0",
"jsdom": "^15.2.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I was trying to accomplish with this PR. All other changes are to adapt to changes/problems introduced by this upgrade. Mostly just changing how certain document properties are mocked so that we can override and spy on them in tests.

"json2csv": "^4.2.1",
"jsonschema": "^1.1.1",
"libxmljs": "^0.19.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import sinon from 'sinon';
import { MhvTermsAndConditions } from '../../containers/MhvTermsAndConditions';

describe('<MhvTermsAndConditions>', () => {
let oldLocation;

const props = {
location: {
pathname: '/health-care/medical-information-terms-conditions',
Expand All @@ -30,14 +32,20 @@ describe('<MhvTermsAndConditions>', () => {
};

const setup = () => {
global.window.location.replace = sinon.spy();
oldLocation = global.window.location;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes to JSDOM prevent us from directly overriding the location object's properties so we need to delete it and replace it for our testing purposes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we could set window.location to writeable:true similar to what you are doing below and what's mentioned in jestjs/jest#890?

delete global.window.location;
global.window.location = { replace: sinon.spy() };
props.acceptTerms.reset();
props.fetchLatestTerms.reset();
props.fetchTermsAcceptance.reset();
};

beforeEach(setup);

afterEach(() => {
global.window.location = oldLocation;
});

it('should show an error when there are errors', () => {
const newProps = set('errors', { code: 404 }, props);
const wrapper = shallow(<MhvTermsAndConditions {...newProps} />);
Expand Down
7 changes: 4 additions & 3 deletions src/applications/vaos/tests/containers/VAOSApp.unit.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@ describe('VAOS <VAOSApp>', () => {
},
};

const oldReplace = window.location.replace;
window.location.replace = sinon.spy();
const oldLocation = window.location;
delete window.location;
window.location = { replace: sinon.spy() };
const tree = mount(<VAOSApp showApplication user={user} />);

expect(window.location.replace.firstCall.args[0]).to.contain('verify');
expect(tree.find('RequiredLoginView').exists()).to.be.true;

window.location.replace = oldReplace;
window.location.replace = oldLocation;
tree.unmount();
});
});
13 changes: 12 additions & 1 deletion src/platform/testing/unit/mocha-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,18 @@ export default function setupJSDom() {

win.dataLayer = [];
win.scrollTo = () => {};
win.sessionStorage = {};
Object.defineProperty(win, 'sessionStorage', {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sessionStorage and localStorage props that JSDOM creates are now readonly which creates issues for some of our tests that try to replace them. This override fixes that.

value: global.sessionStorage,
configurable: true,
enumerable: true,
writable: true,
});
Object.defineProperty(win, 'localStorage', {
value: global.localStorage,
configurable: true,
enumerable: true,
writable: true,
});
win.requestAnimationFrame = func => func();
win.matchMedia = () => ({
matches: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import backendServices from '../../../../user/profile/constants/backendServices'
import { MHVApp } from '../../../authorization/containers/MHVApp';

describe('<MHVApp>', () => {
let oldLocation;

const props = {
location: { pathname: '/health-care/prescriptions', query: {} },
mhvAccount: {
Expand All @@ -28,7 +30,11 @@ describe('<MHVApp>', () => {
};

const setup = () => {
global.window.location.replace = sinon.spy();
oldLocation = global.window.location;
delete global.window.location;
global.window.location = {
replace: sinon.spy(),
};
props.createMHVAccount.reset();
props.fetchMHVAccount.reset();
props.upgradeMHVAccount.reset();
Expand All @@ -52,6 +58,10 @@ describe('<MHVApp>', () => {

beforeEach(setup);

afterEach(() => {
global.window.location = oldLocation;
});

it('should show a loading indicator when fetching an account', () => {
const newProps = set('mhvAccount.loading', true, props);
const wrapper = shallow(<MHVApp {...newProps} />, { context });
Expand Down
Loading