From a315a97e04307c3aea9f4a61ba4030c4d05566b5 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 6 Sep 2013 22:16:27 -0600 Subject: [PATCH 1/6] Unused fixtures --- fixtures/one.js | 1 - fixtures/two.js | 1 - 2 files changed, 2 deletions(-) delete mode 100644 fixtures/one.js delete mode 100644 fixtures/two.js diff --git a/fixtures/one.js b/fixtures/one.js deleted file mode 100644 index 6c04396..0000000 --- a/fixtures/one.js +++ /dev/null @@ -1 +0,0 @@ -var one = 'one'; diff --git a/fixtures/two.js b/fixtures/two.js deleted file mode 100644 index 79a78e7..0000000 --- a/fixtures/two.js +++ /dev/null @@ -1 +0,0 @@ -var two = 'two'; From 6428f8c9c55e10080bf494d670c2b3ed632153e6 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 6 Sep 2013 22:16:47 -0600 Subject: [PATCH 2/6] Unused task --- test/fixtures/newer-modify-one/gruntfile.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/fixtures/newer-modify-one/gruntfile.js b/test/fixtures/newer-modify-one/gruntfile.js index 745313d..169fe5b 100644 --- a/test/fixtures/newer-modify-one/gruntfile.js +++ b/test/fixtures/newer-modify-one/gruntfile.js @@ -45,10 +45,6 @@ module.exports = function(grunt) { grunt.loadTasks('../../../tasks'); grunt.loadTasks('../../../test/tasks'); - grunt.registerTask('fail', function() { - throw new Error('see above'); - }); - grunt.registerTask('default', function() { grunt.task.run([ From 27fecd15b50ba6bee6cde92466322e218d2573ee Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 6 Sep 2013 23:12:42 -0600 Subject: [PATCH 3/6] Lint fixtures --- gruntfile.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gruntfile.js b/gruntfile.js index 3082984..41cecc0 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -11,6 +11,8 @@ module.exports = function(grunt) { var gruntfileSrc = 'gruntfile.js'; var tasksSrc = 'tasks/**/*.js'; var testSrc = 'test/**/*.spec.js'; + var fixturesJs = 'test/fixtures/**/*.js'; + var fixturesAll = 'test/fixtures/**/*'; grunt.initConfig({ @@ -33,11 +35,14 @@ module.exports = function(grunt) { tasks: { src: tasksSrc }, - fixtures: { + tests: { options: { jshintrc: 'test/.jshintrc' }, src: testSrc + }, + fixturesJs: { + src: fixturesJs } }, @@ -50,12 +55,12 @@ module.exports = function(grunt) { files: testSrc, tasks: ['newer:cafemocha'] }, - fixtures: { - files: 'test/fixtures/**/*', + fixturesAll: { + files: fixturesAll, tasks: ['cafemocha'] }, - all: { - files: [gruntfileSrc, tasksSrc, testSrc], + allJs: { + files: [gruntfileSrc, tasksSrc, testSrc, fixturesJs], tasks: ['newer:jshint'] } } From cc93cfde38134a6f8316605e58ad5495b4ad4f92 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 6 Sep 2013 23:13:20 -0600 Subject: [PATCH 4/6] Filter before logging --- test/tasks/index.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/test/tasks/index.js b/test/tasks/index.js index 1e67164..e0e8bf3 100644 --- a/test/tasks/index.js +++ b/test/tasks/index.js @@ -15,30 +15,42 @@ function prune(obj) { } +/** + * Remove files config objects with no src files. + * @param {Array} files Array of files config objects. + * @return {Array} Filtered array of files config objects. + */ +function filter(files) { + return files.map(prune).filter(function(obj) { + return obj.src && obj.src.length > 0; + }); +} + + /** @param {Object} grunt Grunt. */ module.exports = function(grunt) { grunt.registerMultiTask('assert', function(name, target) { var config = grunt.config([name, target]); - var expected = grunt.task.normalizeMultiTaskFiles(config, target) - .map(prune); + var expected = filter(grunt.task.normalizeMultiTaskFiles(config, target)); var log = this.data.getLog(); - if (expected.length === 0 || expected[0].src.length === 0) { + if (expected.length === 0) { assert.equal(log.length, 0, 'No log entries'); } else { assert.equal(log.length, 1, 'One log entry'); - var actual = log[0].map(prune); + var actual = log[0]; assert.deepEqual(actual, expected); log.length = 0; } - }); grunt.registerMultiTask('log', function() { - var log = this.data.getLog(); - log.push(this.files.map(prune)); + var files = filter(this.files); + if (files.length > 0) { + this.data.getLog().push(files); + } }); From 80c9ee653110c6de4746c6d8f96b211427342e79 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 6 Sep 2013 23:13:41 -0600 Subject: [PATCH 5/6] Fixture with dest files --- test/fixtures/newer-dest/gruntfile.js | 94 +++++++++++++++++++++++++ test/fixtures/newer-dest/src/one.coffee | 3 + test/fixtures/newer-dest/src/two.coffee | 3 + test/newer-dest.spec.js | 23 ++++++ 4 files changed, 123 insertions(+) create mode 100644 test/fixtures/newer-dest/gruntfile.js create mode 100644 test/fixtures/newer-dest/src/one.coffee create mode 100644 test/fixtures/newer-dest/src/two.coffee create mode 100644 test/newer-dest.spec.js diff --git a/test/fixtures/newer-dest/gruntfile.js b/test/fixtures/newer-dest/gruntfile.js new file mode 100644 index 0000000..0953b7b --- /dev/null +++ b/test/fixtures/newer-dest/gruntfile.js @@ -0,0 +1,94 @@ +var path = require('path'); + + +/** + * @param {Object} grunt Grunt. + */ +module.exports = function(grunt) { + + var log = []; + + grunt.initConfig({ + newer: { + options: { + timestamps: path.join(__dirname, '.cache') + } + }, + modified: { + one: { + files: [{ + expand: true, + cwd: 'src/', + src: 'one.coffee', + dest: 'dest/', + ext: '.js' + }] + }, + all: { + files: [{ + expand: true, + cwd: 'src/', + src: '**/*.coffee', + dest: 'dest/', + ext: '.js' + }] + }, + none: { + src: [] + } + }, + log: { + all: { + files: [{ + expand: true, + cwd: 'src/', + src: '**/*.coffee', + dest: 'dest/', + ext: '.js' + }], + getLog: function() { + return log; + } + } + }, + assert: { + that: { + getLog: function() { + return log; + } + } + } + }); + + grunt.loadTasks('../../../tasks'); + grunt.loadTasks('../../../test/tasks'); + + grunt.registerTask('default', function() { + + grunt.task.run([ + // run the log task with newer, expect all files + 'newer:log', + 'assert:that:modified:all', + + // HFS+ filesystem mtime resolution + 'wait:1001', + + // modify one file + 'modified:one', + + // run assert task again, expect one file + 'newer:log', + 'assert:that:modified:one', + + // HFS+ filesystem mtime resolution + 'wait:1001', + + // modify nothing, expect no files + 'newer:log', + 'assert:that:modified:none' + + ]); + + }); + +}; diff --git a/test/fixtures/newer-dest/src/one.coffee b/test/fixtures/newer-dest/src/one.coffee new file mode 100644 index 0000000..aa0ae5a --- /dev/null +++ b/test/fixtures/newer-dest/src/one.coffee @@ -0,0 +1,3 @@ +coffee = + is: 'good' + hot: true diff --git a/test/fixtures/newer-dest/src/two.coffee b/test/fixtures/newer-dest/src/two.coffee new file mode 100644 index 0000000..2f77f36 --- /dev/null +++ b/test/fixtures/newer-dest/src/two.coffee @@ -0,0 +1,3 @@ +semicolons = true +coffee = true +semicolons = false if coffee diff --git a/test/newer-dest.spec.js b/test/newer-dest.spec.js new file mode 100644 index 0000000..6452853 --- /dev/null +++ b/test/newer-dest.spec.js @@ -0,0 +1,23 @@ +var path = require('path'); + +var helper = require('./helper'); + +var name = 'newer-dest'; +var gruntfile = path.join(name, 'gruntfile.js'); + +describe(name, function() { + var fixture; + + it('runs the default task (see ' + gruntfile + ')', function(done) { + this.timeout(3000); + helper.buildFixture(name, function(error, dir) { + fixture = dir; + done(error); + }); + }); + + after(function(done) { + helper.afterFixture(fixture, done); + }); + +}); From 6a104e6548d75d36b64d78789666c5530be5e875 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sat, 7 Sep 2013 08:30:16 -0600 Subject: [PATCH 6/6] Use mtime of dest file if it is more recent --- tasks/newer.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tasks/newer.js b/tasks/newer.js index de0bf7d..770aa6f 100644 --- a/tasks/newer.js +++ b/tasks/newer.js @@ -51,8 +51,21 @@ function createTask(grunt, any) { // look for files that have been modified since last run var previous = fs.statSync(stamp).mtime; newerFiles = files.map(function(obj) { + var time; + /** + * It is possible that there is a dest file that has been created + * more recently than the last successful run. This would happen if + * a target with multiple dest files failed before all dest files were + * created. In this case, we don't need to re-run src files that map + * to dest files that were already created. + */ + if (obj.dest && grunt.file.exists(obj.dest)) { + time = Math.max(fs.statSync(obj.dest).mtime, previous); + } else { + time = previous; + } var src = obj.src.filter(function(filepath) { - var newer = fs.statSync(filepath).mtime > previous; + var newer = fs.statSync(filepath).mtime > time; if (newer) { modified = true; }