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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow #271

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintcache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"C:\\Users\\mariu\\Documents\\GitHub\\social-media-client\\cypress\\e2e\\spec.cy.js":"1","C:\\Users\\mariu\\Documents\\GitHub\\social-media-client\\cypress\\support\\commands.js":"2","C:\\Users\\mariu\\Documents\\GitHub\\social-media-client\\cypress\\support\\e2e.js":"3","C:\\Users\\mariu\\Documents\\GitHub\\social-media-client\\src\\js\\api\\auth\\logout.test.js":"4","C:\\Users\\mariu\\Documents\\GitHub\\social-media-client\\src\\js\\api\\auth\\token.test.js":"5"},{"size":111,"mtime":1692537396000,"results":"6","hashOfConfig":"7"},{"size":861,"mtime":1692537152276,"results":"8","hashOfConfig":"7"},{"size":686,"mtime":1692537152277,"results":"9","hashOfConfig":"7"},{"size":601,"mtime":1692540017829,"results":"10","hashOfConfig":"7"},{"size":713,"mtime":1692539726936,"results":"11","hashOfConfig":"7"},{"filePath":"12","messages":"13","suppressedMessages":"14","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1s83oeu",{"filePath":"15","messages":"16","suppressedMessages":"17","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"18","messages":"19","suppressedMessages":"20","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"21","messages":"22","suppressedMessages":"23","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"24","messages":"25","suppressedMessages":"26","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"C:\\Users\\mariu\\Documents\\GitHub\\social-media-client\\cypress\\e2e\\spec.cy.js",[],[],"C:\\Users\\mariu\\Documents\\GitHub\\social-media-client\\cypress\\support\\commands.js",[],[],"C:\\Users\\mariu\\Documents\\GitHub\\social-media-client\\cypress\\support\\e2e.js",[],[],"C:\\Users\\mariu\\Documents\\GitHub\\social-media-client\\src\\js\\api\\auth\\logout.test.js",[],[],"C:\\Users\\mariu\\Documents\\GitHub\\social-media-client\\src\\js\\api\\auth\\token.test.js",[],[]]
37 changes: 37 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"overrides": [
{
"files": ["**/*.cy.js"],
"env": { "cypress/globals": true },
"plugins": ["cypress"],
"extends": ["plugin:cypress/recommended"],
"rules": {
"cypress/no-unnecessary-waiting": "off",
"no-unused-vars": "off",
"cypress/no-assigning-return-values": "error",
"cypress/assertion-before-screenshot": "warn",
"cypress/no-force": "warn",
"cypress/no-async-tests": "error",
"cypress/no-pause": "error"
}
},
{
"files": ["**/*.test.js"],
"env": { "jest": true },
"plugins": ["jest"],
"extends": ["plugin:jest/recommended"],
"rules": { "jest/prefer-expect-assertions": "off" }
}
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {}
}
19 changes: 19 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Automated Testing E2E
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: Install Dependencies
run: npm i
- name: Build SASS
run: npm run build
- name: run cypress tests with electron
uses: cypress-io/github-action@v4
46 changes: 46 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Dependencies
run: npm i
- name: Build SASS
run: npm run build
- name: Setup Pages
uses: actions/configure-pages@v2
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
# Upload entire repository
path: '.'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
24 changes: 24 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript"]
}
3 changes: 3 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [["@babel/preset-env", { "targets": { "node": "current" } }]]
}
9 changes: 9 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { defineConfig } = require('cypress');

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
51 changes: 51 additions & 0 deletions cypress/e2e/login.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
describe('Login with correct pattern', () => {
beforeEach(() => {
cy.visit('./');
if (window.localStorage.getItem('token')) {
cy.clearLocalStorage();
}
});

it('Logs in', () => {
cy.visit('/');
cy.wait(1000);

cy.get(`#registerForm [data-auth="login"]`)
.contains('Login')
.should('exist')
.click();
cy.wait(1000);
cy.get('input#loginEmail').type('MarHag76645@stud.noroff.no');
cy.get('input#loginPassword').type('12345678');
cy.wait(500);
cy.get('#loginForm button').contains('Login').should('be.visible').click();
cy.wait(500);
});
});

describe('Login with wrong pattern', () => {
beforeEach(() => {
cy.visit('./');
if (window.localStorage.getItem('token')) {
cy.clearLocalStorage();
}
});

it('Does not log in', () => {
cy.visit('/');
cy.wait(1000);
cy.get(`#registerForm [data-auth="login"]`)
.contains('Login')
.should('exist')
.click();
cy.wait(1000);
cy.get('input#loginEmail').type('marhag@gmail.no');
cy.get('input#loginPassword').type('12345678');
cy.get('#loginForm button').contains('Login').should('be.visible').click();
cy.wait(500);

const alertPopup = cy.stub().as('alertPopup');
cy.on('window:alert', alertPopup);
cy.get(alertPopup).should('exist');
});
});
28 changes: 28 additions & 0 deletions cypress/e2e/logout.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
describe('Login with credentials', () => {
beforeEach(() => {
cy.visit('./');
if (window.localStorage.getItem('token')) {
cy.clearLocalStorage();
}
});

it('Logs in', () => {
cy.visit('/');
cy.wait(1000);

cy.get(`#registerForm [data-auth="login"]`)
.contains('Login')
.should('exist')
.click();
cy.wait(1000);
cy.get('input#loginEmail').type('MarHag76645@stud.noroff.no');
cy.get('input#loginPassword').type('12345678');
cy.wait(500);
cy.get('#loginForm button').contains('Login').should('be.visible').click();
cy.wait(1000);
cy.get("button[data-auth='logout']").should('be.visible').click();
cy.then(() => {
expect(window.localStorage.getItem('token')).to.be.null;
});
});
});
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
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"
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
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) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/e2e.js
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')
Binary file added cypress/videos/login.cy.js.mp4
Binary file not shown.
Binary file added cypress/videos/logout.cy.js.mp4
Binary file not shown.
Loading
Loading