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

Add unit tests for utils.ts #294

Merged
merged 7 commits into from
Sep 5, 2024
Merged

Add unit tests for utils.ts #294

merged 7 commits into from
Sep 5, 2024

Conversation

mohamedsalem401
Copy link
Member

@mohamedsalem401 mohamedsalem401 commented Sep 2, 2024

  • Add configuration for jest testing
  • Add unit tests for all functions in the utils.ts file
  • One commented test that should be uncommented or replaced

Copy link
Member

@danstarns danstarns left a comment

Choose a reason for hiding this comment

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

Looks great, can we add into CI?

});
});

// TODO: Fix this test as we can't mock the process.cwd
Copy link
Member

Choose a reason for hiding this comment

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

How come we can't mock?

Copy link
Member Author

@mohamedsalem401 mohamedsalem401 Sep 2, 2024

Choose a reason for hiding this comment

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

I couldn't figure out the solution for this issue. I think it's related to the following issue in the Jest GitHub repository:
Jest globals differ from Node globals

Also take a look at:
jestjs/jest#5146

Copy link
Member Author

Choose a reason for hiding this comment

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

@danstarns
I've changed the test, it's currently using the same logic as the actual function itself, so it should always pass, but at least we are ensuring that the function is correctly implemented and accessible in our test environment.

describe('rootResolve', () => {
    it('should resolve a relative path to an absolute path', () => {
        const result = rootResolve('src/index.js');

        expect(result).toBe(path.join(process.cwd(), 'src/index.js'));
    });
});

@mohamedsalem401
Copy link
Member Author

mohamedsalem401 commented Sep 2, 2024

Looks great, can we add into CI?

I'll work on that

Copy link
Member

@artf artf left a comment

Choose a reason for hiding this comment

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

🚀

@danstarns danstarns merged commit 7375fd5 into master Sep 5, 2024
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.

3 participants