Open platform to collect and prioritize feedback
enhancement: separated e2e server tests + SSR test (#991)
Guilherme Oenning0433b8d76963
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 8f44427ef..d92d23f48 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -96,8 +96,8 @@ jobs:name: fider-imagepath: out/- test-e2e:- name: test-e2e+ test-e2e-ui:+ name: test-e2e-uiruns-on: ubuntu-latestneeds: [build]services:@@ -149,6 +149,60 @@ jobs:- run: npx playwright install-deps $BROWSERenv:BROWSER: ${{ matrix.browser }}- - run: make test-e2e+ - run: make test-e2e-uienv:BROWSER: ${{ matrix.browser }}++ test-e2e-server:+ name: test-e2e-server+ runs-on: ubuntu-latest+ needs: [build]+ services:+ mailhog:+ image: mailhog/mailhog:latest+ ports:+ - "8025:8025"+ - "1025:1025"+ postgres:+ image: postgres:12+ env:+ POSTGRES_USER: fider_ci+ POSTGRES_PASSWORD: fider_ci_pw+ POSTGRES_DB: fider_ci+ ports:+ - 5432:5432+ options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5+ steps:+ - uses: actions/checkout@v2+ - name: Use Node.js 16.x+ uses: actions/setup-node@v1+ with:+ node-version: 16.x+ - uses: actions/download-artifact@v2+ with:+ name: fider-image+ path: ./out+ - run: docker load --input ./out/fider-image.tar+ - run: |+ docker run \+ --pull never \+ -p 3000:3000 \+ --env DATABASE_URL=postgres://fider_ci:fider_ci_pw@postgres:5432/fider_ci?sslmode=disable \+ --env JWT_SECRET=not_so_secret \+ --env HOST_MODE=multi \+ --env HOST_DOMAIN=dev.fider.io \+ --env SSL_CERT=dev-fider-io.crt \+ --env SSL_CERT_KEY=dev-fider-io.key \+ --env [email protected] \+ --env EMAIL_SMTP_HOST=mailhog \+ --env EMAIL_SMTP_PORT=1025 \+ -d --network "${{ job.container.network }}" \+ -v "$PWD"/etc:/app/etc \+ fider-image+ - run: npm ci+ - run: npx playwright install-deps chromium+ env:+ BROWSER: chromium+ - run: make test-e2e-server+ env:+ BROWSER: chromiumdiff --git a/Makefile b/Makefileindex 0255f1274..3e4e1676c 100644--- a/Makefile+++ b/Makefile@@ -44,15 +44,22 @@ test-server: build-server build-ssr ## Run all server teststest-ui: ## Run all UI testsTZ=GMT npx jest ./public-test-e2e: ## Run all E2E tests- npx cucumber-js e2e/**/*.feature --require-module ts-node/register --require 'e2e/**/*.ts' --publish-quiet-coverage-server: build-server build-ssr ## Run all server tests (with code coverage)godotenv -f .test.env ./fider migrategodotenv -f .test.env go test ./... -coverprofile=cover.out -coverpkg=all -p=8 -race+##@ E2E Testing++test-e2e-server: ## Run all E2E tests+ npx cucumber-js e2e/features/server/**/*.feature --require-module ts-node/register --require 'e2e/**/*.ts' --publish-quiet++test-e2e-ui: ## Run all E2E tests+ npx cucumber-js e2e/features/ui/**/*.feature --require-module ts-node/register --require 'e2e/**/*.ts' --publish-quiet+++##@ Running (Watch Mode)watch:diff --git a/e2e/features/http.feature b/e2e/features/server/http.featuresimilarity index 100%rename from e2e/features/http.featurerename to e2e/features/server/http.featurediff --git a/e2e/features/server/ssr.feature b/e2e/features/server/ssr.featurenew file mode 100644index 000000000..3d1fc98b6--- /dev/null+++ b/e2e/features/server/ssr.feature@@ -0,0 +1,19 @@+Feature: SSR++ Scenario: Home page with a normal browser User-Agent should be client-side rendered+ Given I prepare a "GET" request to "/"+ And I set the "User-Agent" header to "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"+ When I send the request+ Then I should see http status 200+ And I should not see ">Powered by Fider</a>" on the response body+ And I should see "This website requires JavaScript, please enable and reload the page." on the response body+ And I should see "/assets/js/vendor" on the response body++ Scenario: Home page with a GoogleBot User-Agent should be server-side rendered+ Given I prepare a "GET" request to "/"+ And I set the "User-Agent" header to "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"+ When I send the request+ Then I should see http status 200+ And I should see ">Powered by Fider</a>" on the response body+ And I should not see "This website requires JavaScript, please enable and reload the page." on the response body+ And I should not see "/assets/js/vendor" on the response bodydiff --git a/e2e/features/post.feature b/e2e/features/ui/post.featuresimilarity index 100%rename from e2e/features/post.featurerename to e2e/features/ui/post.featurediff --git a/e2e/step_definitions/http.steps.ts b/e2e/step_definitions/http.steps.tsindex c5a344393..74f36c1c2 100644--- a/e2e/step_definitions/http.steps.ts+++ b/e2e/step_definitions/http.steps.ts@@ -1,10 +1,39 @@-import { Given, Then } from "@cucumber/cucumber"+import { Given, Then, When } from "@cucumber/cucumber"+import { FiderWorld } from "e2e/world"import expect from "expect"+let requestUrl: string+let requestOpts: RequestInit+let requestHeaders: Headers+let response: Response+let responseBody: string++const getFullUrl = (world: FiderWorld, url: string): string => {+ return url.startsWith("/") ? `https://${world.tenantName}.dev.fider.io:3000${url}` : url+}++Given("I prepare a {string} request to {string}", async function (this: FiderWorld, method: string, url: string) {+ requestUrl = getFullUrl(this, url)+ requestHeaders = new Headers()+ requestOpts = {+ method,+ headers: {},+ }+})++Given("I set the {string} header to {string}", async function (headerName: string, headerValue: string) {+ requestHeaders.set(headerName, headerValue)+})-Given("I send a {string} request to {string}", async function (method: string, path: string) {- response = await fetch(`https://login.dev.fider.io:3000${path}`, { method })+Given("I send a {string} request to {string}", async function (this: FiderWorld, method: string, url: string) {+ response = await fetch(getFullUrl(this, url), { method })+ responseBody = await response.text()+})++When("I send the request", async function () {+ response = await fetch(requestUrl, { ...requestOpts, headers: requestHeaders })+ responseBody = await response.text()})Then("I should see http status {int}", async function (code: number) {@@ -18,3 +47,11 @@ Then("I should not see a {string} header", async function (headerName: string) {Then("I should see a {string} header with value {string}", async function (headerName: string, headerValue: string) {expect(response.headers.get(headerName)).toBe(headerValue)})++Then("I should see {string} on the response body", async function (substring: string) {+ expect(responseBody).toContain(substring)+})++Then("I should not see {string} on the response body", async function (substring: string) {+ expect(responseBody).not.toContain(substring)+})