mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
parent
71bc1b761d
commit
73f8112032
2 changed files with 39 additions and 3 deletions
|
|
@ -1,7 +1,26 @@
|
|||
var writer = require('../src/writer.js');
|
||||
var writer,
|
||||
rewire = require('rewire');
|
||||
|
||||
function mockResolvedPromise(resolvedValue) {
|
||||
return {
|
||||
then: function(success, failure) {
|
||||
success(resolvedValue);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
describe('writer', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
writer = rewire('../src/writer.js');
|
||||
});
|
||||
|
||||
describe('toString', function() {
|
||||
var toString = writer.toString;
|
||||
var toString;
|
||||
|
||||
beforeEach(function() {
|
||||
toString = writer.toString;
|
||||
});
|
||||
|
||||
it('should merge string', function() {
|
||||
expect(toString('abc')).toEqual('abc');
|
||||
|
|
@ -31,4 +50,15 @@ describe('writer', function() {
|
|||
expect(content).toBe('ng super jqlite manifest');
|
||||
});
|
||||
});
|
||||
|
||||
describe('copy', function() {
|
||||
it('should call the transformation function', function() {
|
||||
var readMock = jasmine.createSpy('readMock').andReturn(mockResolvedPromise('DUMMY CONTENT'));
|
||||
writer.__set__("qfs.read", readMock);
|
||||
var transformationFn = jasmine.createSpy('transformationFn');
|
||||
writer.copy('from', 'to', transformationFn, 'arg1', 'arg2');
|
||||
expect(readMock).toHaveBeenCalled();
|
||||
expect(transformationFn).toHaveBeenCalledWith('DUMMY CONTENT', 'arg1', 'arg2');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -51,13 +51,19 @@ exports.copyTemplate = function(filename) {
|
|||
* @param transform{function=} transfromation function to be applied before return
|
||||
*/
|
||||
exports.copy = function(from, to, transform) {
|
||||
var transformArgs = Array.prototype.slice.call(arguments, 3);
|
||||
|
||||
from = pathUtils.normalize(from);
|
||||
to = pathUtils.normalize(to);
|
||||
|
||||
// We have to use binary reading, Since some characters are unicode.
|
||||
return qfs.read(from, 'b').then(function(content) {
|
||||
if (transform) {
|
||||
content = transform.call(null, content.toString(), from, to, transform);
|
||||
// Pass any extra arguments, e.g.
|
||||
// `copy(from, to, transform, extra1, extra2, ...)`
|
||||
// to the transform function
|
||||
transformArgs.unshift(content.toString());
|
||||
content = transform.apply(null, transformArgs);
|
||||
}
|
||||
return output(to, content);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue