Reputation: 312
I've got a project where I'm using browserify to manage my dependencies. I use Backbone with Mustache as a templating engine on client side. To require Mustache templates I have to use Stringify like the following to correctly require Mustache templates:
gulp.task('scripts', function() {
gulp.src(['./js/app.js'])
.pipe(browserify({
transform: stringify({
extensions: ['.html'], minify: true
})
}))
.pipe(gulp.dest('dist/assets/js')) });
Now, my tests are running on Karma with browserify. However, when I'm trying to require the template Karma fails throwing the HTML file parsing errors.
e.g.:
var Template = require('../Templates/CodeEditor.html'); var CodeEditor
= Backbone.View.extend({
el: '#CodeEdit',
editor: {}, currentPreviewMode: "default",
template: function() {
return Mustache.to_html(Template, this.model.toJSON());
} });
Is it possible to configure Karma to use Stringify? If so how? Please help.
Below is my Kara config.
module.exports = function(config) { config.set({
basePath: './js/',
frameworks: ['browserify', 'jasmine'],
browserify: {
debug: true,
transform: [ 'brfs', 'browserify-shim']
},
files: [
'**/**/*.js'
],
exclude: [],
preprocessors: {
'modules/**/*.js': [ 'browserify' ]
},
reporters: ['dots'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: [ 'PhantomJS' ],
singleRun: false }); };
and part of the package.json for reference:
"devDependencies": {
"brfs": "^1.4.0",
"browserify": "^9.0.3",
"browserify-shim": "^3.8.3",
"chai": "^2.2.0",
"del": "^1.1.1",
"gulp": "^3.8.11",
"gulp-autoprefixer": "^2.1.0",
"gulp-browserify": "^0.5.1",
"jasmine": "^2.2.1",
"jasmine-core": "^2.2.0",
"karma": "^0.12.31",
"karma-browserify": "^4.1.2",
"karma-chrome-launcher": "^0.1.7",
"karma-phantomjs-launcher": "^0.1.4",
"karma-jasmine": "^0.3.5",
"map-stream": "0.0.5",
"stringify": "^3.1.0"
},
"browserify-shim": {
"jQuery": "global:jQuery",
"Backbone": "global:Backbone"
}
Thank you
Upvotes: 0
Views: 1758
Reputation: 73
Check this out. Might be what you are looking for.
Just add
browserify: {
transform: ['stringify']
},
to your karma.conf.js (and also make sure to have stringify installed as a node module)
https://gist.github.com/busypeoples/e4ec7e7c1f1a753050dd
UPDATES: You can also add options to the transform itself like
transform: [
['stringify', {extensions: ['.java'], minify: true}]
]
https://github.com/Nikku/karma-browserify#transforms
Upvotes: 3