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

refactor: added absolute import paths to unit tests #215

Merged
merged 29 commits into from
Oct 18, 2024

Conversation

timDeHof
Copy link
Contributor

@timDeHof timDeHof commented Oct 12, 2024

Description

This Pull Request includes refactoring changes to update import paths and Jest configuration for unit tests. The changes improve the overall structure of the codebase, making it easier to maintain and test.

Key changes include:

  • Updated import paths to use the "@" alias for better readability and to avoid relative path issues in unit tests
  • Modified Jest configuration in the package.json to align with the new import paths and improve test execution
  • Updated tsconfig.json to reflect changes in import paths

These changes enhance code organization, improve navigation through the codebase, and ensure proper test execution with new structure.

Issue link

Fixes # 86b2346xp

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature updates / changes
  • Tests
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Verify that the changes work by:

  1. pull the latest changes
  2. Run yarn test or yarn test:docker (if you use docker)
  3. Check that the afterall() in the healthcheck test by running yarn studio:test and see that healthcheck table is empty

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have updated the change log

…organization and testing

The import paths have been updated to use the "@" alias for better readability and to avoid relative path issues. This change improves code organization and makes it easier to navigate through the codebase.

The Jest configuration has also been updated to reflect these changes and ensure that the tests run correctly with the new import paths. The root directory for Jest has been changed to the project root, and a new moduleDirectories property has been added to include "src" along with "node_modules". This allows Jest to resolve modules from the "src" directory as well as "node_modules".

The moduleNameMapper has been updated to map "@" to "src", which aligns with the updated import paths. The testRegex has been changed to ".spec.ts$" to match the naming convention of the test files.

In addition, the tsconfig.json file has been updated to reflect the changes in the import paths. The "@shared/*" path has been removed as it is no longer needed.

These changes improve the overall structure and organization of the codebase, making it easier to maintain and test.
…ameMapper for better path resolution

refactor(package.json): update testRegex to include int-spec.ts files for more comprehensive testing
refactor(health-check.controller.ts): update import path to use alias for better readability
feat(health-check.service.int-spec.ts): add ConfigModule and DB-Config provider for more flexible testing setup
refactor(health-check.service.int-spec.ts): add afterAll block to clean up database after tests
The rootDir and moduleNameMapper changes in package.json improve path resolution, making it easier to manage and understand the project structure. The testRegex update allows Jest to recognize and run integration tests, enhancing the test coverage. The import path in health-check.controller.ts is updated to use an alias, improving readability and maintainability. The health-check.service.int-spec.ts file now imports ConfigModule and provides a DB-Config, making the testing setup more flexible and adaptable to different environments. An afterAll block is added to clean up the database after tests, ensuring a clean state for each test run.
@timDeHof timDeHof requested a review from cherylli October 12, 2024 16:59
@timDeHof timDeHof self-assigned this Oct 12, 2024
…ute import paths

The change was made to improve the readability and maintainability of the unit tests. Using absolute import paths makes the code cleaner and easier to understand, as it eliminates the need for complex relative paths. This change aligns with the previous refactoring of e2e tests to use absolute import paths.
Copy link
Contributor

@cherylli cherylli left a comment

Choose a reason for hiding this comment

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

Everything works fine but I see some controllers file still has relative imports, e.g. auth.controller.ts, were they supposed to be in last PR or next?

image

CHANGELOG.md Outdated Show resolved Hide resolved
@timDeHof
Copy link
Contributor Author

Everything works fine but I see some controllers file still has relative imports, e.g. auth.controller.ts, were they supposed to be in last PR or next?

image

oops, I thought you only wanted the tests...I'll go through and change the relative imports to absolutes now.

@cherylli
Copy link
Contributor

Everything works fine but I see some controllers file still has relative imports, e.g. auth.controller.ts, were they supposed to be in last PR or next?
image

oops, I thought you only wanted the tests...I'll go through and change the relative imports to absolutes now.

Thanks, for some reason I thought all the other ones were changed last time, and only tests left

…s for better project structure

feat(package.json, tsconfig.json): add @prisma alias for prisma directory
The rootDir in package.json is changed from 'src' to '.' to better reflect the project structure. The module paths are adjusted accordingly. This change makes the project structure more intuitive and easier to navigate. Additionally, a new alias '@prisma' is added for the prisma directory, which simplifies the import statements and makes the code cleaner.
…bility and maintainability

The import paths in the auth module, auth service, auth service spec, and discord auth service have been updated to use the '@' alias instead of relative paths. This change improves readability and maintainability of the code by making it easier to understand the file structure and to update import paths when files are moved or renamed.
…e relative paths with absolute paths for better readability and maintainability

The import statements in the development.service.spec.ts and development.service.ts files have been refactored to use absolute paths instead of relative paths. This makes the code more readable and easier to maintain, as it's clear where the imported modules are located in the project structure.
…for better readability and maintainability

The import paths in the features.controller.ts and features.service.ts files have been changed from relative paths to alias paths. This makes the code more readable and easier to maintain, as it reduces the complexity of the paths and makes it easier to understand the structure of the project.
…er readability and maintainability

The relative imports in the forms.controller.ts and forms.service.ts files have been replaced with absolute imports. This change improves the readability of the code and makes it easier to maintain, as it is now clear where the imported modules are located in the project structure.
…ility and maintainability

The import paths have been updated to use absolute paths instead of relative paths. This makes the code more readable and easier to maintain, as it's clear where the imported modules are located in the project structure. It also reduces the risk of errors when moving files around within the project.
The import path for PrismaService has been updated to use an absolute path instead of a relative one. This change improves code readability and maintainability by making it easier to understand where the imported modules are located in the project structure.
…better readability and maintainability

The relative imports in the ideations.controller.ts and ideations.service.ts files have been replaced with absolute imports. This change improves readability and maintainability by making it easier to understand where the imported modules are located in the project structure. It also reduces the risk of errors when moving files around, as the absolute import paths remain valid regardless of the file's location.
…quest

The import paths for FormResponseDto and CustomRequest have been updated to use absolute paths instead of relative paths. This change improves code readability and maintainability by making it easier to understand where the imported modules are located in the project structure.
…rt path for DbConfig

The import path for DbConfig has been changed from a relative path to an alias path. This change improves code readability and maintainability by making the import paths more consistent and easier to manage.
… imports with absolute imports for better readability and maintainability

The relative imports in resources.module.ts and resources.service.ts have been replaced with absolute imports. This change improves the readability of the code and makes it easier to maintain, as it's now clear where the imported modules are located in the project structure.
… better maintainability

The relative import paths in the sprints module, controller, service, and response files have been changed to absolute paths. This makes the code more maintainable and easier to navigate, as it is now clear where the imported modules are located in the project structure.
The import path for PrismaService was incorrect, causing the application to fail when trying to import it. The path has been corrected to "@/prisma/prisma.service", ensuring that the application can now correctly import and use PrismaService.
…er readability and maintainability

The relative imports in the teams module have been replaced with absolute imports. This change improves the readability of the code and makes it easier to maintain, as it is now clear where the imported modules are located in the project structure.
…hs with absolute paths for better maintainability

The relative paths in techs.controller.ts and techs.service.ts have been replaced with absolute paths. This change makes the code easier to maintain and understand, as it is now clear where the imported modules are located in the project structure. It also reduces the risk of errors when moving files around, as the absolute paths remain valid regardless of the location of the file that imports them.
…r readability and maintainability

The relative paths in the users module have been replaced with absolute paths. This change improves the readability of the code and makes it easier to maintain, as it's now clear where the imported modules are located in the project structure.
… and AppConfigService

The import paths for MailConfigService and AppConfigService have been updated to use absolute paths instead of relative paths. This change improves code readability and maintainability by making it easier to understand where the imported modules are located in the project structure.
…er readability and maintainability

The import paths in the voyages.controller.ts and voyages.service.ts files have been updated to use absolute paths instead of relative paths. This makes the code more readable and easier to maintain, as it's clear where the imported modules are located in the project structure.
…ter test coverage

The Prisma directory is now included in the moduleNameMapper configuration in jest-e2e.json. This allows Jest to resolve modules from the Prisma directory, improving the test coverage for Prisma-related code.
… paths

The import paths in all test files have been updated to use the "@" alias instead of relative paths. This change improves readability and maintainability of the code. It also makes it easier to move files around in the project structure without having to update every single import statement.
…ter project structure and testing

The moduleNameMapper for @prisma has been updated to point to the correct directory, improving the project structure and ensuring that imports from @prisma are correctly resolved. The testRegex has been changed to match both .spec and .jest.ts files, allowing for a wider range of test files to be recognized and executed by Jest.
…with absolute paths for better readability and maintainability

The changes were made to replace relative paths with absolute paths. This makes the code more readable and easier to maintain, as it's easier to understand where the imported modules are coming from. It also reduces the risk of errors when files are moved around in the project structure.
@timDeHof
Copy link
Contributor Author

I went back to the how the old testregex was to fix how the units command was running the e2e tests after the unit tests. Also I corrected the absolute path in the jest section in the package.json.

@cherylli cherylli requested review from JoshuaHinman and removed request for Ajen07 October 16, 2024 01:31
@cherylli cherylli assigned JoshuaHinman and unassigned Ajen07 Oct 16, 2024
@cherylli
Copy link
Contributor

Updated reviewer to @JoshuaHinman

@cherylli
Copy link
Contributor

cherylli commented Oct 16, 2024

I'm getting this when I run prisma db seed , do I need to do extra setup?
image

interesting...I'll look into it. I'm also getting the same issue.

…ath resolution

The baseUrl in tsconfig.json has been changed from "./" to ".". This change was made to improve path resolution and to avoid potential issues with module resolution in different environments.
…s/register

The prisma seed script has been updated to include tsconfig-paths/register. This change ensures that TypeScript paths are correctly resolved when running the seed script, preventing potential path resolution errors.
@timDeHof
Copy link
Contributor Author

ok, I fixed it by installing tsconfig-path package to help with the path-mapping and refactored the prisma seed script to include it to correctly resolve the paths.

Copy link
Contributor

@cherylli cherylli left a comment

Choose a reason for hiding this comment

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

Everything works fine (tests, seed), whats the difference between @/prisma and @Prisma? looks like we need to use @Prisma in e2e tests

@timDeHof
Copy link
Contributor Author

Everything works fine (tests, seed), whats the difference between @/prisma and @Prisma? looks like we need to use @Prisma in e2e tests

I opted for distinct absolute import paths for the prisma directories to avoid potential conflicts when importing from @prisma/* modules, as our setup requires referencing two separate prisma directories. One in the project root used for seeding and database connections. The other one in the src folder for the services and controllers.

Copy link
Contributor

@JoshuaHinman JoshuaHinman left a comment

Choose a reason for hiding this comment

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

All tests passed and health check table is empty - looks good!

@cherylli cherylli merged commit 84301a6 into dev Oct 18, 2024
1 check passed
@cherylli cherylli deleted the feat-add-absolute-paths-to-units branch October 18, 2024 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants