diff --git a/.travis.yml b/.travis.yml index 1484cf824e..cc0d4be999 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ matrix: - name: "Cypress frontend tests" os: linux - dist: xenial + dist: bionic addons: chrome: stable services: diff --git a/frontend/cypress/package.json b/frontend/cypress/package.json index 3b33b604e7..a98edc8e4a 100644 --- a/frontend/cypress/package.json +++ b/frontend/cypress/package.json @@ -5,6 +5,6 @@ "debug": "cypress open" }, "devDependencies": { - "cypress": "^3.1.5" + "cypress": "^3.4.1" } } diff --git a/frontend/cypress/tests/codeView_load_benchmark.js b/frontend/cypress/tests/codeView_load_benchmark.js new file mode 100644 index 0000000000..651560bffd --- /dev/null +++ b/frontend/cypress/tests/codeView_load_benchmark.js @@ -0,0 +1,61 @@ +describe('load code view benchmark', function() { + const NUM_TRIALS = 5; + const THRESHOLD_LOADING_TIME = 8000; + const THRESHOLD_LOADING_TIME_SECONDS = THRESHOLD_LOADING_TIME / 1000; + + const BUFFER_PERCENTAGE = 0.1; + const BUFFER_SUGGESTED_TIME = 3000; + const ALLOWED_BUFFER_TIME = BUFFER_PERCENTAGE * THRESHOLD_LOADING_TIME >= BUFFER_SUGGESTED_TIME + ? BUFFER_PERCENTAGE * THRESHOLD_LOADING_TIME : BUFFER_SUGGESTED_TIME; + const ALLOWED_BUFFER_TIME_SECONDS = ALLOWED_BUFFER_TIME / 1000; + + const MAXIMUM_LOADING_TIME = THRESHOLD_LOADING_TIME + ALLOWED_BUFFER_TIME; + + let isATrialWithinMaxTime = false; + + const timeTrial = function(i) { + let startTime; + + // ensure that icons are loaded + Cypress.wait(); + + cy.get('#summary-wrapper .sort-within-group select') + .select('totalCommits dsc'); + + cy.get('.summary-chart__title--button.fa-code') + .should('be.visible') + .first() + .click() + .then(() => { + startTime = performance.now(); + }); + + cy.get('#tab-authorship .files', { timeout: 90000 }) + .should('be.visible') + .then(() => { + const endTime = performance.now(); + const loadingTime = endTime - startTime; + const loadingTimeSeconds = loadingTime / 1000; + + cy.log(`trial ${i+1} loading time: ${loadingTimeSeconds.toFixed(3)}s`); + + if (loadingTime <= MAXIMUM_LOADING_TIME) { + isATrialWithinMaxTime = true; + } + }); + }; + + + for (let i = 0; i < NUM_TRIALS; i++) { + it(`time taken to load code view (trial ${i+1})`, function() { + if (isATrialWithinMaxTime) { + this.skip(); + } + timeTrial(i); + }); + } + + it(`at least one trial is within ${THRESHOLD_LOADING_TIME_SECONDS}(+${ALLOWED_BUFFER_TIME_SECONDS})s`, function() { + assert.isTrue(isATrialWithinMaxTime); + }); +});