Reputation: 11755
I have a module which I want to write a test for. I use webpack to transpile it because I'm writing it in ES6.
The file (app.js) starts like this:
import template from './app.html'; // pulls in the template for this component
import './app.scss'; // pulls in the styles for this component
But when I run the test, I get an error that app.scss is not found
ERROR in ./src/app.js
Module not found: Error: Cannot resolve module 'scss' in /Users/.../src
@ ./src/app.js 11:0-21
13 05 2016 10:38:52.276:INFO [..browserinfo..]: Connected on socket /#KYFiNbOR-7lqgc9qAAAA with id 63011795
(browser) ERROR
Uncaught Error: Cannot find module "./app.scss"
at /Users/.../spec.bundle.js:34081 <- webpack:///src/app.js:4:0
Finished in 0.241 secs / 0 s
The test starts like this:
import angular from 'angular';
import header from './app.js'; // error occurs here cause .scss file is not recognized
describe('my module', () => {
let $rootScope, makeController;
// testing stuff
});
My karma.conf.js file includes this:
webpack: {
devtool: 'inline-source-map',
module: {
loaders: [
{ test: /\.js/, exclude: [/app\/lib/, /node_modules/], loader: 'babel' },
{ test: /\.html/, loader: 'raw' },
{ test: /\.scss/, loader: 'style!css!scss' },
{ test: /\.css$/, loader: 'style!css' }
]
}
}
How do I get karma/webpack to read the scss file correctly and run my tests?
Upvotes: 1
Views: 3425
Reputation: 11755
The problem was a typo:
scss
should have been sass
webpack: {
module: {
loaders: [
...,
{ test: /\.scss/, loader: 'style!css!sass' },
...
]
}
}
Upvotes: 1