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.

[Webpack] File Loaders cause mocha to throw Syntax Error

See original GitHub issue

I went to integrate this test setup into my project which is built on Webpack. As such my .js files sometimes include files loaded with webpack loaders; for example .png or .scss. Mocha throws a SyntaxError on encountering these, so you need a custom compiler.

My custom compiler src/tests/compiler.js:

'use strict'
var babel = require('babel-core/register');
function noop() {
    return null;
require.extensions['.scss'] = noop;
require.extensions['.css'] = noop;

And new npm test command:

mocha --compilers js:./src/tests/compiler.js ./src/tests/*.spec.js

Issue Analytics

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

github_iconTop GitHub Comments

pl12133commented, Mar 13, 2016

Update: There is now a package called ignore-styles which seems to accomplish the same goals and also may help with testability.

Qquanweicommented, May 11, 2016


Read more comments on GitHub >

github_iconTop Results From Across the Web

Mocha testing failed due to css in webpack - Stack Overflow
The problem is the .less loader that I was using in my webpack.config.test.js file. Simply swapping less-loader for null-loader fixed my problem ...
Read more >
mocha-loader | webpack - JS.ORG
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
Testing Node.js with Mocha and Chai - LogRocket Blog
Also notice that the sum() call is wrapped in a function to test that an error is thrown when non-number arguments are passed....
Read more >
How I solved and debugged my Webpack issue through trial ...
js ) and one of the source files contains an error, the stack trace will simply point to bundle.js . This isn't always...
Read more >
Running Mocha Tests as Native ES6 Modules in a Browser
This is exactly what is needed. Adding script-loader to the webpack config fixed the error. chai.js is loaded and available globally. The final ......
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 Post

No results found

github_iconTop Related Hashnode Post

No results found