tsdx icon indicating copy to clipboard operation
tsdx copied to clipboard

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

Open agilgur5 opened this issue 5 years ago • 1 comments

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 https://github.com/agilgur5/mst-persist/pull/9#issuecomment-511167625

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.

agilgur5 avatar Jul 14 '19 02:07 agilgur5

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

ling1726 avatar Nov 10 '21 20:11 ling1726