karma-json-fixtures-preprocessor
Advanced tools
Comparing version 0.0.0 to 0.0.1
module.exports = (function () { | ||
'use strict'; | ||
var util = require('util'), | ||
TEMPLATE = '' + | ||
'window.__fixtures__ = window.__fixtures__ || {};\n' + | ||
'window.__fixtures__[\'%s\'] = %s;\n'; | ||
var util = require('util'); | ||
function createJsonFixturesPreprocessor(basePath) { | ||
function getTemplate(varName) { | ||
varName = varName ? varName : '__fixtures__'; | ||
return 'window.' + varName + ' = window.' + varName + ' || {};\n' + | ||
'window.' + varName + '[\'%s\'] = %s;\n'; | ||
} | ||
function createJsonFixturesPreprocessor(basePath, config) { | ||
config = typeof config === 'object' ? config : {}; | ||
var stripPrefix = new RegExp('^' + (config.stripPrefix || '')), | ||
prependPrefix = config.prependPrefix || ''; | ||
return function (content, file, done) { | ||
@@ -15,11 +24,17 @@ var fixtureName = file.originalPath | ||
// Set the template | ||
var template = getTemplate(config.variableName); | ||
// Update the fixture name | ||
fixtureName = prependPrefix + fixtureName.replace(stripPrefix, ''); | ||
file.path = file.path.replace(/\.json$/, '.js'); | ||
done(util.format(TEMPLATE, fixtureName, content)); | ||
done(util.format(template, fixtureName, content)); | ||
}; | ||
} | ||
createJsonFixturesPreprocessor.$inject = ['config.basePath']; | ||
createJsonFixturesPreprocessor.$inject = ['config.basePath', 'config.jsonFixturesPreprocessor']; | ||
return createJsonFixturesPreprocessor; | ||
})(); |
{ | ||
"name": "karma-json-fixtures-preprocessor", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "A Karma plugin to compile JSON files and make them accessible from Javascript code", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -27,3 +27,11 @@ karma-json-fixtures-preprocessor | ||
'./fixtures/**/*.json' | ||
] | ||
], | ||
jsonFixturesPreprocessor: { | ||
// strip this from the file path \ fixture name | ||
stripPrefix: 'test/fixtures', | ||
// strip this to the file path \ fixture name | ||
prependPrefix: 'mock/', | ||
// change the global fixtures variable name | ||
variableName: '__mocks__' | ||
} | ||
}); | ||
@@ -30,0 +38,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3847
30
56