NODE_ENV must currently be set to "test"
See original GitHub issueSoftware 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:
- Created 4 years ago
- Comments:12 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@hawkeye64 suggests: Use QENV
https://github.com/quasarframework/app-extension-qenv
Would there be an environment that testing shouldn’t be run in? If not, this could be a nice catch all:
Order is debatable of course.