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.

Mocha unit tests failing

See original GitHub issue

This might not be an issue specific to this project, but I haven’t been able to find a solution. When running npm run test out of the box, it looks like es6 imports aren’t working:

$ yarn test
yarn test v0.18.1
$ mocha --compilers js:babel-register
/Users/akoehler/Development/Repos/react-static-boilerplate/test/base.test.js:1
(function (exports, require, module, __filename, __dirname) { import { expect } from 'chai';
                                                              ^^^^^^
SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
...
...

I installed with node v6.9.4.

edit: I was able to get this working by copying the babel configuration in package.json to a .babelrc file within the test directory and removing the "modules": false configuration from the “es2015” preset.

{
  "presets": [
    "react",
    "es2015",
    "stage-1"
  ],
  "plugins": [
    "transform-runtime"
  ]
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
amkoehlercommented, Jan 20, 2017

Implemented the fix worked for me. If anyone else out there is using Relay and needing to add babelRelayPlugin as a preset, this is what my webpack.config.js looks like:

const babelConfig = Object.assign({}, pkg.babel, {
  babelrc: false,
  cacheDirectory: useHMR,
  presets: pkg.babel.presets.map((x) => x === 'latest' ? ['latest', { es2015: { modules: false } }] : x),
});

babelConfig.presets.push({
  plugins: [
    path.resolve(__dirname, 'babelRelayPlugin.js'),
  ],
});
0reactions
amkoehlercommented, Jan 20, 2017

That should work great. Thanks @koistya!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get Mocha to fail a test - Stack Overflow
The test execution path is correct. When I have validating data, it goes to "SHOULD NOT GET HERE". The test is really to...
Read more >
Mocha - the fun, simple, flexible JavaScript test framework
Mocha is a feature-rich JavaScript test framework running on Node.js and in the ... The above test will fail with Error: Resolution method...
Read more >
Mocha might crash on unit testing failure randomly · Issue #1803
This is hard to provide reproduce code, but we get mocha randomly crashed if there is unit testing failure. We have +700 test...
Read more >
Getting Started with Node.js and Mocha - Semaphore Tutorial
Mocha is a simple, extensible and fast testing library for Node.js. This article will walk you through its installation, configuration and usage.
Read more >
Testing Error Handling in node.js | by Lars Trieloff
I've found myself adapting the following patterns to writing unit tests for ... (and will cause npm test to fail when the thresholds...
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