Permalink
Browse files

Merge pull request #36 from denar90/patch-1

Improvements
  • Loading branch information...
paulmillr committed Jan 3, 2017
2 parents d906313 + 620034c commit 27478762246c929ed36140bc81571dbe76fb7019
Showing with 67 additions and 35 deletions.
  1. +8 −4 package.json
  2. +59 −31 test.js
View
@@ -14,16 +14,20 @@
"url": "git@github.com:brunch/jade-brunch.git"
},
"scripts": {
- "test": "node_modules/.bin/eslint index.js && node_modules/.bin/mocha"
+ "test": "eslint index.js && mocha"
},
"dependencies": {
"jade": "~1.11.0",
"progeny": "~0.5.2",
"umd-wrapper": "~0.1.0"
},
"devDependencies": {
- "chai": "^3.3.0",
- "mocha": "^2.3.3",
- "eslint": "^2.1.0"
+ "chai": "^3",
+ "mocha": "^3",
+ "eslint": "^3.12.2",
+ "eslint-config-brunch": "brunch/eslint-config-brunch"
+ },
+ "eslintConfig": {
+ "extends": "brunch"
}
}
View
90 test.js
@@ -1,50 +1,78 @@
-var expect = require('chai').expect;
-var Plugin = require('./');
-var jade = require('jade');
-var sysPath = require('path');
-var fs = require('fs');
+'use strict';
-describe('Plugin', function() {
- var plugin;
+const expect = require('chai').expect;
+const Plugin = require('./');
+const jade = require('jade');
+const sysPath = require('path');
+const fs = require('fs');
- beforeEach(function() {
+describe('Plugin', () => {
+ let plugin;
+
+ beforeEach(() => {
plugin = new Plugin({paths: {root: '.'}});
});
- it('should be an object', function() {
+ it('should be an object', () => {
expect(plugin).to.be.ok;
});
- it('should has #compile method', function() {
+ it('should has #compile method', () => {
expect(plugin.compile).to.be.an.instanceof(Function);
});
- it('should compile and produce valid result', function(done) {
- var content = 'doctype html';
- var expected = '<!DOCTYPE html>';
+ it('should compile and produce valid result', () => {
+ const content = 'doctype html';
+ const expected = '<!DOCTYPE html>';
- plugin.compile({data: content, path: 'template.jade'}).then(data => {
+ return plugin.compile({data: content, path: 'template.jade'}).then(data => {
expect(eval(data)()).to.equal(expected);
- done();
}, error => expect(error).not.to.be.ok);
});
- describe('runtime', function() {
+ it('should compile template string with data', () => {
+ const expected = '<!DOCTYPE html>' +
+ '<html lang="en">' +
+ '<title>Brunch is awesome!</title>' +
+ '</html>';
+ const staticContent = 'doctype html' +
+ '\nhtml(lang="en")' +
+ '\n title #{title}';
+
+ plugin = new Plugin({
+ paths: {
+ root: '.'
+ },
+ plugins: {
+ jade: {
+ locals: {
+ title: 'Brunch is awesome!'
+ }
+ }
+ }
+ });
- it('should include jade/runtime.js', function(){
+ return plugin.compileStatic({data: staticContent, path: 'template.jade'}).then(data => {
+ expect(data).to.equal(expected);
+ }, error => expect(error).not.to.be.ok);
+ });
+
+ describe('runtime', () => {
+
+ it('should include jade/runtime.js', () => {
expect(plugin.include).to.match(/jade\/runtime\.js$/);
});
- it('jade/runtime.js should exist', function(){
+ it('jade/runtime.js should exist', () => {
expect(fs.existsSync(plugin.include[0])).to.be.ok;
});
});
- describe('getDependencies', function() {
- it('should output valid deps', function(done) {
- var content = "\
+ describe('getDependencies', () => {
+ it('should output valid deps', done => {
+ const content = "\
include valid1\n\
include valid1.jade\n\
include ../../test/valid1\n\
@@ -57,7 +85,7 @@ include ../../test/valid2.jade\n\
extends /valid4\n\
";
- var expected = [
+ const expected = [
sysPath.join('valid1.jade'),
sysPath.join('app', 'valid3.jade'),
sysPath.join('valid2.jade'),
@@ -66,11 +94,11 @@ extends /valid4\n\
// progeny now only outputs actually found files by default
fs.mkdirSync('app');
- expected.forEach(function(file) {
+ expected.forEach(file => {
fs.writeFileSync(file, 'div');
});
- plugin.getDependencies(content, 'template.jade', function(error, dependencies) {
+ plugin.getDependencies(content, 'template.jade', (error, dependencies) => {
expect(error).not.to.be.ok;
expect(dependencies).to.have.members(expected);
@@ -85,33 +113,33 @@ extends /valid4\n\
});
});
- describe('getDependenciesWithOverride', function() {
- it('should output valid deps', function(done) {
+ describe('getDependenciesWithOverride', () => {
+ it('should output valid deps', done => {
- var content = "\
+ const content = "\
include /valid3\n\
extends /valid4\n\
";
- var expected = [
+ const expected = [
sysPath.join('custom', 'valid3.jade'),
sysPath.join('custom', 'valid4.jade'),
];
// progeny now only outputs actually found files by default
fs.mkdirSync('custom');
- expected.forEach(function(file) {
+ expected.forEach(file => {
fs.writeFileSync(file, 'div');
});
plugin = new Plugin({paths: {root: '.'}, plugins: {jade: {basedir: 'custom'}}});
- plugin.getDependencies(content, 'template.jade', function(error, dependencies) {
+ plugin.getDependencies(content, 'template.jade', (error, dependencies) => {
expect(error).not.to.be.ok;
expect(dependencies).to.have.members(expected);
// clean up temp fixture files
- expected.forEach(function(file) {
+ expected.forEach(file => {
fs.unlinkSync(file);
});
fs.rmdirSync('custom');

0 comments on commit 2747876

Please sign in to comment.