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 - Peer Review #388

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
75a2edd
Added DevDep prettier and ESlint
ArneBHuset Jan 8, 2024
371fac6
added commit hooks and updated the lint-staged{} in package.json
ArneBHuset Jan 8, 2024
47519a5
testing commit without bug
ArneBHuset Jan 8, 2024
e12ac3c
added yml file
ArneBHuset Jan 9, 2024
9d91592
1.0.1
ArneBHuset Jan 9, 2024
ad7f8f8
testing html error
ArneBHuset Jan 9, 2024
4f1d379
added prettier to eslint
ArneBHuset Jan 9, 2024
3f81283
Commit after running npx eslint and fixing >1000 prettier errors
ArneBHuset Jan 9, 2024
6630b2d
Trying to add actions workflow
ArneBHuset Jan 9, 2024
fa191b7
Trigger workflow
ArneBHuset Jan 9, 2024
ae51826
changed to workflows
ArneBHuset Jan 9, 2024
ec102c7
attempt to fix github/workflowsfolder structure
ArneBHuset Jan 9, 2024
b7c2d53
added jest, babel, babel.config.js updated configuration
ArneBHuset Jan 10, 2024
1f12be2
1.0.2
ArneBHuset Jan 10, 2024
0964adc
Installed cypress
ArneBHuset Jan 10, 2024
b1c4548
1.0.3
ArneBHuset Jan 10, 2024
153af16
added cypress confgi to .eslintrc.json and package.json
ArneBHuset Jan 10, 2024
3995ff6
setting up cypress and configuring
ArneBHuset Jan 10, 2024
0430b58
Setting up cypress test for login
ArneBHuset Jan 11, 2024
f2218ad
added cypress test for registration
ArneBHuset Jan 12, 2024
890c89e
Added cypress post interaction test and cypress.env.json
ArneBHuset Jan 12, 2024
8726b44
added unit tests for tokens and resolved actions workflow error
ArneBHuset Jan 16, 2024
b7fae93
added correct url to check actions workflow
ArneBHuset Jan 16, 2024
d3a6247
updated master.yml steps to include launch of live server
ArneBHuset Jan 16, 2024
5d9c12f
working on liver server issues
ArneBHuset Jan 17, 2024
b8e66ad
Working on live server issue by adding defualt url to package.json 's…
ArneBHuset Jan 17, 2024
090d4c9
1.0.4
ArneBHuset Jan 17, 2024
2626803
created readme.md in root folder
ArneBHuset Jan 17, 2024
ffd3e87
Final commit, fixed a e2e error with postinteraction.cy.js and delete…
ArneBHuset Jan 26, 2024
604dbaf
1.0.5
ArneBHuset Jan 26, 2024
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
50 changes: 50 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"env": {
"browser": true,
"es2021": true,
"jest": true
},
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {},
"overrides": [
{
"files": ["*.test.js", "*.spec.js"],
"globals": {
"global": "writable"
},
"env": {
"jest": true
},
"plugins": ["jest"],
"extends": ["plugin:jest/recommended"]
},
{
"files": ["babel.config.js"],
"env": {
"node": true
}
},
{
"files": ["cypress.config.js"],
"env": {
"node": true
}
},
{
"files": ["**/*.cy.js"],
"env": {
"cypress/globals": true
},
"plugins": ["cypress"],
"extends": ["plugin:cypress/recommended"],
"rules": {
"cypress/no-unnecessary-waiting": "off",
"no-unused-vars": "off"
}
}
]
}
32 changes: 32 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Node.js CI

on:
push:
branches: [master, workflow]
pull_request:
branches: [master, workflow]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Run build
run: npm run build
- name: Start server
run: npm start & sleep 15
- name: Run tests
env:
CYPRESS_BASE_URL: http://localhost:3000
run: npm test
6 changes: 3 additions & 3 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Deploy static content to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]
branches: ['master']

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -17,7 +17,7 @@ permissions:

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

jobs:
Expand All @@ -30,7 +30,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Dependencies
- name: Install Dependencies
run: npm i
- name: Build SASS
run: npm run build
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/node_modules
/dist
/dist
/cypress/e2e/1-getting-started/
/cypress/e2e/2-advanced-examples/
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
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
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": true,
"arrowParens": "avoid"
}
12 changes: 12 additions & 0 deletions 6
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

added 56 packages, and audited 385 packages in 4s

60 packages are looking for funding
run `npm fund` for details

3 high severity vulnerabilities

To address all issues (including breaking changes), run:
npm audit fix --force

Run `npm audit` for details.

Choose a reason for hiding this comment

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

Image description CodeRabbit

The output of the npm install command shows that there are 3 high severity vulnerabilities in your dependencies. This is a security concern and should be addressed. You can use npm audit fix to automatically install any compatible updates that address these vulnerabilities. If automatic fixes are not available or fail, you may need to manually update or replace the affected packages.

- 3 high severity vulnerabilities
+ No vulnerabilities found

Please note that the above diff is just an example of what the output should look like after addressing the vulnerabilities. The actual changes will depend on the specific packages and versions involved.

65 changes: 65 additions & 0 deletions READEME.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# CSS Frameworks CA

This project utlizies a pre-developed application by Noroff, as part of the course "workflow". The web application features a front-end utilizing CSS frameworks. Key features include a login form connected to an API JWT endpoint, a logout mechanism, CRUD functionality, and a user profile page.

## Technologies Used

- HTML/CSS
- JavaScript
- SASS
- Jest for unit testing
- Cypress for end-to-end testing
- GitHub Actions for CI/CD

## Configuration

- **ESLint**: Linting utility for JavaScript.
- **Prettier**: Code formatter to ensure code style consistency.
- **Husky**: Used for setting up Git hooks to enforce linting and testing before commits.
- **Jest**: For unit testing JavaScript code.
- **Cypress**: For conducting end-to-end testing.

## Build Status

[![Node.js CI](https://github.com/ArneBHuset/social-media-client/actions/workflows/master.yml/badge.svg)](https://github.com/ArneBHuset/social-media-client/actions/workflows/master.yml)

## Installation and Setup

Clone the repository and install dependencies:

git clone https://github.com/ArneBHuset/social-media-client.git
cd css-frameworks-ca
npm install

npm start

## Running Tests

To run unit tests with Jest:

```bash
npm run test-unit
```

To run end-to-end tests with Cypress:

```bash
npm run test-e2e
npm run test-e2e-cli
```

To run eslint and to fix potential errors

```bash
npx eslint
npx eslint . --fix
```

Test commit hooks by

```bash
git add .
git commit -m "You commit message"
```

Github action workflow will run a final test, initalize in the master.yml file.
12 changes: 12 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
};
7 changes: 7 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { defineConfig } = require('cypress');

module.exports = defineConfig({
e2e: {
// setupNodeEvents(on, config) {},
},
});
7 changes: 7 additions & 0 deletions cypress.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"TEST_EMAIL": "workflowtesty@noroff.no",
"TEST_PASSWORD": "workflowtestypsw",
"REGISTRATION_USER_NAME": "workflowtestyuser",
"REGISTRATION_IMG": "https://shorturl.at/dzQR8",
"TESTCOMMENT": "Cypress automated commenting test"
}
3 changes: 3 additions & 0 deletions cypress/e2e/3-testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Notes about Cypress testing:

When testing login and registration. Remember to fill variable details in cypress.env.json file.
46 changes: 46 additions & 0 deletions cypress/e2e/3-testing/login.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
describe('Login Test', () => {
beforeEach(() => {
cy.visit('/');
cy.wait(500); // waiting for the modal to fully initialize
cy.get('#modalLoginBtn').click();
});

it('fails to log in with invalid email', () => {
cy.get('#loginEmail').should('be.visible').clear();
cy.get('#loginEmail').type('test@test{enter}');

// invalid email
cy.get('#loginEmail').clear();
cy.get('#loginEmail').type('error@test{enter}');
cy.wait(600);

// valid email
cy.get('#loginEmail').clear();
const loginEmail = Cypress.env('TEST_EMAIL');
cy.get('#loginEmail').type(`${loginEmail}{enter}`);
cy.log('Email input ok!');
// invalid password
cy.get('#loginPassword').should('be.visible').clear();
cy.get('#loginPassword').type('errortest{enter}');
cy.wait(600);

//valid password
cy.get('#loginPassword').clear();
const loginPsw = Cypress.env('TEST_PASSWORD');
cy.get('#loginPassword').type(`${loginPsw}{enter}`);
cy.log('Password input ok!');
// Checking that local storage has a profile- and token value
cy.wait(500);
cy.window().then(window => {
const profile = window.localStorage.getItem('profile');
const token = window.localStorage.getItem('token');
expect(profile).to.not.be.null;
expect(token).to.not.be.null;
});
cy.log('Token and profile data ok!');
// Clicking the logout button
cy.get('button[data-auth="logout"]').click();
cy.log('Logout ok!');
cy.log('FINISHED');
});
});
62 changes: 62 additions & 0 deletions cypress/e2e/3-testing/postinteraction.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
describe('Post Interaction Test', () => {
before(() => {
cy.visit('/');
cy.wait(500);

Choose a reason for hiding this comment

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

Image description CodeRabbit

The use of cy.wait(500); is not recommended as it introduces arbitrary waiting times that may lead to flaky tests. Instead, try to use Cypress's built-in wait mechanism which waits for elements to become available.

- cy.wait(500);
+ cy.get('#modalLoginBtn', { timeout: 5000 });


Comment on lines +4 to +5

Choose a reason for hiding this comment

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

Image description CodeRabbit

It's not a good practice to use cy.wait() with hardcoded time values in Cypress tests. This can lead to flaky tests if the operation takes longer than expected. Instead, you should use Cypress's built-in ability to automatically wait for elements to exist in the DOM, commands to complete, or requests to finish.

-    cy.wait(500);

// Log in with valid credentials
cy.get('#modalLoginBtn').click();
cy.get('#loginEmail').clear();
const loginEmail = Cypress.env('TEST_EMAIL');
cy.wait(300);

Choose a reason for hiding this comment

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

Image description CodeRabbit

Similar to the previous comment, avoid using cy.wait(300);. Use the built-in wait mechanism instead.

- cy.wait(300);
+ cy.get('#loginEmail', { timeout: 5000 });

cy.get('#loginEmail').type(`${loginEmail}{enter}`);
Comment on lines +10 to +11

Choose a reason for hiding this comment

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

Image description CodeRabbit

Same issue here with cy.wait(). Also, it's better to use .type() method directly without clearing the input field first unless it's necessary.

-    cy.wait(300);
-    cy.get('#loginEmail').clear();
-    cy.get('#loginEmail').type(`${loginEmail}{enter}`);
+    cy.get('#loginEmail').type(`${loginEmail}{enter}`, {force: true});


cy.get('#loginPassword').clear();
const loginPsw = Cypress.env('TEST_PASSWORD');
cy.get('#loginPassword').type(`${loginPsw}{enter}`);
Comment on lines +13 to +15

Choose a reason for hiding this comment

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

Image description CodeRabbit

Same issue here with cy.wait() and .clear().

-    cy.get('#loginPassword').clear();
-    cy.get('#loginPassword').type(`${loginPsw}{enter}`);
+    cy.get('#loginPassword').type(`${loginPsw}{enter}`, {force: true});


cy.wait(500);

Choose a reason for hiding this comment

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

Image description CodeRabbit

Again, avoid using cy.wait(500);. Use the built-in wait mechanism instead.

- cy.wait(500);
+ cy.get('a[href="./"]', { timeout: 5000 });

cy.get('a[href="./"]').click();
Comment on lines +17 to +18

Choose a reason for hiding this comment

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

Image description CodeRabbit

Again, avoid using cy.wait(). Use cy.click() directly.

-    cy.wait(500);
-    cy.get('a[href="./"]').click();
+    cy.get('a[href="./"]').click({force: true});


cy.wait(500);

Choose a reason for hiding this comment

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

Image description CodeRabbit

Avoid using cy.wait(500);. Use the built-in wait mechanism instead.

- cy.wait(500);
+ cy.get('.post .dropdown-toggle', { timeout: 5000 });

cy.window().then(window => {
Comment on lines +20 to +21

Choose a reason for hiding this comment

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

Image description CodeRabbit

Avoid using cy.wait(). Use assertions directly.

-    cy.wait(500);

const profile = window.localStorage.getItem('profile');
const token = window.localStorage.getItem('token');
expect(profile).to.not.be.null;
expect(token).to.not.be.null;
});
cy.log('Token KEY and profile information in good order');
});

it('reacts to the first post successfully and verifies page reload', () => {
// Openng the reaction menu for the first post
cy.get('.post .dropdown-toggle').first().click();

// Getting the post ID of the first post
cy.get('.post')
.first()
.find('button[data-post-id]')
.invoke('attr', 'data-post-id')
.then(postId => {
cy.get(`button[data-symbol="😀"][data-post-id="${postId}"]`).click();
cy.wait(2000);

Choose a reason for hiding this comment

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

Image description CodeRabbit

Avoid using cy.wait(2000);. Use the built-in wait mechanism instead.

- cy.wait(2000);
+ cy.get(`a[href="./?view=post&postId=${postId}"]`, { timeout: 5000 });

cy.log('Reaction test successful');
Comment on lines +41 to +42

Choose a reason for hiding this comment

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

Image description CodeRabbit

Avoid using cy.wait(). Use assertions directly.

-    cy.wait(2000);

cy.get(`a[href="./?view=post&postId=${postId}"]`).click();

cy.wait(2000);

Choose a reason for hiding this comment

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

Image description CodeRabbit

Avoid using cy.wait(2000);. Use the built-in wait mechanism instead.

- cy.wait(2000);
+ cy.get('textarea#commentBody', { timeout: 5000 });


Comment on lines +45 to +46

Choose a reason for hiding this comment

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

Image description CodeRabbit

Avoid using cy.wait(). Use assertions directly.

-    cy.wait(2000);

const testComment = Cypress.env(`TESTCOMMENT`);
cy.get('textarea#commentBody').type(testComment);
cy.get('form.comment-form button[type="submit"]').click();

cy.wait(2000);

Choose a reason for hiding this comment

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

Image description CodeRabbit

Avoid using cy.wait(2000);. Use the built-in wait mechanism instead.

- cy.wait(2000);
+ cy.get('.comment', { timeout: 5000 });


Comment on lines +51 to +52

Choose a reason for hiding this comment

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

Image description CodeRabbit

Avoid using cy.wait(). Use assertions directly.

-    cy.wait(2000);

// Verifying that the comment is present
cy.get('.comment').should(
'contain.text',
'Cypress automated commenting test'
);
cy.log('Comment test successful');
});
cy.log('FINISHED');
});
});
Loading
Loading