-
globals are not evil. globals are what we have, in JavaScript, and they are not going away. Using good judgement, just avoid them when necessary, but use them where they make sense.
-
where.js is a testing library, not a production application library. The danger of colliding with another global named "where" is vanishingly small, especially in tests.
-
Jasmine, Mocha, QUnit ("... and the rest") all work this way in the browser. In order run jasmine on node.js, jasmine-node does the same thing, making jasmine a global. qunitjs works the same way on node.js. The library by J.P. Castro that in part inspired me to work out where.js also declares a global,
using
. -
I can
require()
my code under test into a test file on Node.js, but must I really require the test file be that kind of module rather than a script?
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
I was looking at how to override the default framework I kept getting now matter how I | |
defined the launchers in testem.json. | |
testem.json is used by the testem command | |
But if we use an npm run script (as defined in "scripts" in package.json) to call testem | |
with various args (like custom test_page) we get the test_page's framework via its script | |
tags. | |
testem generates its own test pages unless you specify your own - to do that, it's best |
[as of 01 MAR 2014]
Here's a copy+paste fix for broken setUp
and tearDown
methods in the examples version of nodeunit:
- replace the following functions in
examples/nodeunit.js
with the corresponding versions from thelib/core.js
file:exports.runModule()
wrapGroup()
exports.runModule()
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
var RE_SEP = /\-|\./; | |
var RE_SEP_AZ = /(\-|\.)[a-z]/; | |
var RE_SEP_AZ_G = /(\-|\.)[a-z]/g; | |
var RE_WS = /[\s]+/g; | |
var BLANK = ''; | |
function camelize(path) { | |
var id = path.split('/').slice(-1)[0]; | |
var m, c, i; | |
if (m = id.match(RE_SEP_AZ_G)) { |
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
// context, scopeName, scopeFunction | |
// context, 'exports', fn | |
function exec(context, fn) { | |
var code = '"use strict";\n'; // need paranoid sandbox for non-strict runtimes | |
for (var k in context) { | |
if (context.hasOwnProperty(k)) { | |
code = code + 'var ' + k + ' = context[\'' + k + '\'];\n'; | |
} |
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
// MOD MAR 6, 2015 | |
function event() { | |
var e = this instanceof event ? this : new event(); | |
e.events = {}; | |
return e; | |
} | |
event.prototype.on = function on(type, listener) { | |
var events = this.events, e = events[type]; |
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
// shell style commonjs for node.js | |
var a = require('a'); | |
module.exports = example; | |
function example() { | |
var r = a.apply(this, arguments); | |
return r; | |
} | |
// AMD for browser - arguments may be incorrect here... | |
define(function(module, require, exports){ |
Just started playing with this (22 MAR 2014) ~ there appear to be two ways to preserve
/*** multiline string comments ***/
when using uglify.
see https://github.com/mishoo/UglifyJS2#keeping-comments-in-the-output
I installed serve which has the following dependencies
"dependencies": {
"connect": "2.3.x"
, "stylus": "*"
, "jade": "*"
, "less-middleware": "*"
, "commander": "0.6.1"
}
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
var registry = {}; | |
function define(id) { | |
function define(param) { | |
var self = define.namespace, type = typeof param; | |
// handle invalid type? then... | |
type == 'function' && exec(param, self); | |
return type == 'string' && string(param, define); | |
} |
OlderNewer