Created
November 10, 2017 01:25
-
-
Save derekshi/e118442381bb0154e5acfb50f167a200 to your computer and use it in GitHub Desktop.
preprocessor script for using Jest testing framework on Angular projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const process = require('ts-jest/preprocessor.js').process; | |
const TEMPLATE_URL_REGEX = /templateUrl:\s*('|")(\.\/){0,}(.*)('|")/g; | |
const STYLE_URLS_REGEX = /style(Url)?s:\s*\[\s*(require\()?((?:'|").*\s*(?:'|")\)?).*\s*.*\]/g; | |
const ESCAPE_TEMPLATE_REGEX = /(\${|\`)/g; | |
module.exports.process = function (src, path, config, transformOptions) { | |
if (path.endsWith('.html')) { | |
console.log('preprocessing ' + path); | |
src = src.replace(ESCAPE_TEMPLATE_REGEX, '\\$1'); | |
} | |
if (path.endsWith('.ts')) { | |
console.log('preprocessing ' + path); | |
src = src | |
.replace(TEMPLATE_URL_REGEX, 'template: require($1./$3$4)') | |
.replace(STYLE_URLS_REGEX, 'styles: []'); | |
} | |
return process(src, path, config, transformOptions); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment