diff --git a/build/mkdirp-sync.js b/build/mkdirp-sync.js index 9bf1ee289..ae621743b 100755 --- a/build/mkdirp-sync.js +++ b/build/mkdirp-sync.js @@ -19,19 +19,22 @@ * @param {Number|String} mode The permission mode. */ function mkdirpSync(dirname, mode) { - var separator = path.sep, - segments = dirname.split(separator), + var sep = path.sep, type = typeof mode; + // ensure relative paths are prefixed with `./` + if (!RegExp('^\\.?' + sep).test(dirname)) { + dirname = '.' + sep + dirname; + } if (!(type == 'number' || type == 'string')) { mode = '0777'; } - segments.reduce(function(currPath, segment, index) { + dirname.split(sep).reduce(function(currPath, segment, index) { // skip leading separator of absolute paths if (index === 0 && currPath === '') { - return separator; + return sep; } - segment = currPath + (currPath === separator ? segment : separator + segment); + segment = currPath + (currPath === sep ? segment : sep + segment); try { segment = fs.realpathSync(segment); } catch(e) { diff --git a/test/test-build.js b/test/test-build.js index d39c80e6c..851e7bb8e 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -2,16 +2,27 @@ ;(function(undefined) { 'use strict'; + /** Load Node.js modules */ + var fs = require('fs'), + path = require('path'), + vm = require('vm'); + + /** Load other modules */ + var build = require('../build.js'), + minify = require('../build/minify'), + _ = require('../lodash.js'); + /** Used to avoid `noglobal` false positives caused by `errno` leaked in Node.js */ global.errno = true; - /** Load modules */ - var fs = require('fs'), - path = require('path'), - vm = require('vm'), - build = require('../build.js'), - minify = require('../build/minify'), - _ = require('../lodash.js'); + /** Add `path.sep` for older versions of Node.js */ + path.sep || (path.sep = process.platform == 'win32' ? '\\' : '/'); + + /** The current working directory */ + var cwd = process.cwd(); + + /** Used to prefix relative paths from the current directory */ + var relativePrefix = '.' + path.sep; /** The unit testing framework */ var QUnit = ( @@ -503,33 +514,46 @@ QUnit.module('template builds'); (function() { - var templatePath = __dirname + '/template'; + var templatePath = path.join(__dirname, 'template'); - asyncTest('`lodash template=*.jst`', function() { - var start = _.after(2, _.once(QUnit.start)); + var commands = [ + 'template=' + path.join('template', '*.jst'), + 'template=' + relativePrefix + path.join('template', '*.jst'), + 'template=' + path.join(templatePath, '*.jst') + ]; - build(['-s', 'template=' + templatePath + '/*.jst'], function(data) { - var basename = path.basename(data.outputPath, '.js'), - context = createContext(); + commands.forEach(function(command) { + asyncTest('`lodash ' + command +'`', function() { + var start = _.after(2, _.once(function() { + process.chdir(cwd); + QUnit.start(); + })); - var object = { - 'a': { 'people': ['moe', 'larry', 'curly'] }, - 'b': { 'epithet': 'stooge' }, - 'c': { 'name': 'ES6' } - }; + process.chdir(__dirname); - context._ = _; - vm.runInContext(data.source, context); + build(['-s', command], function(data) { + var basename = path.basename(data.outputPath, '.js'), + context = createContext(); - equal(_.templates.a(object.a).replace(/[\r\n]+/g, ''), '