Navigation Menu

Skip to content

Commit

Permalink
Lint tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Jun 11, 2016
1 parent ee7bb26 commit 03cff83
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 50 deletions.
12 changes: 6 additions & 6 deletions .jshintrc
@@ -1,13 +1,13 @@
{
"node": true,
"esnext": true,
"bitwise": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"undef": true,
"unused": "vars",
"node": true,
"strict": true,
"mocha": true
"sub": true,
"undef": true,
"unused": true
}
33 changes: 18 additions & 15 deletions Gruntfile.js
Expand Up @@ -15,7 +15,7 @@ module.exports = function (grunt) {
options: {
errorsOnly: false,
cyclometric: 3, // default is 3
halstead: 8, // default is 8
halstead: 8, // default is 8
maintainability: 100 // default is 100
}
}
Expand Down Expand Up @@ -170,10 +170,13 @@ module.exports = function (grunt) {
width: 1300,
height: 900
},
files: [
// makes all src relative to cwd
{expand: true, cwd: 'test/fixture/', src: ['multiple/**/*.html'], dest: 'test/generated/'}
]
// makes all src relative to cwd
files: [{
expand: true,
cwd: 'test/fixture/',
src: ['multiple/**/*.html'],
dest: 'test/generated/'
}]
},
'test-multiple-minified': {
options: {
Expand All @@ -186,15 +189,13 @@ module.exports = function (grunt) {
width: 1300,
height: 900
},
files: [
// makes all src relative to cwd
{
expand: true,
cwd: 'test/fixture/multiple',
src: ['**/*.html'],
dest: 'test/generated/multiple-min'
}
]
// makes all src relative to cwd
files: [{
expand: true,
cwd: 'test/fixture/multiple',
src: ['**/*.html'],
dest: 'test/generated/multiple-min'
}]
},
'test-external': {
options: {
Expand Down Expand Up @@ -258,7 +259,9 @@ module.exports = function (grunt) {

var server;
grunt.registerTask('startServer', function () {
var serve = serveStatic('test/fixture', {'index': ['index.html', 'index.htm']});
var serve = serveStatic('test/fixture', {
index: ['index.html', 'index.htm']
});

server = http.createServer(function (req, res) {
var done = finalhandler(req, res);
Expand Down
14 changes: 7 additions & 7 deletions tasks/critical.js
Expand Up @@ -82,22 +82,22 @@ module.exports = function (grunt) {

options.css = _.chain(options.css)
.compact()
.map(function(css){
return glob.sync(css,{
.map(function(css) {
return glob.sync(css, {
nosort: true
});
})
.flatten()
.value();
}

grunt.log.debug('SOURCE',srcFiles);
grunt.log.debug('SOURCE', srcFiles);

grunt.log.debug('CSS',options.css);
grunt.log.debug('CSS', options.css);

async.eachSeries(srcFiles, function (src, cb) {
var opts = _.assign({
inline: !/\.(css|scss|less|styl)/.test(path.extname(f.dest))
inline: !/\.(css|scss|less|styl)/.test(path.extname(f.dest))
}, options);

if (!isExternal(src)) {
Expand All @@ -110,7 +110,7 @@ module.exports = function (grunt) {
if (isDir(f.dest)) {
destination = path.join(f.dest, opts.src);
}
grunt.log.debug('opts',opts);
grunt.log.debug('opts', opts);


critical.generate(opts).then(function (output) {
Expand All @@ -120,7 +120,7 @@ module.exports = function (grunt) {

cb(null, output);
}).error(function (err) {
grunt.log.error('File "' + destination + '" failed.',err.message || err);
grunt.log.error('File "' + destination + '" failed.', err.message || err);
cb(err);
});

Expand Down
45 changes: 23 additions & 22 deletions test/index.js
@@ -1,25 +1,26 @@
/* jshint mocha: true */

'use strict';

var expect = require('chai').expect,
path = require('path'),
fs = require('fs');


function strip(string) {
return string.replace(/[\r\n]+/mg,' ').replace(/\s+/gm,'');
return string.replace(/[\r\n]+/mg, ' ').replace(/\s+/gm, '');
}

function read(file) {
return strip(fs.readFileSync(path.join(__dirname,file),'utf8'));
return strip(fs.readFileSync(path.join(__dirname, file), 'utf8'));
}

function exists(file) {
return fs.existsSync(path.join(__dirname,file));
return fs.existsSync(path.join(__dirname, file));

}

describe('critical',function(){


describe('critical', function() {

it('generates minified critical-path CSS successfully', function () {
var expected = read('expected/critical.css');
Expand Down Expand Up @@ -49,25 +50,25 @@ describe('critical',function(){
expect(exists('fixture/styles/bootstrap.d87cfcd2.css')).to.equal(true);
});

it('generates multiple html files without throwing "warning: possible EventEmitter memory leak detected"', function(){
var output,expected = read('expected/index-multiple.html');
for (var i=1; i<=5; i++) {
it('generates multiple html files without throwing "warning: possible EventEmitter memory leak detected"', function() {
var output, expected = read('expected/index-multiple.html');
for (var i = 1; i <= 5; i++) {

output = read('generated/multiple/index' + i + '.html');
expect(output).to.equal(expected.replace('<title>pagex</title>','<title>page' + i + '</title>'));
expect(output).to.equal(expected.replace('<title>pagex</title>', '<title>page' + i + '</title>'));
}
});

it('generates multiple html files with minified css', function(){
var output,expected = read('expected/index-multiple-minified.html');
for (var i=1; i<=12; i++) {
it('generates multiple html files with minified css', function() {
var output, expected = read('expected/index-multiple-minified.html');
for (var i = 1; i <= 12; i++) {

output = read('generated/multiple-min/index' + i + '.html');
expect(output).to.equal(expected.replace('<title>pagex</title>','<title>page' + i + '</title>'));
expect(output).to.equal(expected.replace('<title>pagex</title>', '<title>page' + i + '</title>'));
}
});

it('should keep external urls with extract option', function(){
it('should keep external urls with extract option', function() {
var expected = read('expected/index-external.html');
var output = read('generated/index-external.html');
expect(output).to.equal(expected);
Expand All @@ -76,31 +77,31 @@ describe('critical',function(){
expect(exists('fixture/styles/bootstrap.7243c5e5.css')).to.equal(true);
});

it('should write files to folder when folder is specified as dest', function(){
var output,expected = read('expected/index-multiple-minified.html');
it('should write files to folder when folder is specified as dest', function() {
var output, expected = read('expected/index-multiple-minified.html');

for (var i=1; i<=3; i++) {
for (var i = 1; i <= 3; i++) {
expect(exists('generated/multiple-files-folder/multiple/index'+i+'.html')).to.equal(true);
output = read('generated/multiple-files-folder/multiple/index'+i+'.html');
expect(output).to.equal(expected.replace('<title>pagex</title>','<title>page' + i + '</title>'));
expect(output).to.equal(expected.replace('<title>pagex</title>', '<title>page' + i + '</title>'));
}
});

it('should consider ignore option', function(){
it('should consider ignore option', function() {
var expected = read('expected/critical-ignore.css');
var output = read('generated/critical-ignore.css');
expect(output).to.equal(expected);
});

it('should allow glob pattern for css option', function(){
it('should allow glob pattern for css option', function() {
var expected = read('expected/critical.css');
var output1 = read('generated/critical-glob.css');
var output2 = read('generated/critical-glob2.css');
expect(output1).to.equal(expected);
expect(output2).to.equal(expected);
});

it('should allow remote sources', function(){
it('should allow remote sources', function() {
var expectedCss = read('expected/critical.css');
var expectedHtml = read('expected/index-minified.html');
var outputCss = read('generated/remote.css');
Expand Down

0 comments on commit 03cff83

Please sign in to comment.