From 77d286ebb680c7a1a0b6a083583dd75aa45fa73f Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 5 Oct 2019 19:07:50 +0200 Subject: [PATCH] Introduce Cypress Signed-off-by: Thomas Citharel --- .gitlab-ci.yml | 25 + config/config.exs | 10 +- config/dev.exs | 2 +- config/e2e.exs | 24 + config/prod.exs | 2 +- config/test.exs | 2 +- docker/tests/Dockerfile | 6 +- js/.gitignore | 2 + js/cypress.json | 7 + js/package.json | 6 +- js/src/App.vue | 3 +- js/src/components/NavBar.vue | 2 +- js/src/views/Home.vue | 179 ++-- js/src/views/User/Register.vue | 168 ++-- js/tests/e2e/plugins/index.js | 24 + js/tests/e2e/specs/browser-language.js | 2 + js/tests/e2e/specs/dashboard.js | 42 + js/tests/e2e/specs/login.js | 45 + js/tests/e2e/specs/register.js | 69 ++ js/tests/e2e/specs/test.js | 14 - js/tests/e2e/support/commands.js | 129 +++ js/tests/e2e/support/index.js | 20 + js/tests/e2e/tsconfig.json | 12 + js/yarn.lock | 1073 ++++++++++-------------- lib/mobilizon_web/endpoint.ex | 14 +- lib/mobilizon_web/router.ex | 2 +- mix.exs | 2 +- 27 files changed, 1041 insertions(+), 845 deletions(-) create mode 100644 config/e2e.exs create mode 100644 js/cypress.json create mode 100644 js/tests/e2e/plugins/index.js create mode 100644 js/tests/e2e/specs/browser-language.js create mode 100644 js/tests/e2e/specs/dashboard.js create mode 100644 js/tests/e2e/specs/login.js create mode 100644 js/tests/e2e/specs/register.js delete mode 100644 js/tests/e2e/specs/test.js create mode 100644 js/tests/e2e/support/commands.js create mode 100644 js/tests/e2e/support/index.js create mode 100644 js/tests/e2e/tsconfig.json diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4a75f9b6d..ab9fcdfd6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,7 @@ stages: - deps - front - back + - e2e - deploy variables: @@ -19,6 +20,7 @@ variables: MOBILIZON_DATABASE_DBNAME: $POSTGRES_DB MOBILIZON_DATABASE_HOST: $POSTGRES_HOST GEOLITE_CITIES_PATH: "/usr/share/GeoIP/GeoLite2-City.mmdb" + MOBILIZON_INSTANCE_REGISTRATIONS_OPEN: "true" setup_elixir_deps: stage: deps @@ -144,3 +146,26 @@ mix: paths: - deps - _build + +e2e: + stage: e2e + services: + - name: mdillon/postgis:10 + alias: postgres + script: + - mix deps.get + - cd js + - yarn install + - yarn run build + - cd ../ + - MIX_ENV=e2e mix ecto.create + - MIX_ENV=e2e mix ecto.migrate + - MIX_ENV=e2e mix phx.server & + - cd js + - npx wait-on http://localhost:4000 + - npx cypress run --record --parallel --key $CYPRESS_KEY + artifacts: + expire_in: 2 day + paths: + - js/tests/e2e/screenshots/**/*.png + - js/tests/e2e/videos/**/*.mp4 \ No newline at end of file diff --git a/config/config.exs b/config/config.exs index 96e3c20be..412f3d158 100644 --- a/config/config.exs +++ b/config/config.exs @@ -3,7 +3,7 @@ # # This configuration file is loaded before any dependency and # is restricted to this project. -use Mix.Config +import Config # General application configuration config :mobilizon, @@ -71,10 +71,6 @@ config :logger, :console, format: "$time $metadata[$level] $message\n", metadata: [:request_id] -# Import environment specific config. This must remain at the bottom -# of this file so it overrides the configuration defined above. -import_config "#{Mix.env()}.exs" - config :mobilizon, MobilizonWeb.Guardian, issuer: "mobilizon", secret_key: "ty0WM7YBE3ojvxoUQxo8AERrNpfbXnIJ82ovkPdqbUFw31T5LcK8wGjaOiReVQjo" @@ -136,3 +132,7 @@ config :mobilizon, Mobilizon.Service.Geospatial.GoogleMaps, config :mobilizon, Mobilizon.Service.Geospatial.MapQuest, api_key: System.get_env("GEOSPATIAL_MAP_QUEST_API_KEY") || nil + +# Import environment specific config. This must remain at the bottom +# of this file so it overrides the configuration defined above. +import_config "#{Mix.env()}.exs" diff --git a/config/dev.exs b/config/dev.exs index ae2ab7e5e..c50f236af 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config # For development, we disable any cache and enable # debugging and code reloading. diff --git a/config/e2e.exs b/config/e2e.exs new file mode 100644 index 000000000..5af461115 --- /dev/null +++ b/config/e2e.exs @@ -0,0 +1,24 @@ +import Config + +import_config "dev.exs" + +config :mobilizon, MobilizonWeb.Endpoint, + http: [ + port: 4000 + ], + url: [ + host: "localhost", + port: 4000, + scheme: "http" + ], + debug_errors: true, + code_reloader: false, + check_origin: false, + # Somehow this can't be merged properly with the dev config some we got this… + watchers: [ + yarn: [cd: Path.expand("../js", __DIR__)] + ] + +config :mobilizon, sql_sandbox: true + +config :mobilizon, Mobilizon.Storage.Repo, pool: Ecto.Adapters.SQL.Sandbox diff --git a/config/prod.exs b/config/prod.exs index 334790b5e..32c8f3d53 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config config :mobilizon, MobilizonWeb.Endpoint, http: [:inet6, port: System.get_env("MOBILIZON_INSTANCE_PORT") || 4000], diff --git a/config/test.exs b/config/test.exs index c72f44b4d..575bd1e92 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config config :mobilizon, :instance, name: "Test instance", diff --git a/docker/tests/Dockerfile b/docker/tests/Dockerfile index a2abcb6af..925b8808a 100644 --- a/docker/tests/Dockerfile +++ b/docker/tests/Dockerfile @@ -1,10 +1,10 @@ FROM elixir:latest LABEL maintainer="Thomas Citharel " -ENV REFRESHED_AT=2019-07-03 -RUN apt-get update -yq && apt-get install -yq build-essential inotify-tools postgresql-client git curl gnupg +ENV REFRESHED_AT=2019-10-06 +RUN apt-get update -yq && apt-get install -yq build-essential inotify-tools postgresql-client git curl gnupg xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 RUN curl -sL https://deb.nodesource.com/setup_10.x | bash && apt-get install nodejs -yq -RUN npm install -g yarn +RUN npm install -g yarn wait-on RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN mix local.hex --force && mix local.rebar --force RUN curl http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz --output GeoLite2-City.tar.gz -s && tar zxf GeoLite2-City.tar.gz && mkdir -p /usr/share/GeoIP && mv GeoLite2-City_*/GeoLite2-City.mmdb /usr/share/GeoIP/GeoLite2-City.mmdb diff --git a/js/.gitignore b/js/.gitignore index 03808dce1..40fba83f0 100644 --- a/js/.gitignore +++ b/js/.gitignore @@ -3,6 +3,8 @@ node_modules /dist /tests/e2e/reports/ +/tests/e2e/screenshots/ +/tests/e2e/videos/ selenium-debug.log # local env files diff --git a/js/cypress.json b/js/cypress.json new file mode 100644 index 000000000..17b7cd741 --- /dev/null +++ b/js/cypress.json @@ -0,0 +1,7 @@ +{ + "pluginsFile": "tests/e2e/plugins/index.js", + "projectId": "86dpkx", + "baseUrl": "http://localhost:4000", + "viewportWidth": 1920, + "viewportHeight": 1080 +} diff --git a/js/package.json b/js/package.json index 2a82d43dd..f34498b43 100644 --- a/js/package.json +++ b/js/package.json @@ -4,11 +4,11 @@ "private": true, "scripts": { "build": "vue-cli-service build", + "test:unit": "vue-cli-service test:unit", + "test:e2e": "vue-cli-service test:e2e", "lint": "vue-cli-service lint", "analyze-bundle": "yarn run build -- --report-json && webpack-bundle-analyzer ../priv/static/report.json", "dev": "vue-cli-service build --watch", - "test:e2e": "vue-cli-service test:e2e", - "test:unit": "vue-cli-service test:unit", "vue-i18n-extract": "vue-i18n-extract" }, "dependencies": { @@ -44,7 +44,7 @@ "@types/lodash": "^4.14.141", "@types/mocha": "^5.2.6", "@vue/cli-plugin-babel": "^3.6.0", - "@vue/cli-plugin-e2e-nightwatch": "^3.6.0", + "@vue/cli-plugin-e2e-cypress": "^4.0.0-rc.7", "@vue/cli-plugin-pwa": "^3.6.0", "@vue/cli-plugin-typescript": "^3.6.0", "@vue/cli-plugin-unit-mocha": "^3.6.0", diff --git a/js/src/App.vue b/js/src/App.vue index 45a8cb599..c71c69238 100644 --- a/js/src/App.vue +++ b/js/src/App.vue @@ -87,6 +87,7 @@ export default class App extends Vue { } body { - background: #f6f7f8; + // background: #f7f8fa; + background: #ebebeb; } diff --git a/js/src/components/NavBar.vue b/js/src/components/NavBar.vue index 071cec7b7..e3dee29bd 100644 --- a/js/src/components/NavBar.vue +++ b/js/src/components/NavBar.vue @@ -1,5 +1,5 @@