From 16fa6259eac1a8c58761187348789a71e776572c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 30 Nov 2021 17:22:17 +0100 Subject: [PATCH 1/3] :construction: Update docker deps and start working on test coverage. --- .gitignore | 2 ++ backend/test/app/test_helpers.clj | 1 + common/package.json | 6 ++++++ common/shadow-cljs.edn | 9 ++++++-- .../common/{data_test.clj => data_test.cljc} | 15 +++++-------- docker/devenv/Dockerfile | 4 ++-- frontend/shadow-cljs.edn | 21 +++++++++++++++---- 7 files changed, 40 insertions(+), 18 deletions(-) rename common/test/app/common/{data_test.clj => data_test.cljc} (86%) diff --git a/.gitignore b/.gitignore index d11830e816..4217d6130a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ figwheel_server.log .nrepl-port .cpcache .rebel_readline_history +.nyc_output /vendor/**/target /cd.md node_modules @@ -32,6 +33,7 @@ node_modules /docker/images/bundle* /common/.shadow-cljs /common/target +/common/coverage /.clj-kondo/.cache /bundle* /media diff --git a/backend/test/app/test_helpers.clj b/backend/test/app/test_helpers.clj index f503e5d663..9161296d18 100644 --- a/backend/test/app/test_helpers.clj +++ b/backend/test/app/test_helpers.clj @@ -57,6 +57,7 @@ :app.http/server :app.http/router :app.notifications/handler + :app.loggers.sentry/reporter :app.http.oauth/google :app.http.oauth/gitlab :app.http.oauth/github diff --git a/common/package.json b/common/package.json index 4344351821..494c86655a 100644 --- a/common/package.json +++ b/common/package.json @@ -6,6 +6,12 @@ "dependencies": { "luxon": "^1.27.0" }, + "scripts": { + "compile-and-watch-test": "clojure -M:dev:shadow-cljs watch test", + "compile-test": "clojure -M:dev:shadow-cljs compile test --config-merge '{:autorun false}'", + "run-test": "node target/test.js", + "test": "yarn run compile-test && yarn run run-test" + }, "devDependencies": { "source-map-support": "^0.5.19", "ws": "^7.4.6" diff --git a/common/shadow-cljs.edn b/common/shadow-cljs.edn index e6bcd7175c..d7e55017c8 100644 --- a/common/shadow-cljs.edn +++ b/common/shadow-cljs.edn @@ -6,12 +6,17 @@ :builds {:test {:target :node-test - :output-to "target/tests.js" + :output-to "target/test.js" + :output-dir "target/test/" :ns-regexp "^app.common.*-test$" - ;; :autorun true + :autorun true :compiler-options {:output-feature-set :es-next :output-wrapper false + :source-map true + :source-map-include-sources-content true + :source-map-detail-level :all :warnings {:fn-deprecated false}}}}} + diff --git a/common/test/app/common/data_test.clj b/common/test/app/common/data_test.cljc similarity index 86% rename from common/test/app/common/data_test.clj rename to common/test/app/common/data_test.cljc index 8a85bb97b1..4cf9c661f2 100644 --- a/common/test/app/common/data_test.clj +++ b/common/test/app/common/data_test.cljc @@ -10,16 +10,11 @@ [clojure.test :as t])) (t/deftest concat-vec - (t/is (= [1 2 3] - (d/concat-vec [1] #{2} [3]))) - - (t/is (= [1 2] - (d/concat-vec '(1) [2]))) - - (t/is (= [1] - (d/concat-vec [1]))) - - (t/is (= [] (d/concat-vec)))) + (t/is (= [] (d/concat-vec))) + (t/is (= [1] (d/concat-vec [1]))) + (t/is (= [1] (d/concat-vec #{1}))) + (t/is (= [1 2] (d/concat-vec [1] #{2}))) + (t/is (= [1 2] (d/concat-vec '(1) [2])))) (t/deftest concat-set (t/is (= #{} (d/concat-set))) diff --git a/docker/devenv/Dockerfile b/docker/devenv/Dockerfile index 602c6aa6ba..3e100a612e 100644 --- a/docker/devenv/Dockerfile +++ b/docker/devenv/Dockerfile @@ -3,10 +3,10 @@ LABEL maintainer="Andrey Antukh " ARG DEBIAN_FRONTEND=noninteractive -ENV NODE_VERSION=v14.17.6 \ +ENV NODE_VERSION=v16.13.0 \ CLOJURE_VERSION=1.10.3.967 \ CLJKONDO_VERSION=2021.10.19 \ - BABASHKA_VERSION=0.6.1 \ + BABASHKA_VERSION=0.6.6 \ LANG=en_US.UTF-8 \ LC_ALL=en_US.UTF-8 diff --git a/frontend/shadow-cljs.edn b/frontend/shadow-cljs.edn index 679a30a5dd..6dda88e7f4 100644 --- a/frontend/shadow-cljs.edn +++ b/frontend/shadow-cljs.edn @@ -65,7 +65,20 @@ :ns-regexp "^app.*-test$" ;; :autorun true - :compiler-options - {:output-feature-set :es8 - :output-wrapper false - :warnings {:fn-deprecated false}}}}} + :release + {:compiler-options + {:pseudo-names true + :pretty-print true + :source-map true + :source-map-include-sources-content true + :source-map-detail-level :all + :optimizations :whitespace + :fn-invoke-direct true}} + + :dev + {:compiler-options + {:output-feature-set :es8 + :output-wrapper false}} + + }}} + From 1cc3819e65f787f76ede516b161dc62f8bba9eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Wed, 1 Dec 2021 13:38:09 +0100 Subject: [PATCH 2/3] :test_tube: Add e2e tests with Cypress --- .gitignore | 1 + docker/devenv/Dockerfile | 1 + frontend/cypress.json | 1 + frontend/cypress/fixtures/example.json | 5 + .../1-getting-started/todo.spec.js | 143 +++++ .../2-advanced-examples/actions.spec.js | 299 +++++++++ .../2-advanced-examples/aliasing.spec.js | 39 ++ .../2-advanced-examples/assertions.spec.js | 177 ++++++ .../2-advanced-examples/connectors.spec.js | 97 +++ .../2-advanced-examples/cookies.spec.js | 77 +++ .../2-advanced-examples/cypress_api.spec.js | 202 ++++++ .../2-advanced-examples/files.spec.js | 88 +++ .../2-advanced-examples/local_storage.spec.js | 52 ++ .../2-advanced-examples/location.spec.js | 32 + .../2-advanced-examples/misc.spec.js | 104 ++++ .../2-advanced-examples/navigation.spec.js | 56 ++ .../network_requests.spec.js | 163 +++++ .../2-advanced-examples/querying.spec.js | 114 ++++ .../spies_stubs_clocks.spec.js | 205 ++++++ .../2-advanced-examples/traversal.spec.js | 121 ++++ .../2-advanced-examples/utilities.spec.js | 110 ++++ .../2-advanced-examples/viewport.spec.js | 59 ++ .../2-advanced-examples/waiting.spec.js | 31 + .../2-advanced-examples/window.spec.js | 22 + .../cypress/integration/01-auth/login.spec.js | 21 + frontend/cypress/plugins/index.js | 22 + frontend/cypress/support/commands.js | 25 + frontend/cypress/support/index.js | 20 + frontend/cypress/videos/.gitkeep | 0 frontend/package.json | 3 + frontend/yarn.lock | 589 +++++++++++++++++- 31 files changed, 2869 insertions(+), 10 deletions(-) create mode 100644 frontend/cypress.json create mode 100644 frontend/cypress/fixtures/example.json create mode 100644 frontend/cypress/integration-examples/1-getting-started/todo.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/actions.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/aliasing.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/assertions.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/connectors.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/cookies.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/cypress_api.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/files.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/local_storage.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/location.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/misc.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/navigation.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/network_requests.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/querying.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/spies_stubs_clocks.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/traversal.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/utilities.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/viewport.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/waiting.spec.js create mode 100644 frontend/cypress/integration-examples/2-advanced-examples/window.spec.js create mode 100644 frontend/cypress/integration/01-auth/login.spec.js create mode 100644 frontend/cypress/plugins/index.js create mode 100644 frontend/cypress/support/commands.js create mode 100644 frontend/cypress/support/index.js create mode 100644 frontend/cypress/videos/.gitkeep diff --git a/.gitignore b/.gitignore index 4217d6130a..04e1da56b8 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,4 @@ node_modules .calva .clj-kondo .lsp +/frontend/cypress/videos/*/ diff --git a/docker/devenv/Dockerfile b/docker/devenv/Dockerfile index 3e100a612e..60452fab24 100644 --- a/docker/devenv/Dockerfile +++ b/docker/devenv/Dockerfile @@ -97,6 +97,7 @@ RUN set -ex; \ libappindicator1 \ libnss3 \ libgbm1 \ + xvfb \ ; \ rm -rf /var/lib/apt/lists/*; diff --git a/frontend/cypress.json b/frontend/cypress.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/frontend/cypress.json @@ -0,0 +1 @@ +{} diff --git a/frontend/cypress/fixtures/example.json b/frontend/cypress/fixtures/example.json new file mode 100644 index 0000000000..02e4254378 --- /dev/null +++ b/frontend/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/frontend/cypress/integration-examples/1-getting-started/todo.spec.js b/frontend/cypress/integration-examples/1-getting-started/todo.spec.js new file mode 100644 index 0000000000..4768ff923e --- /dev/null +++ b/frontend/cypress/integration-examples/1-getting-started/todo.spec.js @@ -0,0 +1,143 @@ +/// + +// Welcome to Cypress! +// +// This spec file contains a variety of sample tests +// for a todo list app that are designed to demonstrate +// the power of writing tests in Cypress. +// +// To learn more about how Cypress works and +// what makes it such an awesome testing tool, +// please read our getting started guide: +// https://on.cypress.io/introduction-to-cypress + +describe('example to-do app', () => { + beforeEach(() => { + // Cypress starts out with a blank slate for each test + // so we must tell it to visit our website with the `cy.visit()` command. + // Since we want to visit the same URL at the start of all our tests, + // we include it in our beforeEach function so that it runs before each test + cy.visit('https://example.cypress.io/todo') + }) + + it('displays two todo items by default', () => { + // We use the `cy.get()` command to get all elements that match the selector. + // Then, we use `should` to assert that there are two matched items, + // which are the two default items. + cy.get('.todo-list li').should('have.length', 2) + + // We can go even further and check that the default todos each contain + // the correct text. We use the `first` and `last` functions + // to get just the first and last matched elements individually, + // and then perform an assertion with `should`. + cy.get('.todo-list li').first().should('have.text', 'Pay electric bill') + cy.get('.todo-list li').last().should('have.text', 'Walk the dog') + }) + + it('can add new todo items', () => { + // We'll store our item text in a variable so we can reuse it + const newItem = 'Feed the cat' + + // Let's get the input element and use the `type` command to + // input our new list item. After typing the content of our item, + // we need to type the enter key as well in order to submit the input. + // This input has a data-test attribute so we'll use that to select the + // element in accordance with best practices: + // https://on.cypress.io/selecting-elements + cy.get('[data-test=new-todo]').type(`${newItem}{enter}`) + + // Now that we've typed our new item, let's check that it actually was added to the list. + // Since it's the newest item, it should exist as the last element in the list. + // In addition, with the two default items, we should have a total of 3 elements in the list. + // Since assertions yield the element that was asserted on, + // we can chain both of these assertions together into a single statement. + cy.get('.todo-list li') + .should('have.length', 3) + .last() + .should('have.text', newItem) + }) + + it('can check off an item as completed', () => { + // In addition to using the `get` command to get an element by selector, + // we can also use the `contains` command to get an element by its contents. + // However, this will yield the