Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 57 additions and 48 deletions.
  1. +1 −4 .gitignore
  2. +35 −24 grunt.js
  3. +21 −20 test/less_test.js
View
5 .gitignore
@@ -1,4 +1 @@
-.DS_Store
-node_modules
-npm-debug.log
-tmp
+/node_modules/
View
59 grunt.js
@@ -1,12 +1,11 @@
module.exports = function(grunt) {
- "use strict";
+ 'use strict';
+ // Project configuration.
grunt.initConfig({
-
lint: {
- all: ["grunt.js", "tasks/*.js"]
+ all: ['grunt.js', 'tasks/*.js', '<config:nodeunit.tasks>']
},
-
jshint: {
options: {
curly: true,
@@ -20,37 +19,49 @@ module.exports = function(grunt) {
boss: true,
eqnull: true,
node: true,
- es5: true
- }
+ es5: true,
+ },
+ },
+ nodeunit: {
+ tasks: ['test/*_test.js']
},
+ // Configuration to be run (and then tested).
less: {
compile: {
files: {
- "tmp/less_a.css": ["test/fixtures/style.less"],
- "tmp/less_b.css": ["test/fixtures/style.less"],
- "tmp/less_c.css": ["test/fixtures/**/*.nomatches"],
- "tmp/less_d.css": ["test/fixtures/style.less", "test/fixtures/style2.less"]
+ '<%= TMP %>/less_a.css': ['test/fixtures/style.less'],
+ '<%= TMP %>/less_b.css': ['test/fixtures/style.less'],
+ '<%= TMP %>/less_c.css': ['test/fixtures/**/*.nomatches'],
+ '<%= TMP %>/less_d.css': ['test/fixtures/style.less', 'test/fixtures/style2.less']
},
options: {
- paths: ["test/fixtures/include"]
- }
+ paths: ['test/fixtures/include']
+ },
}
},
-
- nodeunit: {
- tasks: ["test/*_test.js"]
- }
-
});
- grunt.registerTask("testprep", "prepare for tests", function() {
- require("rimraf").sync("tmp");
- grunt.file.mkdir("tmp");
+ // This needs to be run before our task + tests are run.
+ grunt.registerTask('test_setup', 'Test setup.', function() {
+ // Create a temporary directory.
+ var Tempdir = require('temporary/lib/dir');
+ var tmpdir = new Tempdir();
+ // Update config so our task can utilize the tempdir.
+ grunt.config.set('TMP', tmpdir.path);
+ // Unit tests need to know where the tempdir is.
+ global.TMP = tmpdir.path;
});
- grunt.registerTask("default", "lint");
- grunt.renameTask("test", "nodeunit");
- grunt.registerTask("test", "testprep less nodeunit");
- grunt.loadTasks("tasks");
+ // Whenever "test" is run, perform test setup, run task in as many ways
+ // as necessary, then test the result.
+ grunt.renameTask('test', 'nodeunit');
+ grunt.registerTask('test', 'test_setup less nodeunit');
+
+ // By default, lint and run all tests.
+ grunt.registerTask('default', 'lint test');
+
+ // Actually load tasks to be tested.
+ grunt.loadTasks('tasks');
+
};
View
41 test/less_test.js
@@ -1,31 +1,32 @@
-var grunt = require("grunt");
+var grunt = require('grunt');
+var path = require('path');
-exports.less = {
- main: function(test) {
+// The temporary directory, as-created in the test_setup task.
+var TMP = global.TMP;
- "use strict";
-
- var expect;
- var result;
- var tmpdir = "???";
+exports['less'] = {
+ 'main': function(test) {
+ 'use strict';
test.expect(4);
- expect = "body {\n color: #ffffff;\n}\n";
- result = grunt.file.read("tmp/less_a.css");
- test.equal(expect, result, "should compile less, with the ability to handle imported files from alternate include paths");
+ var actual, expected;
+
+ actual = grunt.file.read(path.join(TMP, 'less_a.css'));
+ expected = 'body {\n color: #ffffff;\n}\n';
+ test.equal(actual, expected, 'should compile less, with the ability to handle imported files from alternate include paths');
- expect = "body {\n color: #ffffff;\n}\n";
- result = grunt.file.read("tmp/less_b.css");
- test.equal(expect, result, "should support multiple destination:source sets");
+ actual = grunt.file.read(path.join(TMP, 'less_b.css'));
+ expected = 'body {\n color: #ffffff;\n}\n';
+ test.equal(actual, expected, 'should support multiple destination:source sets');
- expect = "";
- result = grunt.file.read("tmp/less_c.css");
- test.equal(expect, result, "should write an empty file when no less sources are found");
+ actual = grunt.file.read(path.join(TMP, 'less_c.css'));
+ expected = '';
+ test.equal(actual, expected, 'should write an empty file when no less sources are found');
- expect = "body {\n color: #ffffff;\n}\n\n#header {\n background: #ffffff;\n}\n";
- result = grunt.file.read("tmp/less_d.css");
- test.equal(expect, result, "should concat output when passed an array");
+ actual = grunt.file.read(path.join(TMP, 'less_d.css'));
+ expected = 'body {\n color: #ffffff;\n}\n\n#header {\n background: #ffffff;\n}\n';
+ test.equal(actual, expected, 'should concat output when passed an array');
test.done();
}

No commit comments for this range

Something went wrong with that request. Please try again.