From e3cfce22fcdc217a38a53d561cda7f7cf2f04578 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 30 May 2014 06:36:26 -0600 Subject: [PATCH 1/3] Add util tests --- package.json | 3 +- test/helper.js | 12 ++++++ test/lib/util.spec.js | 97 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 test/helper.js create mode 100644 test/lib/util.spec.js diff --git a/package.json b/package.json index bf0d5a18..028b5bcc 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "devDependencies": { "glob": "~3.2.9", "mocha": "~1.18.2", - "jshint": "~2.4.4" + "jshint": "~2.4.4", + "chai": "~1.9.1" } } diff --git a/test/helper.js b/test/helper.js new file mode 100644 index 00000000..de6adf3d --- /dev/null +++ b/test/helper.js @@ -0,0 +1,12 @@ +var chai = require('chai'); + + +/** @type {boolean} */ +chai.config.includeStack = true; + + +/** + * Chai's assert function configured to include stacks on failure. + * @type {function} + */ +exports.assert = chai.assert; diff --git a/test/lib/util.spec.js b/test/lib/util.spec.js new file mode 100644 index 00000000..2ec1b8d7 --- /dev/null +++ b/test/lib/util.spec.js @@ -0,0 +1,97 @@ +var path = require('path'); + +var assert = require('../helper').assert; + +var util = require('../../lib/util'); + +describe('util', function() { + + var files; + beforeEach(function() { + files = [ + path.join('a1', 'b1', 'c2', 'd2.txt'), + path.join('a1', 'b2', 'c2', 'd1.txt'), + path.join('a2.txt'), + path.join('a1', 'b1', 'c1', 'd1.txt'), + path.join('a1', 'b1', 'c2', 'd1.txt'), + path.join('a1', 'b1.txt'), + path.join('a2', 'b1', 'c2.txt'), + path.join('a1', 'b1', 'c2', 'd3.txt'), + path.join('a1', 'b2', 'c1', 'd1.txt'), + path.join('a1.txt'), + path.join('a2', 'b1', 'c1.txt'), + path.join('a2', 'b1.txt') + ].slice(); + }); + + describe('byShortPath', function() { + it('sorts an array of filepaths, shortest first', function() { + files.sort(util.byShortPath); + + var expected = [ + path.join('a1.txt'), + path.join('a2.txt'), + path.join('a1', 'b1.txt'), + path.join('a2', 'b1.txt'), + path.join('a2', 'b1', 'c1.txt'), + path.join('a2', 'b1', 'c2.txt'), + path.join('a1', 'b1', 'c1', 'd1.txt'), + path.join('a1', 'b1', 'c2', 'd1.txt'), + path.join('a1', 'b1', 'c2', 'd2.txt'), + path.join('a1', 'b1', 'c2', 'd3.txt'), + path.join('a1', 'b2', 'c1', 'd1.txt'), + path.join('a1', 'b2', 'c2', 'd1.txt') + ]; + + assert.deepEqual(files, expected); + }); + }); + + describe('uniqueDirs', function() { + + it('gets a list of unique directory paths', function() { + // not comparing order here, so we sort both + var got = util.uniqueDirs(files).sort(); + + var expected = [ + '.', + 'a1', + 'a2', + path.join('a1', 'b1'), + path.join('a1', 'b1', 'c1'), + path.join('a1', 'b1', 'c2'), + path.join('a1', 'b2'), + path.join('a1', 'b2', 'c1'), + path.join('a1', 'b2', 'c2'), + path.join('a2', 'b1') + ].sort(); + + assert.deepEqual(got, expected); + }); + + }); + + describe('dirsToCreate', function() { + + it('gets a sorted list of directories to create', function() { + var got = util.dirsToCreate(files); + + var expected = [ + '.', + 'a1', + 'a2', + path.join('a1', 'b1'), + path.join('a1', 'b2'), + path.join('a2', 'b1'), + path.join('a1', 'b1', 'c1'), + path.join('a1', 'b1', 'c2'), + path.join('a1', 'b2', 'c1'), + path.join('a1', 'b2', 'c2') + ]; + + assert.deepEqual(got, expected); + }); + + }); + +}); From 37a4a2c8c7e90d5151da461dbeaac0866f54c996 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 30 May 2014 06:42:10 -0600 Subject: [PATCH 2/3] Enlist travis --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..df63076b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - "0.10" + - "0.8" From 42458210c52941b04b92b9c14cd7dc8881f5d3be Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 30 May 2014 06:45:50 -0600 Subject: [PATCH 3/3] Build status --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 21334ad4..00b148ff 100644 --- a/readme.md +++ b/readme.md @@ -3,3 +3,5 @@ Publish files to a `gh-pages` branch on GitHub (or any other branch anywhere else). This will evolve into a more useful package. For now, it's just some extracted bits from the [`grunt-gh-pages`](https://www.npmjs.org/package/grunt-gh-pages) package. + +[![Current Status](https://secure.travis-ci.org/tschaub/gh-pages.png?branch=master)](https://travis-ci.org/tschaub/gh-pages)