karma-ng-hamlet2js-preprocessor
Version:
A karma plugin to compile Hamlet HTML templates to JavaScript on the fly.
38 lines (28 loc) • 1.18 kB
JavaScript
var child_proc = require("child_process");
var hamlet2js = require("./../../lib/hamlet2js.js");
//Mocks out proc.execFile to return the given error, stdout, and stderr
//Returns the spy for the stdin used for exec.
exports.mockExec = function(error, stdout, stderr) {
var stdinSpy = createSpyObj("stdin", ["write", "end"]);
spyOn(child_proc, 'execFile').and.callFake(function(prog, args, opts, done) {
done(error, stdout, stderr);
return { stdin: stdinSpy };
});
return stdinSpy;
};
//Calls hamlet2js with the given args. Returns a spy for the done function passed to hamlet2js.
exports.callHamlet = function(config, filePath, fileOriginalPath) {
var logger =
{ create: function() {
return { debug: createSpy("debug log"),
error: createSpy("debug error"),
};
}
};
var func = hamlet2js(logger, config);
var file = { path: filePath, originalPath: fileOriginalPath };
var doneSpy = createSpy("processDone");
func("", file, doneSpy);
expect(file.path).toEqual(filePath + ".js");
return doneSpy;
}