ES6 code doesn't work?
See original GitHub issueI’m having some issues running my tests that contain ES6 code? They run just fine if I open up the test.js file in say Chrome where V8 is definitely ready to handle ES6 but not in the interpreter packaged with phantomjs.
Is there anyway to make mocha-phantomjs compatible with ES6 besides pre-babelifying the test.js file?
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
ES6 support in VSCode isnt working - Stack Overflow
To turn ES6/ES7 support, the best way is to use ESLint with dedicated parser ( babel, etc...). I try it if you're interested:...
Read more >ES6 syntax support isn't working in VSCode #2394 - GitHub
I cloned the ES6 example repo (https://github.com/jrieken/es6-vscode-sample), but when I open it, the syntax support is broken.
Read more >How to fix the 'let' is available in ES6 error in VS Code
This is a quick video on how to fix the "'let' is available in ES6 " error in VS Code. - - -...
Read more >How to enable ES6 (and beyond) syntax with Node and Express
We need a package that translates ES6 and above syntax to ES5 code. ES5 code is the JS syntax style that is readable...
Read more >Arrow function expressions - JavaScript - MDN Web Docs
Returning object literals using the concise body syntax (params) => { object: literal } does not work as expected.
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

Right. I was just wondering if there was a convenient way to run my tests with ES6 code without always including them in my Webpack config or setting up multiple configs for different environments (as recommended here: https://stackoverflow.com/questions/28572380/conditional-build-based-on-environment-using-webpack).
The project I’m currently working on is otherwise pretty simple, so that seemed like more of a hassle than it would be worth.
I found a solution that was less effort but still required a little bit of fiddling. Basically when testing I now run webpack with a specific NODE_ENV and conditionally include include my test files in the list of entry points.
Now I have this script in my package.json and can run the tests with
npm test:"test": "NODE_ENV=test node_modules/.bin/webpack && node_modules/.bin/mocha-phantomjs test.html"This bundles my application and test code and then runs mocha-phantomjs. Note that I am using locally installed binaries in case other devs don’t have webpack or mocha-phantomjs installed globally, but this command would be cleaner if I referenced the global modules instead.
My test.html does not need to explicitly include my test files now, as they are in the bundle:
And I can use ES2015 all over the place!
I also have an npm build script where NODE_ENV is set to production, which runs webpack without including my tests.
Yup that works. #hipstertax (I pay it too sometimes 😃