-
Notifications
You must be signed in to change notification settings - Fork 521
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Morten Ramfjords Workflow PR #401
base: master
Are you sure you want to change the base?
Changes from all commits
9f3b5ac
81952fc
5d6837a
cdbc837
459ed73
39a6192
fdb20e2
e1baef9
1a9dc85
0a08a5b
bbf5912
bbd8ba8
40ddca5
0825be2
c1b98a2
5bfac0d
8349b33
ee60385
41bfe5e
8b5b9a3
392539b
95edcd5
31b7208
c362bd7
053b4e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:prettier/recommended" | ||
], | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"**/*.test.js", | ||
"**/*.cy.js" | ||
], | ||
"env": { | ||
"jest": true, | ||
"cypress/globals": true | ||
}, | ||
"plugins": [ | ||
"prettier", | ||
"jest", | ||
"cypress" | ||
], | ||
"extends": [ | ||
"plugin:jest/recommended", | ||
"plugin:cypress/recommended" | ||
], | ||
"rules": { | ||
"jest/prefer-expect-assertions": "off", | ||
"cypress/no-unnecessary-waiting": "off", | ||
"no-unused-vars": "off" | ||
} | ||
} | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"rules": {} | ||
} | ||
Comment on lines
+1
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ESLint configuration looks good overall, but there's a minor issue. It's a best practice to always end your files with a newline. This is because some tools like "rules": {}
- 42: }
+ 42: }\n Also, you've turned off the rule |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Automated Unit Testing | ||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
run-unit-tests: | ||
name: Run Unit Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout under $GITHUB_WORKSPACE | ||
uses: actions/checkout@main | ||
|
||
- name: Set up NodeJS | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 16 | ||
|
||
- name: Install all dependencies | ||
run: npm install | ||
|
||
- name: Run Tests | ||
run: npm run test-unit | ||
# new |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Automated E2E Testing | ||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
jobs: | ||
run-e2e-tests: | ||
name: Run E2E Tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout under $GITHUB_WORKSPACE | ||
uses: actions/checkout@main | ||
|
||
- name: run cypress tests with electron | ||
uses: cypress-io/github-action@v4 | ||
with: | ||
browser: electron |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/node_modules | ||
/dist | ||
/dist | ||
.eslintcache |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lint-staged |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Social media client | ||
|
||
## Frameworks, tools and plugins | ||
|
||
### eslint | ||
|
||
ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, with the goal of making code more consistent and avoiding bugs. | ||
|
||
### Prettier | ||
|
||
Prettier is an opinionated code formatter that supports a lot of different programming languages, like: JavaScript. JSON. JSX. CSS. | ||
|
||
### Husky | ||
|
||
Husky empowers developers to automate pre-commit checks, enhancing code quality and productivity. | ||
|
||
### Jest | ||
|
||
Jest is a JavaScript testing framework is used for testing applications, including login and logout functionality in this application-case. | ||
|
||
### Cypress | ||
|
||
Cypress is an end-to-end testing framework for web applications. In the context of testing login and logout functionality. | ||
|
||
## Installation and configuration | ||
|
||
### Clone the repository | ||
|
||
``` | ||
git clone 'repo' | ||
``` | ||
|
||
### Install all the available dependencies from package.JSON | ||
|
||
``` | ||
npm i | ||
``` | ||
|
||
### Activate the SASS | ||
|
||
``` | ||
npm run build | ||
``` | ||
|
||
## Jest & Cypress | ||
|
||
- Run all test dependencies | ||
|
||
``` | ||
npm run test | ||
``` | ||
|
||
### Eslint | ||
|
||
- Install, fix and format | ||
|
||
``` | ||
npm run lint | ||
npm run lint-fix | ||
npm run format | ||
``` | ||
|
||
## Jest | ||
|
||
- Run isolated Jest-test | ||
|
||
``` | ||
npm run test-unit | ||
``` | ||
|
||
## Cypress E2E | ||
|
||
- Run isolated Cypress-test | ||
|
||
``` | ||
npm run test-e2e | ||
``` | ||
|
||
## Husky | ||
|
||
- commit hooks function | ||
|
||
``` | ||
git add example.file(s) | ||
git commit -m "test your error" | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": "current" | ||
} | ||
} | ||
] | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { defineConfig } = require("cypress"); | ||
|
||
module.exports = defineConfig({ | ||
e2e: { | ||
baseUrl: "http://localhost:8080", | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
describe("Login spec", () => { | ||
beforeEach(() => { | ||
cy.visit("/"); | ||
cy.wait(1000); | ||
cy.get("#registerForm").within(() => { | ||
cy.get("button[data-bs-target='#loginModal']:visible").click(); | ||
}); | ||
cy.wait(2000); | ||
}); | ||
|
||
it("The user can login with the login form with valid credentials", () => { | ||
cy.get("#loginEmail").type("Ramsnes@noroff.no"); | ||
cy.get("#loginPassword").type("Marmea88"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Real data should be protected in .env and secrets |
||
cy.get("button[type='submit']:visible").click(); | ||
cy.get(window.localStorage.getItem("token")).should("not.be.empty"); | ||
cy.get(window.localStorage.getItem("profile")).should("not.be.empty"); | ||
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way you're trying to access localStorage items is incorrect. - cy.get(window.localStorage.getItem("token")).should("not.be.empty");
- cy.get(window.localStorage.getItem("profile")).should("not.be.empty");
+ cy.window().its('localStorage.token').should('exist');
+ cy.window().its('localStorage.profile').should('exist'); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rabbit is telling the truth |
||
}); | ||
|
||
it("The user cannot submit the login form with invalid credentials and is shown a message", () => { | ||
cy.get("#loginEmail").type("not_real_user@hotmail.no"); | ||
cy.get("#loginPassword").type("not_real_password"); | ||
cy.get("button[type='submit']:visible").click(); | ||
cy.window().its("localStorage.token").should("not.exist"); | ||
cy.window().its("localStorage.profile").should("not.exist"); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
describe("Logout spec", () => { | ||
beforeEach(() => { | ||
cy.visit("/"); | ||
cy.wait(1000); | ||
|
||
cy.get("#registerForm").within(() => { | ||
cy.get("button[data-bs-target='#loginModal']:visible").click(); | ||
}); | ||
cy.wait(1000); | ||
|
||
cy.get("#loginEmail").should("exist"); | ||
cy.get("#loginPassword").should("exist"); | ||
cy.get("#loginEmail").type("Ramsnes@noroff.no"); | ||
cy.get("#loginPassword").type("Marmea88"); | ||
cy.wait(2000); | ||
cy.get("button[type='submit']:visible").click(); | ||
cy.get(window.localStorage.getItem("token")).should("not.be.empty"); | ||
cy.get(window.localStorage.getItem("profile")).should("not.be.empty"); | ||
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accessing - cy.get(window.localStorage.getItem("token")).should("not.be.empty");
- cy.get(window.localStorage.getItem("profile")).should("not.be.empty");
+ cy.window().its('localStorage.token').should('exist');
+ cy.window().its('localStorage.profile').should('exist'); |
||
cy.wait(2000); | ||
}); | ||
|
||
it("The user can log out with the logout button", () => { | ||
cy.get("button[data-auth='logout']:visible").click(); | ||
cy.window().its("localStorage.token").should("not.exist"); | ||
cy.window().its("localStorage.profile").should("not.exist"); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// *********************************************** | ||
// This example commands.js shows you how to | ||
// create various custom commands and overwrite | ||
// existing commands. | ||
// | ||
// 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) => { ... }) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// *********************************************************** | ||
// This example support/e2e.js 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.js using ES2015 syntax: | ||
import "./commands"; | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should have one override for each testing platform, instead of merging these together.