diff --git a/.jshintrc b/.jshintrc index be66a1b..96e0042 100644 --- a/.jshintrc +++ b/.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 } diff --git a/Gruntfile.js b/Gruntfile.js index ac185ab..ad4be52 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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 } } @@ -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: { @@ -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: { @@ -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); diff --git a/tasks/critical.js b/tasks/critical.js index 7faefa1..0c4ac13 100644 --- a/tasks/critical.js +++ b/tasks/critical.js @@ -82,8 +82,8 @@ 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 }); }) @@ -91,13 +91,13 @@ module.exports = function (grunt) { .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)) { @@ -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) { @@ -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); }); diff --git a/test/index.js b/test/index.js index ab80f04..319418b 100644 --- a/test/index.js +++ b/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'); @@ -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('pagex','page' + i + '')); + expect(output).to.equal(expected.replace('pagex', 'page' + 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++) { + 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('pagex','page' + i + '')); + expect(output).to.equal(expected.replace('pagex', 'page' + i + '')); } }); - 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); @@ -76,23 +77,23 @@ 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('pagex','page' + i + '')); + expect(output).to.equal(expected.replace('pagex', 'page' + i + '')); } }); - 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'); @@ -100,7 +101,7 @@ describe('critical',function(){ 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');