UNPKG

pp-parachute

Version:
96 lines (89 loc) 4.06 kB
var TemplateBundler = require('../../bundlers/template_bundler'); var path = require('path'); var fs = require('fs'); describe('TemplateBundler', function () { it('should build templates', function (done) { var bundler = new TemplateBundler('haml/**/*.haml'); bundler.build().then(function () { expect(bundler.rawOutput.indexOf('angular')).not.toBe(-1); expect(bundler.rawOutput.indexOf('%')).toBe(-1); done(); }); }); it('should have a settable template root path', function (done) { var bundler = new TemplateBundler('haml/**/*.haml') .setTemplateRoot(__dirname + '/haml'); bundler.build().then(function () { expect(bundler.rawOutput.indexOf('haml/')).toBe(-1); done(); }); }); it('should have a settable module name', function (done) { var bundler = new TemplateBundler('haml/**/*.haml') .setModuleName('testmodule'); bundler.build().then(function () { expect(bundler.rawOutput.indexOf("angular.module('testmodule', [])")).not.toBe(-1); done(); }); }); it('should watch a bundle and recompile on add', function (done) { var bundler = new TemplateBundler('haml/*.haml'); var writePath = __dirname + "/haml/add.haml"; fs.existsSync(writePath) && fs.unlinkSync(writePath); bundler.watch().then(function () { bundler.on('bundleSucceeded', function () { expect(bundler.rawOutput.indexOf("<div class='here-i-am'></div>")).not.toBe(-1); bundler.shutdown(); fs.existsSync(writePath) && fs.unlinkSync(writePath); done(); }); fs.writeFileSync(writePath, "%div.here-i-am"); }); }); it('should watch a bundle and recompile on change', function (done) { var writePath = __dirname + "/haml/change.haml"; fs.existsSync(writePath) && fs.unlinkSync(writePath); fs.writeFileSync(writePath, "%div.here-i-am"); var bundler = new TemplateBundler('haml/*.haml'); bundler.watch().then(function () { bundler.on('bundleSucceeded', function () { expect(bundler.rawOutput.indexOf("<div class='here-i-am'></div>")).toBe(-1); expect(bundler.rawOutput.indexOf("<div class='i-have-changed'></div>")).not.toBe(-1); bundler.shutdown(); fs.existsSync(writePath) && fs.unlinkSync(writePath); done(); }); fs.writeFileSync(writePath, "%div.i-have-changed"); }); }); it('should watch a bundle and recompile on remove', function (done) { var writePath = __dirname + "/haml/remove.haml"; fs.existsSync(writePath) && fs.unlinkSync(writePath); fs.writeFileSync(writePath, "%div.here-i-am"); var bundler = new TemplateBundler('haml/*.haml'); bundler.watch().then(function () { bundler.on('bundleSucceeded', function () { expect(bundler.rawOutput.indexOf("<div class='here-i-am'></div>")).toBe(-1); bundler.shutdown(); done(); }); fs.existsSync(writePath) && fs.unlinkSync(writePath); }); }); it('should report errors in compilation', function(done) { var bundler = new TemplateBundler('haml/*.haml'); var writePath = __dirname + "/haml/error.haml"; fs.existsSync(writePath) && fs.unlinkSync(writePath); bundler.watch().then(function () { bundler.on('bundleFailed', function () { expect(typeof bundler.rawOutput).toBe('object'); expect(bundler.rawOutput.path).toBeDefined(); expect(bundler.rawOutput.error).toBeDefined(); bundler.shutdown(); fs.existsSync(writePath) && fs.unlinkSync(writePath); done(); }); fs.writeFileSync(writePath, "-x"); }); }); });