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

No support for test build, breaks process.env.NODE_ENV === 'test' #167

Open
agilgur5 opened this issue Jul 14, 2019 · 1 comment
Open

No support for test build, breaks process.env.NODE_ENV === 'test' #167

agilgur5 opened this issue Jul 14, 2019 · 1 comment
Labels
kind: feature New feature or request

Comments

@agilgur5
Copy link
Collaborator

agilgur5 commented Jul 14, 2019

Current Behavior

tsdx does not create a test build and will end up loading the development build when process.env.NODE_ENV === 'test'. But the development build has replaced process.env.NODE_ENV with 'development'.

This causes some issues if one puts a process.env.NODE_ENV === 'test' in their source code as it will always be false. This is what I experienced in agilgur5/mst-persist#9 (comment)

The ESM build actually leaves process.env.NODE_ENV as is, so it causes differing behavior for ESM vs. CJS.
Most tests are run in Node and require CJS support as a result (unless one is transpiling node_modules or using the esm package as a loader), so this means most behavior behind a test check just won't work for folks who build their libraries with tsdx.

Expected behavior

If someone added a process.env.NODE_ENV === 'test' in their source code it should work as expected in a test environment.

Suggested solution(s)

  • Don't replace process.env.NODE_ENV with 'development' in the development build, OR
  • Create a separate test build

Additional context

None, have linked the repo in which I experienced the problem above.

Your environment

Software Version(s)
TSDX 0.7.2
TypeScript 3.5.2
Browser N/A
npm/Yarn npm 6.9.0
Operating System macOS High Sierra 10.13

^Also y'all might want to check out how nyc uses npx envinfo@latest --preset nyc in order to get the above table easily from all users reporting issues.

@ling1726
Copy link

FYI you can just use process.env["NODE_ENV"] === "test" since the replace plugin used in just matches for process.env.NODE_ENV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants