-
Notifications
You must be signed in to change notification settings - Fork 524
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 #389
base: master
Are you sure you want to change the base?
Workflow #389
Changes from all commits
d340db1
58f672a
1cc6104
2fd2e70
2a6330d
d1e870b
bcc18b8
10fc626
1ddda9a
d109aee
bfa910a
b530979
bc80767
4591bf8
f5aeb40
d4d3f44
58d6f0a
d9df945
e7850e5
b68ebbe
7c496f2
2cc2539
b310281
9f33e9d
cd6e2af
45ca825
3893fcd
21cb4b0
a87fe0a
ee4d74c
35b2a5c
a288c8e
40e8951
5ec440c
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 @@ | ||
[{"C:\\Users\\pamij\\OneDrive\\Documents\\GitHub\\social-media-client\\src\\js\\app.test.js":"1","C:\\Users\\pamij\\OneDrive\\Documents\\GitHub\\social-media-client\\src\\js\\apple.js":"2","C:\\Users\\pamij\\OneDrive\\Documents\\GitHub\\social-media-client\\src\\js\\apple.test.js":"3","C:\\Users\\pamij\\OneDrive\\Documents\\GitHub\\social-media-client\\cypress.config.js":"4","C:\\Users\\pamij\\OneDrive\\Documents\\GitHub\\social-media-client\\cypress\\support\\commands.js":"5","C:\\Users\\pamij\\OneDrive\\Documents\\GitHub\\social-media-client\\cypress\\support\\e2e.js":"6","C:\\Users\\pamij\\OneDrive\\Documents\\GitHub\\social-media-client\\cypress\\e2e\\logout.cy.js":"7"},{"size":92,"mtime":1705949183269,"results":"8","hashOfConfig":"9"},{"size":95,"mtime":1706304834391,"results":"10","hashOfConfig":"11"},{"size":372,"mtime":1705950990633,"results":"12","hashOfConfig":"9"},{"size":184,"mtime":1706104417274,"results":"13","hashOfConfig":"11"},{"size":861,"mtime":1706104417291,"results":"14","hashOfConfig":"11"},{"size":686,"mtime":1706104417291,"results":"15","hashOfConfig":"11"},{"size":1011,"mtime":1706374604231,"results":"16","hashOfConfig":"11"},{"filePath":"17","messages":"18","suppressedMessages":"19","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1owb8p1",{"filePath":"20","messages":"21","suppressedMessages":"22","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1nhz40n",{"filePath":"23","messages":"24","suppressedMessages":"25","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"26","messages":"27","suppressedMessages":"28","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"29","messages":"30","suppressedMessages":"31","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"32","messages":"33","suppressedMessages":"34","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"35","messages":"36","suppressedMessages":"37","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"C:\\Users\\pamij\\OneDrive\\Documents\\GitHub\\social-media-client\\src\\js\\app.test.js",[],[],"C:\\Users\\pamij\\OneDrive\\Documents\\GitHub\\social-media-client\\src\\js\\apple.js",[],[],"C:\\Users\\pamij\\OneDrive\\Documents\\GitHub\\social-media-client\\src\\js\\apple.test.js",[],[],"C:\\Users\\pamij\\OneDrive\\Documents\\GitHub\\social-media-client\\cypress.config.js",[],[],"C:\\Users\\pamij\\OneDrive\\Documents\\GitHub\\social-media-client\\cypress\\support\\commands.js",[],[],"C:\\Users\\pamij\\OneDrive\\Documents\\GitHub\\social-media-client\\cypress\\support\\e2e.js",[],[],"C:\\Users\\pamij\\OneDrive\\Documents\\GitHub\\social-media-client\\cypress\\e2e\\logout.cy.js",[],[]] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"overrides": [ | ||
{ | ||
"files": ["**/*.test.js"], | ||
"env": { "jest": true }, | ||
"plugins": ["jest"], | ||
"extends": ["plugin:jest/recommended"], | ||
"rules": { "jest/prefer-expect-assertions": "off" } | ||
}, | ||
{ | ||
"files": ["**/*.cy.js", "cypress.config.js"], | ||
"env": { "cypress/globals": true }, | ||
"plugins": ["cypress"], | ||
"extends": ["plugin:cypress/recommended"], | ||
"rules": { | ||
"cypress/no-unnecessary-waiting": "off", | ||
"no-unused-vars": "off" | ||
} | ||
} | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
/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,5 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lint-staged | ||
npx lint-staged | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
added 54 packages, and audited 368 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. | ||
Comment on lines
+1
to
+12
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 changes made in this hunk are related to the package management and audit. It seems like there are 3 high severity vulnerabilities found during the audit. While Instead of using - To address all issues (including breaking changes), run:
- npm audit fix --force
+ To address all issues individually, review the output of:
+ npm audit This change will encourage developers to take a more careful approach when dealing with security vulnerabilities. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Workflow CA | ||
|
||
In this CA we are tasked with applying workflow skills in installing code formatting tools, configuration and code testing. | ||
|
||
# GitHub repository | ||
|
||
I fork the gitHub repository from the gitHub provided in the CA brief and clone it to my gitHub desktop. Created the workflow branch in which i did all the workflow tasks and committed into the workflow branch. | ||
Open the github repo on vscode and use the vscode terminal to install and configure the different extensions for the workflow CA. | ||
|
||
# Installed dependencies | ||
- npm init | ||
- installing Prettier | ||
- Installing eslint | ||
- npm run lint-fix (to fix errors notice by eslint) | ||
- Installing hooks (npx mrm@2 lint-staged) | ||
|
||
# Tests installed and configured for the project | ||
|
||
- Installed jest (npm i -D jest@29.2.0) for our unit testings | ||
- npm i -D eslint-plugin-jest (this to setup the environment for the jest configuration) | ||
- Installed babel for jest | ||
- Installed cypress ( for end-to-end testings) | ||
Comment on lines
+1
to
+22
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 changes to the README file look good overall, but there's a minor issue. It's a best practice to end a file with a newline character. This is a POSIX standard that ensures easier concatenation of files and better compatibility across different tools and systems. - Installed cypress ( for end-to-end testings)
+22: - Installed cypress ( for end-to-end testings)
+23: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": [["@babel/preset-env", { "targets": { "node": "current" } }]] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defineConfig } from "cypress"; | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
// implement node event listeners here | ||
}, | ||
}, | ||
}); | ||
Comment on lines
+1
to
+9
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 new hunk introduces a configuration for Cypress using - setupNodeEvents(on, config) {
- // implement node event listeners here
- }, If you plan to add event listeners in the future, it would be better to leave a more descriptive comment: + setupNodeEvents(on, config) {
+ // TODO: Implement node event listeners as required by the tests
+ }, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
describe('Login Form', () => { | ||
it('can login with valid credentials', () => { | ||
cy.visit('./'); | ||
cy.get('input[name=email]').first().type('valid-name@example.com'); | ||
cy.get('input[name=password]').first().type('valid-password'); | ||
cy.get('#loginForm').submit(); | ||
cy.wait(3500); | ||
}); | ||
Comment on lines
+1
to
+8
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 test case for logging in with valid credentials does not include any assertions. It's important to verify the outcome of the login attempt, such as checking if the user is redirected to the correct page or if a specific element appears on the page after successful login. cy.get('#loginForm').submit();
cy.wait(3500);
+ // Add an assertion here to check the result of the login attempt
+ // For example, if successful login redirects to a dashboard page:
+ // cy.url().should('include', '/dashboard');
}); |
||
|
||
it('brings out an alert box with invalid credentials', () => { | ||
cy.visit('./'); | ||
cy.get('input[name=email]').first().type('invalid-name@example.com'); | ||
cy.get('input[name=password]').first().type('invalid-password'); | ||
cy.get('#loginForm').submit(); | ||
cy.on('window:alert', (alertText) => { | ||
expect(alertText).to.equal( | ||
'Login failed, please check your email or password and try again.' | ||
); | ||
}); | ||
}); | ||
Comment on lines
+10
to
+20
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. This test case relies on a |
||
}); | ||
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
+1
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. The test cases look good, but there are a few improvements that can be made:
Here's how you could improve these tests: describe('Login Form', () => {
it('can login with valid credentials', () => {
cy.visit('./');
cy.get('input[name=email]').first().type('valid-name@example.com');
cy.get('input[name=password]').first().type('valid-password');
cy.get('#loginForm').submit();
- cy.wait(3500);
+ cy.intercept('POST', '/api/login').as('login');
+ cy.wait('@login');
});
it('brings out an alert box with invalid credentials', () => {
cy.visit('./');
cy.get('input[name=email]').first().type('invalid-name@example.com');
cy.get('input[name=password]').first().type('invalid-password');
cy.get('#loginForm').submit();
- cy.on('window:alert', (alertText) => {
- expect(alertText).to.equal(
- 'Login failed, please check your email or password and try again.'
- );
- });
+ cy.get('.error-message').should('contain', 'Login failed, please check your email or password and try again.');
});
}); In the above changes, I've replaced |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
describe("User logout", () => { | ||
beforeEach(() => { | ||
cy.visit("./"); | ||
cy.clearLocalStorage(); | ||
}); | ||
|
||
it("successfully logs out the user", () => { | ||
cy.visit("/"); | ||
cy.wait(1500); | ||
cy.get(".btn-close:visible").click({ multiple: true }); | ||
Comment on lines
+8
to
+10
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 use of - cy.wait(1500);
- cy.get(".btn-close:visible").click({ multiple: true });
- cy.wait(1500);
+ cy.get(".btn-close:visible", { timeout: 5000 }).click({ multiple: true }); |
||
cy.wait(1500); | ||
cy.get("button[data-auth='login']:visible").click({ multiple: true }); | ||
cy.wait(1500); | ||
cy.get("input[type='email']:visible") | ||
.should("exist") | ||
.type("name@example.com"); | ||
cy.get("input[type='password']:visible").should("exist").type("mane12345"); | ||
cy.get(".btn-success:visible").click({ multiple: true }); | ||
cy.wait(2000); | ||
cy.get(window.localStorage.getItem("token")).should("not.to.be.empty"); | ||
cy.get(window.localStorage.getItem("profile")).should("not.to.be.empty"); | ||
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. Directly accessing - cy.get(window.localStorage.getItem("token")).should("not.to.be.empty");
- cy.get(window.localStorage.getItem("profile")).should("not.to.be.empty");
+ cy.window().its('localStorage.token').should('not.to.be.empty');
+ cy.window().its('localStorage.profile').should('not.to.be.empty'); |
||
cy.get("button[data-auth='logout']").click({ multiple: true }); | ||
cy.then(() => expect(window.localStorage.getItem("token")).to.be.null); | ||
cy.then(() => expect(window.localStorage.getItem("profile")).to.be.null); | ||
Comment on lines
+23
to
+24
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. Similar to the previous comment, use - cy.then(() => expect(window.localStorage.getItem("token")).to.be.null);
- cy.then(() => expect(window.localStorage.getItem("profile")).to.be.null);
+ cy.window().its('localStorage.token').should('be.null');
+ cy.window().its('localStorage.profile').should('be.null'); |
||
}); | ||
}); |
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.
CodeRabbit
There seems to be a redundancy in your pre-commit hook. The
npx lint-staged
command is repeated twice, which could lead to unnecessary execution and slow down the commit process.