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(isNodeProcess): avoid undefined error #255

Merged
merged 5 commits into from
Jul 3, 2020
Merged

fix(isNodeProcess): avoid undefined error #255

merged 5 commits into from
Jul 3, 2020

Conversation

jameslahm
Copy link
Contributor

Hi, Thanks for the amazing tool. I try to use it in a browser, but global is not defined came out. I think it maybe caused by isNodeProcess function. Change it to typeof process ==='object' may solve this problem.

Copy link
Member

@kettanaito kettanaito left a comment

Choose a reason for hiding this comment

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

Thank you for spotting this, @jameslahm! I've had one suggestion to the changes, could you please let me know what you think about it?

src/utils/isNodeProcess.ts Show resolved Hide resolved
@kettanaito kettanaito added this to the 0.20.0 milestone Jul 2, 2020
kettanaito
kettanaito previously approved these changes Jul 2, 2020
Copy link
Member

@kettanaito kettanaito left a comment

Choose a reason for hiding this comment

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

Looks awesome!

I'd love to see a unit test in a React Native environment, but to reliably bootstrap one would be an overkill in our testing pipeline. We'd have to maintain that navigator manually.

Let's wait for the CI to pass.

@jameslahm
Copy link
Contributor Author

Yes, there should be a unit test. I add a React Native Environment test just now. Copying environment settings from React Native, and because typescript will check Process type properties, which will break the mock of global process, I add ts-nocheck. What do you think about it?

src/utils/isNodeProcess.react-native.test.ts Outdated Show resolved Hide resolved
src/utils/isNodeProcess.react-native.test.ts Outdated Show resolved Hide resolved
@kettanaito
Copy link
Member

Hey. I've rebased the branch against the latest master and cleaned up the React Native test suite a little. Will wait for the CI to pass and then merge.

Copy link
Member

@kettanaito kettanaito left a comment

Choose a reason for hiding this comment

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

Great changes. Thank you, @jameslahm, and welcome to contributors!

@kettanaito kettanaito merged commit 52f17dd into mswjs:master Jul 3, 2020
@jameslahm
Copy link
Contributor Author

The changes look good! Thanks!

@jameslahm
Copy link
Contributor Author

I just found a problem, that is because we mock global.process like this Object.defineProperty(global.process, 'env', { get: () => ({ NODE_ENV: 'development', }), }), which leads Object.prototype.toString.call(global.process) still equals [object process]. It should be [object Object]? Would you mind to look at it again?

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