pp-parachute
Version:
Airdrop JS Applications
75 lines (68 loc) • 2.94 kB
JavaScript
var StyleBundler = require('../../bundlers/style_bundler');
var path = require('path');
var fs = require('fs');
describe('StyleBundler', function() {
it('should bundle styles', function(done) {
var s = new StyleBundler('scss/**/*.scss');
s.build().then(function(bundler) {
expect(bundler.rawOutput).toBeDefined();
done();
});
});
it('should return an error object on fail', function(done) {
var s = new StyleBundler('scss/**/*.scss');
var failPath = __dirname + "/scss/fail.scss";
fs.writeFileSync(failPath, "{}");
s.build().then(function(bundler) {
expect(typeof bundler.rawOutput).toBe('object');
expect(bundler.rawOutput.path).toBeDefined();
expect(bundler.rawOutput.error).toBeDefined();
fs.existsSync(failPath) && fs.unlinkSync(failPath);
done();
});
});
it('should watch and bundle and recompile on add', function(done) {
var s = new StyleBundler('scss/**/*.scss');
var writePath = __dirname + "/scss/add.scss";
s.watch().then(function(bundler) {
s.on('bundleCompleted', function() {
expect(bundler.rawOutput).toBeDefined();
expect(bundler.rawOutput.indexOf(".stuff")).not.toBe(-1);
s.shutdown();
fs.existsSync(writePath) && fs.unlinkSync(writePath);
done();
});
fs.writeFileSync(writePath, ".stuff {color:red;}");
});
});
it('should watch a bundle and recompile on change', function(done) {
var s = new StyleBundler('scss/**/*.scss');
var writePath = __dirname + "/scss/change.scss";
fs.writeFileSync(writePath, ".stuff {color:red;}");
s.watch().then(function(bundler) {
s.on('bundleCompleted', function() {
expect(bundler.rawOutput).toBeDefined();
expect(bundler.rawOutput.indexOf(".stuff")).toBe(-1);
expect(bundler.rawOutput.indexOf(".more-stuff")).not.toBe(-1);
s.shutdown();
fs.existsSync(writePath) && fs.unlinkSync(writePath);
done();
});
fs.writeFileSync(writePath, ".more-stuff {color:blue;}");
});
});
it('should watch a bundle and recompile on remove', function(done) {
var s = new StyleBundler('scss/**/*.scss');
var writePath = __dirname + "/scss/change.scss";
fs.writeFileSync(writePath, ".stuff {}");
s.watch().then(function(bundler) {
s.on('bundleCompleted', function() {
expect(bundler.rawOutput).toBeDefined();
expect(bundler.rawOutput.indexOf(".stuff")).toBe(-1);
s.shutdown();
done();
});
fs.existsSync(writePath) && fs.unlinkSync(writePath);
});
});
});