Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bluepnume committed Nov 27, 2018
1 parent 673819b commit 69f5663
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 35 deletions.
20 changes: 5 additions & 15 deletions .travis.yml
@@ -1,23 +1,13 @@
language: node_js language: node_js
node_js: node_js:
- "8" - "10"
before_install: before_install:
- export CHROME_BIN=chromium-browser - sudo apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sudo sh -c "echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections"
- sudo aptitude -y install ttf-mscorefonts-installer > /dev/null
- sudo fc-cache
before_script: before_script:
- npm run flow-typed - npm run flow-typed
script: script:
- npm run test - npm run build
sudo: required sudo: required
dist: trusty dist: xenial
addons: addons:
firefox: "52.0" chrome: stable
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
4 changes: 4 additions & 0 deletions src/buttons/template/containerTemplate.jsx
Expand Up @@ -65,6 +65,10 @@ export function containerTemplate({ id, props, CLASS, on, container, tag, contex


const size = BUTTON_SIZE.RESPONSIVE; const size = BUTTON_SIZE.RESPONSIVE;


if (!container) {
throw new Error(`Expected container`);
}

const getContainerDimensions = () => { const getContainerDimensions = () => {
let cont = container; let cont = container;


Expand Down
29 changes: 12 additions & 17 deletions test/index.js
Expand Up @@ -4,8 +4,7 @@ import './tests';


window.mockDomain = 'mock://www.merchant-site.com'; window.mockDomain = 'mock://www.merchant-site.com';


const MAX_OVERALL_MEMORY = 800; const MEM_PER_TEST = 2;
const MAX_TEST_MEMORY = 80;


const memoryReported = (window.performance && window.performance.memory && const memoryReported = (window.performance && window.performance.memory &&
window.performance.memory.usedJSHeapSize); window.performance.memory.usedJSHeapSize);
Expand All @@ -14,12 +13,12 @@ function getMemory() : number {
return window.performance.memory.usedJSHeapSize / Math.pow(2, 20); return window.performance.memory.usedJSHeapSize / Math.pow(2, 20);
} }


let startMem; let maxMem = getMemory();
let originalUserAgent; let originalUserAgent;


beforeEach(() => { beforeEach(() => {
if (memoryReported) { if (memoryReported) {
startMem = getMemory(); maxMem += MEM_PER_TEST;
} }


// eslint-disable-next-line unicorn/prefer-add-event-listener // eslint-disable-next-line unicorn/prefer-add-event-listener
Expand All @@ -35,7 +34,6 @@ beforeEach(() => {
}); });


afterEach(() => { afterEach(() => {

window.localStorage.clear(); window.localStorage.clear();
delete window.__paypal_storage__; delete window.__paypal_storage__;
delete window.__paypal_global__; delete window.__paypal_global__;
Expand All @@ -47,22 +45,19 @@ afterEach(() => {


delete window.document.documentMode; delete window.document.documentMode;


if (window.gc) { return window.paypal.destroyAll();
window.gc(); });
}


after(() => {
if (memoryReported) { if (memoryReported) {
const mem = getMemory(); if (window.gc) {
const diff = mem - startMem; window.gc();

if (mem > MAX_OVERALL_MEMORY) {
throw new Error(`Overall memory exceeded ${ MAX_OVERALL_MEMORY }mb - ${ mem.toFixed(2) }`);
} }


if (diff > MAX_TEST_MEMORY) { const mem = getMemory();
throw new Error(`Test memory exceeded ${ MAX_TEST_MEMORY }mb - ${ diff.toFixed(2) }`);
if (mem > maxMem) {
throw new Error(`Overall memory exceeded ${ parseInt(maxMem, 10) }mb - ${ mem.toFixed(2) }mb used`);
} }
} }

return window.paypal.destroyAll();
}); });
2 changes: 1 addition & 1 deletion test/screenshot/lib/browser.js
Expand Up @@ -14,7 +14,7 @@ import { readPNG, type PngType } from './image';


export async function openPage(scriptURL : string, { headless = true } : { headless : boolean }) : Promise<Object> { export async function openPage(scriptURL : string, { headless = true } : { headless : boolean }) : Promise<Object> {


const browser = await puppeteer.launch({ headless }); const browser = await puppeteer.launch({ headless, args: [ '--no-sandbox' ] });
const page = await browser.newPage(); const page = await browser.newPage();


page.emulate({ page.emulate({
Expand Down
2 changes: 1 addition & 1 deletion test/windows/button/index.jsx
Expand Up @@ -30,7 +30,7 @@ if (bridge) {
function renderCheckout(props = {}) { function renderCheckout(props = {}) {




window.paypal.Checkout.renderTo(window.xchild.getParentRenderWindow(), { window.paypal.Checkout.renderTo(window.parent, {


payment: window.xprops.createOrder, payment: window.xprops.createOrder,
onAuthorize(data, actions) : void | ZalgoPromise<void> { onAuthorize(data, actions) : void | ZalgoPromise<void> {
Expand Down
2 changes: 1 addition & 1 deletion test/windows/checkout/index.js
Expand Up @@ -65,7 +65,7 @@ if (action === 'checkout') {
testButton.addEventListener('click', () => { testButton.addEventListener('click', () => {
window.xchild.hide(); window.xchild.hide();


window.paypal.Checkout.renderPopupTo(window.xchild.getParentRenderWindow(), { window.paypal.Checkout.renderPopupTo(window.opener ? window.opener.parent : window.parent, {
payment: window.xprops.payment, payment: window.xprops.payment,
onAuthorize: window.xprops.onAuthorize, onAuthorize: window.xprops.onAuthorize,
onCancel: window.xprops.onCancel, onCancel: window.xprops.onCancel,
Expand Down

0 comments on commit 69f5663

Please sign in to comment.