question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NODE_ENV must currently be set to "test"

See original GitHub issue

Software version

OS: Debian Sid Node: v11.13.0 NPM: 6.7.0

What did you do to get the error?

When NODE_ENV is set to anything but “test”, the babel environment settings required to run the tests are not applied and the babel transpilation fails.

NODE_ENV=development;quasar test --unit jest returns

    /tmp/quasar-test/test/jest/__tests__/App.spec.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import "core-js/modules/es6.array.find";
                                                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    SyntaxError: Unexpected string

      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:513:25)

What were you expecting?

Tests to run without babel errors.

What steps did you take, to get the error?

export NODE_ENV=development
quasar create sample -b dev
cd sample
quasar ext add @quasar/testing
quasar test --unit jest

Possible solution

babel.config.js

const fs = require('fs-extra')
let extend

const env = {
  'plugins': ['dynamic-import-node'],
  'presets': [
    [
      '@babel/preset-env',
      {
        'modules': 'commonjs',
        'targets': {
          'node': 'current'
        }
      }
    ]
  ]
}

/**
 * The .babelrc file has been created to assist Jest for transpiling.
 * You should keep your application's babel rules in this file.
 */

if (fs.existsSync('./.babelrc')) {
  extend = './.babelrc'
}

module.exports = {
  presets: [
    '@quasar/babel-preset-app'
  ],
  extends: extend,
  env: {
    development: env,
    test: env
  }
}

.babelrc

{
  "plugins": ["@babel/plugin-syntax-dynamic-import"]
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
nothingismagickcommented, Apr 5, 2019

@hawkeye64 suggests: Use QENV

  "scripts": {
    "dev": "QENV=development quasar dev",
    "test-dev": "QENV=test quasar dev",
    "combined": "QENV=development+test quasar dev",
    "build": "QENV=production quasar build"
  },

https://github.com/quasarframework/app-extension-qenv

1reaction
RichAyottecommented, Apr 6, 2019

Would there be an environment that testing shouldn’t be run in? If not, this could be a nice catch all:

process.env.NODE_ENV || process.env.QUSAR_TEST || process.env.QENV || 'test'

Order is debatable of course.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The test NODE_ENV isn't being set properly #17032 - GitHub
Bug report Describe the bug Currently, Next.js only supports three different values for process.env.NODE_ENV (as documented here): ...
Read more >
node.js - NODE_ENV with Jest - Stack Overflow
Jest automatically defines environment variable NODE_ENV as test ... This should also automatically set NODE_ENV=test when running jest .
Read more >
Working with Environment Variables in Node.js - Twilio
Environment variables are a great way to configure parts of your Node.js application. Learn how to work with them using helpful tools such ......
Read more >
Build your Node image - Docker Documentation
Test the application . Let's start our application and make sure it's running properly. Open your terminal and navigate to your working...
Read more >
Using Environment Variables in Node.js for App Configuration ...
Set the NODE_ENV environment variable to "development" , enabling debug mode ... you should try to avoid defaults in your application code, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found