A preprocessor for Karma that does string replacement on module content on the fly.
The easiest way is to keep karma-string-replace-preprocessor
as a devDependency.
You can simple do it by:
npm install karma-string-replace-preprocessor --save-dev
Following code shows the default configuration
// karma.conf.js
module.exports = function(config) {
config.set({
preprocessors: {
'src/**/*.js': [ 'stringreplace' ]
},
stringReplacePreprocessor: {
patterns: [
{ match: 'stringToReplaceOne', replacement: 'This string has been replace with number one.' },
{ match: 'stringToReplaceTwo', replacement: 'This string has been replace with number two.' }
]
},
...
})
}
See the Karma Documentation for additional details on custom - in this case, preprocessor - plugin development.
Dependency Injection in Karma is handled by Node-DI, but that library is deprecated. See the author's readme notes in the repo. Just something to be aware of as this dependency may change in Karma in the future. And, it defines $inject
, which is something on which this plugin relies.
Logger is another dependency of Karma. See log4js