fusion-cli icon indicating copy to clipboard operation
fusion-cli copied to clipboard

Simulate `__DEV__` value in tests

Open simonrobb opened this issue 6 years ago • 3 comments

Type of issue

Feature request

Description

I'd like to test a behavior that varies with the value of __DEV__. There isn't a way to simulate this value in tests.

Current behavior

__DEV__ is true while developing tests locally. I'm not sure what the value would be on a CI server.

Expected behavior

Ideally the __DEV__ value should be configurable on a per-test basis.

Steps to reproduce

  1. Write a function which returns __DEV__
  2. Test that function
  3. Profit?

Your environment

  • fusion-cli version: 1.8.5

  • Node.js version (node --version): v8.11.3

  • npm version (npm --version): 5.6.0

  • Operating System: OSX

simonrobb avatar Aug 03 '18 16:08 simonrobb

So one janky way of doing this before might be to mock with global.__DEV__ = false;. It's probably not what we want to suggest long term, but might be enough to get you unblocked. I believe we're going to re-evaluate environment variable usage soon, and this is possibly something we can make better as well when we do that.

KevinGrandon avatar Aug 03 '18 17:08 KevinGrandon

I'd be happy to do that, but it doesn't appear to have any effect. I had thought __DEV__ was replaced during compile?

simonrobb avatar Aug 03 '18 19:08 simonrobb

I'd be happy to do that, but it doesn't appear to have any effect. I had thought DEV was replaced during compile?

I think it depends on when you set it. If you set it before the code executes, it should work. We use a babel transformer for jest tests, so the build is a little bit different. Happy to sit with you next week to see if we can figure out a quick workaround if you want.

KevinGrandon avatar Aug 03 '18 21:08 KevinGrandon