Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Feature/issue 8 #22

Open
wants to merge 6 commits into from

4 participants

@fblundun
@alexanderdean

+1 would be awesome to get this released. Hopefully the addition of a test suite should increase confidence in the PR and make merging the other PRs less painful.

Any timeline on getting this released? This is blocking the next release of our own project which is moving to using grunt-yui-compressor but needs the linebreak option.

@mathiasbynens

@alexanderdean I’ll have to review this first. For now you could just point to @fblundun’s fork directly in your package.json – see https://npmjs.org/doc/json.html#Git-URLs-as-Dependencies.

@alexanderdean

I didn't know that was possible - thanks @mathiasbynens !

@alexanderdean

@fblundun - it looks like test/yui_compressor_test.js has incorrect whitespace & indentation - could you change from spaces to tabs and check indentation.

@fblundun

Hi @mathiasbynens , any news on getting this feature merged?

@idangren

:+1: I'd also like this feature to be added, it's sorely missing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
70 Gruntfile.js
@@ -1,27 +1,59 @@
module.exports = function(grunt) {
+ // Load required npm grunt tasks
+ grunt.loadNpmTasks('grunt-contrib-jshint');
+ grunt.loadNpmTasks('grunt-contrib-watch');
+ grunt.loadNpmTasks('grunt-contrib-clean');
+ grunt.loadNpmTasks('grunt-contrib-nodeunit');
+
+ // Project configuration.
grunt.initConfig({
'min': {
- 'dist': {
+ 'simple': {
+ 'options': {
+ 'report': 'gzip'
+ },
+ 'files': [{
+ 'src': 'test/fixtures/simple.js',
+ 'dest': 'tmp/simple.min.js'
+ }]
+ },
+ 'w_breaks': {
'options': {
+ 'linebreak': 10,
'report': 'gzip'
},
'files': [{
- 'src': 'examples/example.js',
- 'dest': 'examples/example.min.js'
+ 'src': 'test/fixtures/simple.js',
+ 'dest': 'tmp/w_breaks.min.js'
}]
}
},
'cssmin': {
- 'dist': {
+ 'simple': {
'options': {
- 'report': false
+ 'report': 'gzip'
+
},
'files': [{
- 'src': 'examples/example.css',
- 'dest': 'examples/example.min.css'
+ 'src': 'test/fixtures/simple.css',
+ 'dest': 'tmp/simple.min.css'
}]
- }
+ },
+ 'w_breaks': {
+ 'options': {
+ 'linebreak': 10,
+ 'report': 'gzip'
+ },
+ 'files': [{
+ 'src': 'test/fixtures/simple.css',
+ 'dest': 'tmp/w_breaks.min.css'
+ }]
+ }
+ },
+ // Before generating any new files, remove any previously-created files.
+ 'clean': {
+ 'tests': ['tmp']
},
'lint': {
'files': ['gruntFile.js', 'tasks/*.js', 'tasks/lib/*.js']
@@ -45,17 +77,23 @@ module.exports = function(grunt) {
'trailing': true,
'smarttabs': true
}
- }
- });
+ },
- grunt.loadNpmTasks('grunt-contrib-jshint');
- grunt.loadNpmTasks('grunt-contrib-watch');
+ // Unit tests.
+ 'nodeunit': {
+ tests: ['test/*_test.js']
+ }
+ });
+
+ // Actually load this plugin's task(s).
grunt.loadTasks('tasks');
- grunt.registerTask('default', [
- 'min',
- 'cssmin'
- ]);
+ // Whenever the "test" task is run, first clean the "tmp" dir, then run this
+ // plugin's task(s), then test the result.
+ grunt.registerTask('test', ['clean', 'min', 'cssmin', 'nodeunit']);
+
+ // By default, lint and run all tests.
+ grunt.registerTask('default', ['jshint', 'test']);
};
View
5 tasks/lib/yui-compressor.js
@@ -18,6 +18,10 @@ exports.init = function(grunt) {
var max = concat(source);
var min;
var report = options.report;
+ var opts = [];
+ if (options.linebreak) {
+ opts.push('--line-break', options.linebreak);
+ }
// Ugly hack to create the destination path automatically if needed
if (!grunt.file.exists(destination)) {
@@ -29,6 +33,7 @@ exports.init = function(grunt) {
'type': 'yui-' + options.type,
'fileIn': source,
'fileOut': destination,
+ 'options': opts,
'callback': function(error) {
if (error) {
grunt.warn(error);
View
6 tasks/yui-compressor.js
@@ -20,7 +20,8 @@ module.exports = function(grunt) {
done();
}
},
- 'report': options.report
+ 'report': options.report,
+ 'linebreak': options.linebreak
});
});
});
@@ -43,7 +44,8 @@ module.exports = function(grunt) {
done();
}
},
- 'report': options.report
+ 'report': options.report,
+ 'linebreak': options.linebreak
});
});
});
View
1  test/expected/simple.min.css
@@ -0,0 +1 @@
+html{background:hotpink}@media(max-width:40em){html{border:1px solid lime}}
View
4 test/expected/simple.min.js
@@ -0,0 +1,4 @@
+/*! License comment */
+(function(){
+/*! Weird inline license comment */
+;var foo=42,a="lol\x0bwat"}());
View
3  test/expected/w_breaks.min.css
@@ -0,0 +1,3 @@
+html{background:hotpink}
+@media(max-width:40em){html{border:1px solid lime}
+}
View
6 test/expected/w_breaks.min.js
@@ -0,0 +1,6 @@
+/*! License comment */
+(function(){
+/*! Weird inline license comment */
+;
+var foo=42,a="lol\x0bwat"
+}());
View
9 test/fixtures/simple.css
@@ -0,0 +1,9 @@
+html {
+ background: hotpink;
+}
+
+@media (max-width: 40em) {
+ html {
+ border: 1px solid lime;
+ }
+}
View
7 test/fixtures/simple.js
@@ -0,0 +1,7 @@
+/*! License comment */
+(function() {
+ "foo:nomunge";
+ /*! Weird inline license comment */
+ var foo = 42,
+ bar = 'lol\x0bwat';
+}());
View
49 test/yui_compressor_test.js
@@ -0,0 +1,49 @@
+'use strict';
+
+var grunt = require('grunt');
+
+exports.yui_compressor = {
+ setUp: function (done) {
+ // setup here if necessary
+ done();
+ },
+
+ min_simple: function (test) {
+ test.expect(1);
+
+ var actual = grunt.file.read('tmp/simple.min.js');
+ var expected = grunt.file.read('test/expected/simple.min.js');
+ test.equal(actual, expected, 'should minify a JavaScript file correctly.');
+
+ test.done();
+ },
+
+ min_w_breaks: function (test) {
+ test.expect(1);
+
+ var actual = grunt.file.read('tmp/w_breaks.min.js');
+ var expected = grunt.file.read('test/expected/w_breaks.min.js');
+ test.equal(actual, expected, 'should minify a JavaScript file using the line break option correctly.');
+
+ test.done();
+ },
+ cssmin_simple: function (test) {
+ test.expect(1);
+
+ var actual = grunt.file.read('tmp/simple.min.css');
+ var expected = grunt.file.read('test/expected/simple.min.css');
+ test.equal(actual, expected, 'should minify a CSS file correctly.');
+
+ test.done();
+ },
+
+ cssmin_w_breaks: function (test) {
+ test.expect(1);
+
+ var actual = grunt.file.read('tmp/w_breaks.min.css');
+ var expected = grunt.file.read('test/expected/w_breaks.min.css');
+ test.equal(actual, expected, 'should minify a CSS file using the line break option correctly.');
+
+ test.done();
+ }
+};
Something went wrong with that request. Please try again.