I managed to get it working, using Chutzpah's compile option. I ported karma-ng-html2js-preprocessor into a PowerShell script and then call that from Chutzpah to compile the HTML into JS files.
Added PowerShell script next to chutzpah.json settings file (the below script contains untested support for PreprendPrefix and StripSuffix)
# PowerShell port of https://github.com/karma-runner/karma-ng-html2js-preprocessor
Param (
[parameter(Mandatory=$true)] [string] $Path,
[string] $Module = '',
[string] $StripPrefix = '',
[string] $PrependPrefix = '',
[string] $StripSuffix = ''
)
Function EscapeContent($content) {
$content -replace "\\", "\\\\" -replace "'", "\'" -replace "`r?`n", "\n' +`n '"
}
Function Rename($fileName) {
"$PrependPrefix" + ("$fileName" -replace "$StripPrefix", '' -replace "$StripSuffix", '' -replace "\\", "/")
}
$Template = If ("$Module" -eq "") {
"angular.module('{0}', []).run(function(`$templateCache) {{`n" `
+ " `$templateCache.put('{0}',`n '{2}');`n" `
+ "}});`n"
} Else {
"(function(module) {{`n" `
+ "try {{`n" `
+ " module = angular.module('{1}');`n" `
+ "}} catch (e) {{`n" `
+ " module = angular.module('{1}', []);`n" `
+ "}}`n" `
+ "module.run(function(`$templateCache) {{`n" `
+ " `$templateCache.put('{0}',`n '{2}');`n" `
+ "}});`n" `
+ "}})();`n"
}
Get-ChildItem $Path -Recurse -Filter *.html | Foreach-Object {
$content = Get-Content $_.FullName | Out-String
$content = EscapeContent $content
$fileName = Rename "$($_.FullName)"
("$Template" -f "$fileName", "$Module", "$content") | Set-Content "$($_.FullName).js"
}
Added compile configuration to chutzpah.json and add the "compiled" JS files to References (the reference could added from the test file, but I prefer to use chutzpah.json to manage all the references)
{
"References": [
{ "Path": "./path/to/templates/", "Include": "*.html.js" },
],
"Compile": {
"Extensions": [".html"],
"ExtensionsWithNoOutput": [".html.js"],
"SourceDirectory": "./path/to/templates",
"OutDirectory": "./path/to/templates",
"Executable": "%powershellexe%",
"Arguments": "-NoProfile %chutzpahsettingsdir%\\chutzpah-ng-html2js-compiler.ps1 -Path '/path/to/templates/' -Module 'templates' -StripPrefix '.+(?=\\\\templates)'"
}
}
In your test files, load the module, in my case they are all in 'templates' module
beforeEach(module('templates'));
// or alternatively
beforeEach(module('/path/to/templates/foo.html'));