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

fix(node): Correctly handle Windows paths when resolving module name #5476

Merged
merged 7 commits into from Jul 28, 2022

Conversation

timfish
Copy link
Collaborator

@timfish timfish commented Jul 27, 2022

This was causing getsentry/sentry-electron#503

It looks like this was never handled correctly and we don't CI test on Windows so this was never noticed!

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

Can we add a test for this?

@timfish
Copy link
Collaborator Author

timfish commented Jul 27, 2022

Can we add a test for this?

Possibly, let me try. Looks like I'll need to overwrite require.main.filename!


describe('getModule', () => {
test('Windows', async () => {
(require.main as any) = { filename: 'C:\\Users\\Tim\\app.js' };
Copy link
Member

Choose a reason for hiding this comment

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

can we mock this return value with jest, and mockRestore afterwards?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

jest.spyOn complains that require and require.main are "not declared configurable". I guess this means the properties are marked as configurable: false and there is no way to modify them other than by overwriting them?

@timfish
Copy link
Collaborator Author

timfish commented Jul 27, 2022

I've had a better go and restore filename to it's previous value!

packages/node/src/module.ts Outdated Show resolved Hide resolved
packages/node/test/module.test.ts Outdated Show resolved Hide resolved
@AbhiPrasad
Copy link
Member

@timfish mind rebasing this PR? We had to fix some NextJS test failures with #5484

@AbhiPrasad AbhiPrasad merged commit 1182e71 into getsentry:master Jul 28, 2022
@timfish timfish deleted the fix/windows-module-name branch September 23, 2022 11:59
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.

None yet

2 participants