Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f86a51
commit a2a76c5
Showing
4 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
!function (name, definition) { | ||
if (typeof define == 'function' && typeof define.amd == 'object') define(definition); | ||
else this[name] = definition(); | ||
}('chai_timers', function () { | ||
// CommonJS require() | ||
function require(p){ | ||
var path = require.resolve(p) | ||
, mod = require.modules[path]; | ||
if (!mod) throw new Error('failed to require "' + p + '"'); | ||
if (!mod.exports) { | ||
mod.exports = {}; | ||
mod.call(mod.exports, mod, mod.exports, require.relative(path)); | ||
} | ||
return mod.exports; | ||
} | ||
|
||
require.modules = {}; | ||
|
||
require.resolve = function (path){ | ||
var orig = path | ||
, reg = path + '.js' | ||
, index = path + '/index.js'; | ||
return require.modules[reg] && reg | ||
|| require.modules[index] && index | ||
|| orig; | ||
}; | ||
|
||
require.register = function (path, fn){ | ||
require.modules[path] = fn; | ||
}; | ||
|
||
require.relative = function (parent) { | ||
return function(p){ | ||
if ('.' != p[0]) return require(p); | ||
|
||
var path = parent.split('/') | ||
, segs = p.split('/'); | ||
path.pop(); | ||
|
||
for (var i = 0; i < segs.length; i++) { | ||
var seg = segs[i]; | ||
if ('..' == seg) path.pop(); | ||
else if ('.' != seg) path.push(seg); | ||
} | ||
|
||
return require(path.join('/')); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
return require('timers'); | ||
}); | ||
|
||
chai.use(chai_timers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/*! | ||
* chai-spies :: browser build script | ||
* Copyright (c) 2012 Jake Luer <jake@alogicalparadox.com> | ||
* MIT Licensed | ||
*/ | ||
|
||
/*! | ||
* Script dependancies | ||
*/ | ||
|
||
var fs = require('fs') | ||
, path = require('path') | ||
, join = path.join | ||
, folio = require('folio'); | ||
|
||
/*! | ||
* Script variables | ||
*/ | ||
|
||
var appfiles = [] | ||
, basepath = join(__dirname, '..', 'lib'); | ||
|
||
/** | ||
* Recursively iterate through a given path | ||
* and add all `.js` files to an array. | ||
* | ||
* @param {String} absolute path | ||
*/ | ||
|
||
function iteratePath (p) { | ||
var self = this | ||
, files = fs.readdirSync(p); | ||
files.forEach(function (filename) { | ||
var file = path.join(p, filename) | ||
, stat = fs.statSync(file); | ||
if (stat.isDirectory()) { | ||
iteratePath(file); | ||
} else if (stat.isFile()) { | ||
if (path.extname(file) == '.js') | ||
appfiles.push(file); | ||
} | ||
}); | ||
}; | ||
|
||
// Go! | ||
iteratePath(basepath); | ||
|
||
/** | ||
* Package together all found files into a | ||
* folio.Glossary, defining a custom "compiler" | ||
* that will wrap our script with the needed commonjs | ||
* | ||
* @param {Array} files | ||
* @param {Object} folio glossary configuration | ||
*/ | ||
|
||
var applicationJs = new folio.Glossary(appfiles, { | ||
compilers: { | ||
js: function (name, source, filename) { | ||
var title = filename.replace(basepath + '/', '').replace('.js', '') | ||
, buf = '\nrequire.register("' + title + '", function (module, exports, require) {\n'; | ||
buf += source; | ||
buf += '\n}); // module ' + name; | ||
return buf; | ||
} | ||
} | ||
}); | ||
|
||
/*! | ||
* Load up our prefix/suffix | ||
*/ | ||
|
||
var prefix = fs.readFileSync(join(__dirname, 'browser', 'prefix.js'), 'utf8') | ||
, suffix = fs.readFileSync(join(__dirname, 'browser', 'suffix.js'), 'utf8') | ||
|
||
/** | ||
* Compile the folio.Glossary, applying our wrapper, | ||
* and output the src. Wrap with prefix/suffix and | ||
* write to file. | ||
*/ | ||
|
||
applicationJs.compile(function (err, src) { | ||
var content = prefix + src + suffix; | ||
fs.writeFileSync(join(__dirname, '..', 'chai-timers.js'), content, 'utf8'); | ||
console.log('completed: chai-timers.js'); | ||
}); |