I have big problems getting Karma to serve the json files needed in my application. I don’t want to mock json, I just need it to serve on the karma server.
When I browse the Karma browser, I can upload the HTML files in the templates folder. But the JSON files in the data folder were not found.
But I configured both folders the same way!
I tried to add the fixture plugin, but it does not affect the JSON files served.
My karma configuration:
module.exports = function(config) {
config.set({
basePath: './',
frameworks: [
'jasmine-jquery',
'jasmine',
'requirejs',
'fixture'
],
files: [
{pattern: 'frontend/js/*.js', watched: true, served: true, included: false},
{pattern: 'frontend/templates/*.*', watched: true, served: true, included: false},
{pattern: 'frontend/data/*.json', watched: true, served: true, included: false},
{pattern: 'test/**/*Spec.js', watched: true, included: false},
'test/helpers/jasmine-ajax-helper.js',
'test/test-main.js'
],
proxies: {
"/templates/": "/base/frontend/templates/",
"/base/../templates/": "/base/frontend/templates/",
"/data/": "/base/frontend/data/",
"/base/../data/": "/base/frontend/data/"
},
preprocessors: {
'**/*.json' : ['json_fixtures']
},
jsonFixturesPreprocessor: {
variableName: '__json__'
},
port: 9876,
colors: true,
logLevel: config.LOG_WARN,
autoWatch: true,
browsers: [
'Firefox'
],
singleRun: false,
});
};
One of my applications requireJS modules load JSON files:
define([
"text!../data/mydata.json"
], function (crowdUI, jsonDATA) {
'use strict';
fields = JSON.parse(jsonDATA);
});