diff --git a/Makefile.local b/Makefile.local index ff9cc0bb..78c5b77a 100644 --- a/Makefile.local +++ b/Makefile.local @@ -1,75 +1,88 @@ TEST_DIRS := ./swh/web/tests TESTFLAGS = --hypothesis-profile=swh-web-fast TESTFULL_FLAGS = --hypothesis-profile=swh-web YARN ?= yarn yarn-install: package.json $(YARN) install .PHONY: build-webpack-dev build-webpack-dev: yarn-install $(YARN) build-dev .PHONY: build-webpack-test build-webpack-test: yarn-install $(YARN) build-test .PHONY: build-webpack-dev-no-verbose build-webpack-dev-no-verbose: yarn-install $(YARN) build-dev >/dev/null .PHONY: build-webpack-prod build-webpack-prod: yarn-install $(YARN) build .PHONY: run-migrations run-migrations: python3 swh/web/manage.py migrate --settings=swh.web.settings.development -v0 2>/dev/null python3 swh/web/manage.py createcachetable --settings=swh.web.settings.development -v0 2>/dev/null .PHONY: run-migrations-prod run-migrations-prod: django-admin migrate --settings=swh.web.settings.production -v0 2>/dev/null django-admin createcachetable --settings=swh.web.settings.production -v0 2>/dev/null .PHONY: run-migrations-test run-migrations-test: rm -f swh/web/settings/testdb.sqlite3 django-admin migrate --settings=swh.web.settings.tests -v0 2>/dev/null django-admin createcachetable --settings=swh.web.settings.tests -v0 2>/dev/null cat swh/web/tests/create_test_admin.py | django-admin shell --settings=swh.web.settings.tests .PHONY: clear-memcached clear-memcached: echo "flush_all" | nc -q 2 localhost 11211 2>/dev/null run-django-webpack-devserver: run-migrations yarn-install bash -c "trap 'trap - SIGINT SIGTERM ERR; kill %1' SIGINT SIGTERM ERR; $(YARN) start-dev & sleep 10 && cd swh/web && python3 manage.py runserver --nostatic --settings=swh.web.settings.development" run-django-webpack-dev: build-webpack-dev run-migrations python3 swh/web/manage.py runserver --nostatic --settings=swh.web.settings.development run-django-webpack-prod: build-webpack-prod run-migrations-prod clear-memcached python3 swh/web/manage.py runserver --nostatic --settings=swh.web.settings.production run-django-server-dev: run-migrations python3 swh/web/manage.py runserver --nostatic --settings=swh.web.settings.development run-django-server-prod: run-migrations-prod clear-memcached python3 swh/web/manage.py runserver --nostatic --settings=swh.web.settings.production run-gunicorn-server: run-migrations clear-memcached gunicorn3 -b 127.0.0.1:5004 swh.web.wsgi run-django-webpack-memory-storages: build-webpack-dev run-migrations python3 swh/web/manage.py runserver --nostatic --settings=swh.web.settings.tests test-full: $(TEST) $(TESTFULL_FLAGS) $(TEST_DIRS) -test-frontend: build-webpack-test run-migrations-test - python3 swh/web/manage.py runserver --nostatic --settings=swh.web.settings.tests & sleep 10 && $(YARN) run cypress run && pkill -P $$! && $(YARN) run mochawesome +.PHONY: test-frontend-cmd +test-frontend-cmd: build-webpack-test run-migrations-test + python3 swh/web/manage.py runserver --nostatic --settings=swh.web.settings.tests & sleep 10 && $(YARN) run cypress run ; pkill -P $$! ; $(YARN) run mochawesome -test-frontend-ui: build-webpack-test run-migrations-test +test-frontend: export CYPRESS_SKIP_SLOW_TESTS=1 +test-frontend: test-frontend-cmd + +test-frontend-full: export CYPRESS_SKIP_SLOW_TESTS=0 +test-frontend-full: test-frontend-cmd + +.PHONY: test-frontend-ui-cmd +test-frontend-ui-cmd: build-webpack-test run-migrations-test bash -c "trap 'trap - SIGINT SIGTERM ERR EXIT; jobs -p | head -1 | xargs pkill -P' SIGINT SIGTERM ERR EXIT; python3 swh/web/manage.py runserver --nostatic --settings=swh.web.settings.tests & sleep 10 && $(YARN) run cypress open" +test-frontend-ui: export CYPRESS_SKIP_SLOW_TESTS=1 +test-frontend-ui: test-frontend-ui-cmd + +test-frontend-full-ui: export CYPRESS_SKIP_SLOW_TESTS=0 +test-frontend-full-ui: test-frontend-ui-cmd diff --git a/cypress.json b/cypress.json index 90a03961..1f3ff8f2 100644 --- a/cypress.json +++ b/cypress.json @@ -1,20 +1,23 @@ { "baseUrl": "http://localhost:5004", "video": false, "viewportWidth": 1920, "viewportHeight": 1080, "defaultCommandTimeout": 10000, "requestTimeout": 10000, "numTestsKeptInMemory": 500, "reporter": "cypress-multi-reporters", "reporterOptions": { "reporterEnabled": "mochawesome", "mochawesomeReporterOptions": { "reportDir": "cypress/mochawesome/results", "quiet": true, "overwrite": false, "html": false, "json": true } + }, + "env": { + "SKIP_SLOW_TESTS": 1 } } diff --git a/cypress/integration/content-rendering.spec.js b/cypress/integration/content-rendering.spec.js index 4bd949c0..fa532f02 100644 --- a/cypress/integration/content-rendering.spec.js +++ b/cypress/integration/content-rendering.spec.js @@ -1,99 +1,99 @@ /** * Copyright (C) 2019 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ -import {checkLanguageHighlighting} from '../utils'; +import {checkLanguageHighlighting, describeSlowTests} from '../utils'; -describe('Code highlighting tests', function() { +describeSlowTests('Code highlighting tests', function() { const extensions = require('../fixtures/source-file-extensions.json'); extensions.forEach(ext => { it(`should highlight source files with extension ${ext}`, function() { cy.request(this.Urls.tests_content_code_extension(ext)).then(response => { const data = response.body; cy.visit(`${this.Urls.browse_content(data.sha1)}?path=file.${ext}`); checkLanguageHighlighting(data.language); }); }); }); const filenames = require('../fixtures/source-file-names.json'); filenames.forEach(filename => { it(`should highlight source files with filenames ${filename}`, function() { cy.request(this.Urls.tests_content_code_filename(filename)).then(response => { const data = response.body; cy.visit(`${this.Urls.browse_content(data.sha1)}?path=${filename}`); checkLanguageHighlighting(data.language); }); }); }); }); describe('Image rendering tests', function() { const imgExtensions = ['gif', 'jpeg', 'png', 'webp']; imgExtensions.forEach(ext => { it(`should render image with extension ${ext}`, function() { cy.request(this.Urls.tests_content_other_extension(ext)).then(response => { const data = response.body; cy.visit(`${this.Urls.browse_content(data.sha1)}?path=file.${ext}`); cy.get('.swh-content img') .should('be.visible'); }); }); }); }); describe('PDF rendering test', function() { function sum(previousValue, currentValue) { return previousValue + currentValue; } it(`should render a PDF file`, function() { cy.request(this.Urls.tests_content_other_extension('pdf')).then(response => { const data = response.body; cy.visit(`${this.Urls.browse_content(data.sha1)}?path=file.pdf`); cy.get('.swh-content canvas') .wait(2000) .then(canvas => { let width = canvas[0].width; let height = canvas[0].height; let context = canvas[0].getContext('2d'); let imgData = context.getImageData(0, 0, width, height); assert.notEqual(imgData.data.reduce(sum), 0); }); }); }); }); describe('Jupyter notebook rendering test', function() { it(`should render a notebook file to HTML`, function() { cy.request(this.Urls.tests_content_other_extension('ipynb')).then(response => { const data = response.body; cy.visit(`${this.Urls.browse_content(data.sha1)}?path=file.ipynb`); cy.get('.nb-notebook') .should('be.visible') .and('not.be.empty'); cy.get('.nb-cell.nb-markdown-cell') .should('be.visible') .and('not.be.empty'); cy.get('.nb-cell.nb-code-cell') .should('be.visible') .and('not.be.empty'); cy.get('.MathJax') .should('be.visible') .and('not.be.empty'); }); }); }); diff --git a/cypress/utils/index.js b/cypress/utils/index.js index cb8cf7f0..dd5386b7 100644 --- a/cypress/utils/index.js +++ b/cypress/utils/index.js @@ -1,52 +1,54 @@ /** * Copyright (C) 2019 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ import axios from 'axios'; export async function httpGetJson(url) { const response = await axios.get(url); return response.data; } /** * Converts string with Time information * to an object with Time information */ export function getTime(text) { const date = new Date(text); function pad(n) { return n < 10 ? '0' + n : n; } const time = { date: date.getUTCDate(), month: date.getUTCMonth(), monthName: date.toLocaleString('en', { month: 'long' }), year: date.getUTCFullYear(), hours: pad(date.getUTCHours()), minutes: pad(date.getUTCMinutes()) }; return time; } export function checkLanguageHighlighting(language) { cy.get('code') .should('be.visible') .and('have.class', 'hljs') .and('have.class', language) .and('not.be.empty') .find('table.hljs-ln') .should('be.visible') .and('not.be.empty'); } export function random(start, end) { const range = end - start; return Math.floor(Math.random() * range) + start; } + +export const describeSlowTests = Cypress.env('SKIP_SLOW_TESTS') === 1 ? describe.skip : describe;