Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cypress as dep and initialize first test #1342

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 20 additions & 20 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ steps:
- name: build-frontend
image: node:16
when:
event: push
event: [push]
environment:
LANG: C.UTF-8
commands:
Expand All @@ -18,7 +18,7 @@ steps:
- name: typescript
image: node:16
when:
event: push
event: [push]
environment:
LANG: C.UTF-8
depends_on:
Expand All @@ -27,9 +27,9 @@ steps:
- yarn types

- name: missing-migrations
image: abakus/lego-testbase:python3.9
image: abakus/lego-testbase:poetry
when:
event: push
event: [push]
environment:
LANG: C.UTF-8
DATABASE: database
Expand All @@ -38,38 +38,38 @@ steps:
- tox -e missing-migrations

- name: tests
image: abakus/lego-testbase:python3.9
image: abakus/lego-testbase:poetry
when:
event: push
event: [push]
environment:
LANG: C.UTF-8
DATABASE: database
commands:
- tox -e tests

- name: isort
image: abakus/lego-testbase:python3.9
image: abakus/lego-testbase:poetry
when:
event: push
event: [push]
environment:
LANG: C.UTF-8
commands:
- tox -e isort

- name: black
image: abakus/lego-testbase:python3.9
pull: true
image: abakus/lego-testbase:poetry
pull: if-not-exists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this is only added to this step? Just genuinely wondering

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm good question!

The drone docs aren't very clear on what the default value of pull is imo, but the way I understand the docs, we wouldn't really need to use the pull attribute as long as we're not tagging out images with :latest, unless we do not want it to cache.
So the default behavior for non-latest tags appears to be if-not-exists.

But regarding why it's just on this step, I suppose it is because this file was originally copied from lego, and in https://github.com/webkom/lego/blob/master/.drone.yml#L69-L92 the only two steps that have the pull attribute set are black and mypy, and mypy is not implemented in admissions.

pull: true does not appear to be a valid tag however, but if it is processed at all I would guess it reads as pull: always, which would mean unnecessary fetching of docker images that are cached

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I see. I've had mixed experiences with Drone's "cache", so imo. it's fine to leave it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Although I guess we might eventually decide on whether or not we type out the configuration or not - as all the steps should now be configured the same way, but black is the only one where it's written out

when:
event: push
event: [push]
environment:
LANG: C.UTF-8
commands:
- tox -e black

- name: coverage
image: abakus/lego-testbase:python3.9
image: abakus/lego-testbase:poetry
when:
event: push
event: [push]
depends_on:
- tests
environment:
Expand All @@ -84,8 +84,8 @@ steps:
branch:
- staging
- prod
status: success
event: push
status: [success]
event: [push]
depends_on:
- build-frontend
- missing-migrations
Expand All @@ -104,7 +104,7 @@ steps:
- latest
- version-${DRONE_COMMIT_SHA:0:7}
build_args:
RELEASE: ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7}
- "RELEASE=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7}"

- name: Deploy staging
image: abakus/ansible-deploy
Expand All @@ -113,8 +113,8 @@ steps:
when:
branch:
- staging
event: push
status: success
event: [push]
status: [success]
settings:
playbook: /infrastructure/esas/playbooks/deploy.yml
repository:
Expand All @@ -136,8 +136,8 @@ steps:
when:
branch:
- prod
event: push
status: success
event: [push]
status: [success]
settings:
playbook: /infrastructure/esas/playbooks/deploy.yml
repository:
Expand Down
7 changes: 7 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
baseUrl: "http://127.0.0.1:5000",
},
});
12 changes: 12 additions & 0 deletions cypress/e2e/landing_page_spec.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe("landing page spec", () => {
before(() => {
cy.clearDb();
});

it("successfully loads", () => {
cy.visit("/");
cy.contains("Opptak");
cy.contains("Ingen 氓pne opptak for 酶yeblikket");
cy.contains("Logg inn");
});
});
37 changes: 37 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }

Cypress.Commands.add("clearDb", () => {
cy.exec("poetry run python manage.py flush --no-input");
});
16 changes: 16 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

import "./commands";
7 changes: 7 additions & 0 deletions cypress/support/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />

declare namespace Cypress {
interface Chainable {
clearDb(): Chainable<void>;
}
}
8 changes: 8 additions & 0 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "node"]
},
"include": ["**/*.ts"]
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"lint": "yarn lint:prettier && yarn lint:js && yarn lint:css",
"lint:js": "eslint '**/*.{ts,tsx}' --ignore-path .prettierignore",
"lint:css": "stylelint './frontend/**/*.css'",
"types": "tsc"
"types": "tsc",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
},
"dependencies": {
"@babel/polyfill": "^7.0.0",
Expand Down Expand Up @@ -44,7 +46,9 @@
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.62.0",
"@vitejs/plugin-react": "^4.0.2",
"cypress": "^13.6.2",
"eslint": "^8.42.0",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-react": "^7.32.2",
"prettier": "2.8.8",
"stylelint": "^15.10.1",
Expand Down