Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Webpack] File Loaders cause mocha to throw Syntax Error #1

Closed
pl12133 opened this issue Nov 18, 2015 · 8 comments
Closed

[Webpack] File Loaders cause mocha to throw Syntax Error #1

pl12133 opened this issue Nov 18, 2015 · 8 comments

Comments

@pl12133
Copy link

pl12133 commented Nov 18, 2015

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
@bruderstein
Copy link
Owner

Thanks for reporting the fix! I've added your text to the wiki, so hopefully people can find it if they need it.
https://github.com/bruderstein/unexpected-react/wiki/Webpack-Loader-issue

@mattdell
Copy link

+1

Helped me solve what I thought was a fairly obscure issue.

@siawyoung
Copy link

+1, saved my life

@mrberggg
Copy link

mrberggg commented Mar 9, 2016

Thanks for posting this, saved me!

@pl12133
Copy link
Author

pl12133 commented 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.

@crabbits
Copy link

+1

2 similar comments
@rewmike
Copy link

rewmike commented Apr 29, 2016

+1

@Qquanwei
Copy link

+1

bruderstein pushed a commit that referenced this issue Aug 6, 2017
Update the jest-integration tests for unexpected10.30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants