-
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 #389
base: master
Are you sure you want to change the base?
Workflow #389
Changes from 31 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"},{"size":92,"mtime":1705949183269,"results":"7","hashOfConfig":"8"},{"size":95,"mtime":1706304834391,"results":"9","hashOfConfig":"10"},{"size":372,"mtime":1705950990633,"results":"11","hashOfConfig":"8"},{"size":184,"mtime":1706104417274,"results":"12","hashOfConfig":"10"},{"size":861,"mtime":1706104417291,"results":"13","hashOfConfig":"10"},{"size":686,"mtime":1706104417291,"results":"14","hashOfConfig":"10"},{"filePath":"15","messages":"16","suppressedMessages":"17","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1owb8p1",{"filePath":"18","messages":"19","suppressedMessages":"20","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1nhz40n",{"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},{"filePath":"27","messages":"28","suppressedMessages":"29","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"30","messages":"31","suppressedMessages":"32","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",[],[]] |
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,13 @@ | ||
describe('Logout Button', () => { | ||
it('logs out a user', () => { | ||
cy.visit('./'); | ||
cy.get('input[name=email]').first().type('mane@suiteTeardown.noroff.no'); | ||
cy.get('input[name=password]').first().type('mane12345'); | ||
cy.get('#loginForm').submit(); | ||
|
||
cy.get('[data-auth="logout"]').click(); | ||
|
||
cy.get('#loginForm').should('be.visible'); | ||
cy.url().should('equal', 'http://localhost:55499/'); | ||
}); | ||
}); | ||
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 the logout functionality seems fine. However, it's not a good practice to hardcode user credentials in your test cases. Consider using environment variables or a configuration file that is not committed to the repository to store these sensitive data. - cy.get('input[name=email]').first().type('mane@suiteTeardown.noroff.no');
- cy.get('input[name=password]').first().type('mane12345');
+ cy.get('input[name=email]').first().type(Cypress.env('TEST_USER_EMAIL'));
+ cy.get('input[name=password]').first().type(Cypress.env('TEST_USER_PASSWORD')); Also, please add a newline at the end of the file to follow best practices and avoid potential parsing issues. });
\ No newline at end of file
+13: });
+ |
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.