-
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
Workflow - Peer Review #388
Changes from 28 commits
75a2edd
371fac6
47519a5
e12ac3c
9d91592
ad7f8f8
4f1d379
3f81283
6630b2d
fa191b7
ae51826
ec102c7
b7c2d53
1f12be2
0964adc
b1c4548
153af16
3995ff6
0430b58
f2218ad
890c89e
8726b44
b7fae93
d3a6247
5d9c12f
b8e66ad
090d4c9
2626803
ffd3e87
604dbaf
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,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" | ||
} | ||
} | ||
] | ||
} |
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 |
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/ |
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,10 @@ | ||
{ | ||
"semi": true, | ||
"trailingComma": "es5", | ||
"singleQuote": true, | ||
"printWidth": 80, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"bracketSpacing": true, | ||
"arrowParens": "avoid" | ||
} |
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. | ||
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
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: { | ||
// setupNodeEvents(on, config) {}, | ||
}, | ||
}); |
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" | ||
} |
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. |
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'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
describe('Post Interaction Test', () => { | ||
before(() => { | ||
cy.visit('/'); | ||
cy.wait(500); | ||
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. |
||
|
||
Comment on lines
+4
to
+5
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. It's not a good practice to use - 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); | ||
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. |
||
cy.get('#loginEmail').type(`${loginEmail}{enter}`); | ||
Comment on lines
+10
to
+11
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. Same issue here with - 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
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. |
||
|
||
cy.wait(500); | ||
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. |
||
cy.get('a[href="./"]').click(); | ||
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. |
||
|
||
cy.wait(500); | ||
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. |
||
cy.window().then(window => { | ||
Comment on lines
+20
to
+21
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. |
||
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); | ||
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. |
||
cy.log('Reaction test successful'); | ||
Comment on lines
+41
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. |
||
cy.get(`a[href="./?view=post&postId=${postId}"]`).click(); | ||
|
||
cy.wait(2000); | ||
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. |
||
|
||
Comment on lines
+45
to
+46
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. |
||
const testComment = Cypress.env(`TESTCOMMENT`); | ||
cy.get('textarea#commentBody').type(testComment); | ||
cy.get('form.comment-form button[type="submit"]').click(); | ||
|
||
cy.wait(2000); | ||
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. |
||
|
||
Comment on lines
+51
to
+52
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. |
||
// Verifying that the comment is present | ||
cy.get('.comment').should( | ||
'contain.text', | ||
'Cypress automated commenting test' | ||
); | ||
cy.log('Comment test successful'); | ||
}); | ||
cy.log('FINISHED'); | ||
}); | ||
}); |
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.
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 usenpm 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.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.