Skip to content

Instantly share code, notes, and snippets.

@dfkaye
dfkaye / gist:8773266
Last active August 29, 2015 13:55
Configure and run multiple framework launchers for testem
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
@dfkaye
dfkaye / global-where.md
Last active August 29, 2015 13:56
answering the global issue in where.js

why where.js is global

  • 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?

@dfkaye
dfkaye / nodeunit-browser-fix.md
Last active August 29, 2015 13:56
copy+paste fix for broken `setUp` and `tearDown` methods in the examples version of nodeunit

a fix for nodeunit.js ~ browser version

[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 the lib/core.js file:
    • exports.runModule()
    • wrapGroup()
  • exports.runModule()
@dfkaye
dfkaye / path-to-symbol.js
Last active August 29, 2015 13:57
camelCase path-names to symbols: example-name => exampleName; path.ext => path
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)) {
@dfkaye
dfkaye / function-exec.js
Last active August 29, 2015 13:57
sketch of executable function context method ~ populates context props as vars into new scope ~ follows commonjs mod exports falafel
// 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';
}
@dfkaye
dfkaye / tiny-e.js
Last active August 29, 2015 13:57
tiny event on/off p.o.c. ~ for the scrapbook
// 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];
@dfkaye
dfkaye / common-inject.js
Last active August 29, 2015 13:57
3/20/2014 ~ api for common-inject.js
// 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){
@dfkaye
dfkaye / uglify-multiline-string.md
Last active August 29, 2015 13:57
preserving /*** multiline string comments ***/ in uglify
@dfkaye
dfkaye / dependency-bloat.md
Last active August 29, 2015 13:57
dependency bloat example

I installed serve which has the following dependencies

"dependencies": {
    "connect": "2.3.x"
  , "stylus": "*"
  , "jade": "*"
  , "less-middleware": "*"
  , "commander": "0.6.1"
}
@dfkaye
dfkaye / gist:11094033
Last active August 29, 2015 14:00
monadic namespace loader sketch...
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);
}