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

Morten Ramfjords Workflow PR #401

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open

Conversation

Ramsnes
Copy link

@Ramsnes Ramsnes commented Jan 28, 2024

Summary by CodeRabbit

  • New Feature: Introduced ESLint for maintaining code quality and consistency across the project.
  • Chore: Added Husky pre-commit hook to ensure linting before commits.
  • Documentation: Updated README.md with detailed information about the project setup, tools used, and commands for running tests and linting.
  • Test: Implemented automated unit testing and end-to-end testing using GitHub Actions workflows.
  • Test: Added Cypress configuration and test suites for login and logout functionalities.
  • Test: Created unit tests for login and logout functions to verify their correct behavior.

Copy link

github-actions bot commented Jan 28, 2024

Image description CodeRabbit

Walkthrough

This pull request introduces a comprehensive suite of testing and linting tools to the project. It includes ESLint for static code analysis, Husky for pre-commit hooks, GitHub Actions for automated unit and end-to-end testing, and Cypress for end-to-end testing. The changes also include test cases for login and logout functionalities, both for unit tests and end-to-end tests.

Changes

Files Summary
.eslintrc.json, .gitignore, .husky/pre-commit, README.md Introduced ESLint configuration, updated gitignore, added Husky pre-commit hook, and updated README with project details and instructions.
.github/workflows/autoUnitTesting.yml, .github/workflows/e2e-test.yml Added GitHub Actions workflows for automated unit and end-to-end testing.
cypress.config.js, cypress/e2e/3-e2e-testing-ca/loginSpec.cy.js, cypress/e2e/3-e2e-testing-ca/logoutSpec.cy.js, cypress/support/commands.js, cypress/support/e2e.js Added Cypress configuration and test suites for login and logout functionalities, along with custom commands and support files.
src/tests/login.test.js, src/tests/logout.test.js Added unit test cases for login and logout functions.

🐇💻

In the land of code where the shadows lie,

A rabbit hopped in, with a twinkle in its eye.

Linting, testing, all in place,

Ensuring bugs have no space.

With each commit, the checks run free,

For a world of code without entropy! 🎉


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between fc52c7c and 053b4e5 commits.
Files selected (13)
  • .eslintrc.json (1)
  • .github/workflows/autoUnitTesting.yml (1)
  • .github/workflows/e2e-test.yml (1)
  • .gitignore (1)
  • .husky/pre-commit (1)
  • README.md (1)
  • cypress.config.js (1)
  • cypress/e2e/3-e2e-testing-ca/loginSpec.cy.js (1)
  • cypress/e2e/3-e2e-testing-ca/logoutSpec.cy.js (1)
  • cypress/support/commands.js (1)
  • cypress/support/e2e.js (1)
  • src/tests/login.test.js (1)
  • src/tests/logout.test.js (1)
Files ignored due to filter (4)
  • babel.config.json
  • cypress/fixtures/example.json
  • package-lock.json
  • package.json
Files skipped from review due to trivial changes (9)
  • .github/workflows/autoUnitTesting.yml
  • .github/workflows/e2e-test.yml
  • .gitignore
  • .husky/pre-commit
  • README.md
  • cypress.config.js
  • cypress/support/commands.js
  • cypress/support/e2e.js
  • src/tests/login.test.js
Review comments generated (6)
  • Review: 3
  • LGTM: 3

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines +17 to +18
cy.get(window.localStorage.getItem("token")).should("not.be.empty");
cy.get(window.localStorage.getItem("profile")).should("not.be.empty");

Choose a reason for hiding this comment

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

Image description CodeRabbit

Accessing localStorage directly in Cypress commands is not recommended. Instead, use the cy.window() command to access localStorage. This ensures that you're accessing the same localStorage object as your application.

-    cy.get(window.localStorage.getItem("token")).should("not.be.empty");
-    cy.get(window.localStorage.getItem("profile")).should("not.be.empty");
+    cy.window().its('localStorage.token').should('exist');
+    cy.window().its('localStorage.profile').should('exist');

Comment on lines +1 to +42
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:prettier/recommended"
],
"overrides": [
{
"files": [
"**/*.test.js",
"**/*.cy.js"
],
"env": {
"jest": true,
"cypress/globals": true
},
"plugins": [
"prettier",
"jest",
"cypress"
],
"extends": [
"plugin:jest/recommended",
"plugin:cypress/recommended"
],
"rules": {
"jest/prefer-expect-assertions": "off",
"cypress/no-unnecessary-waiting": "off",
"no-unused-vars": "off"
}
}
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {}
}

Choose a reason for hiding this comment

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

Image description CodeRabbit

The ESLint configuration looks good overall, but there's a minor issue. It's a best practice to always end your files with a newline. This is because some tools like cat, sed, awk, etc., might not recognize or have issues processing the last line if it doesn't end with a newline.

    "rules": {}
- 42: }
+ 42: }\n

Also, you've turned off the rule no-unused-vars in your test files (line 33). While this can sometimes be necessary in test files, be cautious as it could potentially hide bugs related to unused variables in your tests. Consider enabling it and using ignore comments (// eslint-disable-next-line no-unused-vars) on a case-by-case basis where necessary.

Comment on lines +15 to +16
cy.get(window.localStorage.getItem("token")).should("not.be.empty");
cy.get(window.localStorage.getItem("profile")).should("not.be.empty");

Choose a reason for hiding this comment

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

Image description CodeRabbit

The way you're trying to access localStorage items is incorrect. cy.get is used to get DOM elements, not localStorage items. You should use cy.window().its('localStorage.token') and cy.window().its('localStorage.profile') instead.

-     cy.get(window.localStorage.getItem("token")).should("not.be.empty");
-     cy.get(window.localStorage.getItem("profile")).should("not.be.empty");
+     cy.window().its('localStorage.token').should('exist');
+     cy.window().its('localStorage.profile').should('exist');

Copy link
Collaborator

Choose a reason for hiding this comment

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

The rabbit is telling the truth

"overrides": [
{
"files": [
"**/*.test.js",
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should have one override for each testing platform, instead of merging these together.


it("The user can login with the login form with valid credentials", () => {
cy.get("#loginEmail").type("Ramsnes@noroff.no");
cy.get("#loginPassword").type("Marmea88");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Real data should be protected in .env and secrets

Comment on lines +15 to +16
cy.get(window.localStorage.getItem("token")).should("not.be.empty");
cy.get(window.localStorage.getItem("profile")).should("not.be.empty");
Copy link
Collaborator

Choose a reason for hiding this comment

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

The rabbit is telling the truth

@@ -1,20 +1,52 @@
{
"name": "css-frameworks-ca",
"version": "1.0.0",
"version": "0.0.3",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"version": "0.0.3",
"version": "1.0.3",

Version numbers never go backwards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants