diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/spec/writerSpec.js | 34 | ||||
| -rw-r--r-- | docs/src/writer.js | 8 |
2 files changed, 39 insertions, 3 deletions
diff --git a/docs/spec/writerSpec.js b/docs/spec/writerSpec.js index c0f80de3..1c25078c 100644 --- a/docs/spec/writerSpec.js +++ b/docs/spec/writerSpec.js @@ -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'); + }); + }); }); diff --git a/docs/src/writer.js b/docs/src/writer.js index c9089be0..cdfa12d6 100644 --- a/docs/src/writer.js +++ b/docs/src/writer.js @@ -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); }); |
