Skip to content

Commit

Permalink
test fixing, with full install test
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jan 13, 2015
1 parent 61686aa commit f91375b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 198 deletions.
6 changes: 6 additions & 0 deletions api.js
Expand Up @@ -22,6 +22,7 @@ var EventEmitter = require('events').EventEmitter;
var System = require('systemjs');
var config = require('./lib/config');
var path = require('path');
var Promise = require('rsvp').Promise;

require('rsvp').on('error', function(reason) {
ui.log('warn', 'Unhandled promise rejection.\n' + reason && reason.stack || reason || '' + '\n');
Expand Down Expand Up @@ -55,6 +56,11 @@ API.normalize = function(name, parentName) {
* Callback answer defined in https://github.com/SBoudrias/Inquirer.js/tree/master#answers
*/
ui.setResolver(API);
ui.useDefaults();

API.promptDefaults = function(_useDefaults) {
ui.useDefaults(_useDefaults);
}

/*
* Installs a library in the current folder
Expand Down
6 changes: 4 additions & 2 deletions lib/ui.js
Expand Up @@ -32,8 +32,10 @@ exports.setResolver = function(resolver) {
// use the default option in all prompts
// throws an error for prompts that don't take a default
var useDefaults;
exports.useDefaults = function() {
useDefaults = true;
exports.useDefaults = function(_useDefaults) {
if (_useDefaults === undefined)
_useDefaults = true;
useDefaults = _useDefaults;
}


Expand Down
9 changes: 6 additions & 3 deletions test/api.js
Expand Up @@ -11,9 +11,12 @@ suite('API Calls', function() {
});

test('Import', function(done) {
api.import('mocha').then(function(mocha) {
assert(mocha.setup);
done();
api.install(true)
.then(function() {
api.import('mocha').then(function(mocha) {
assert(mocha.setup);
done();
}, done);
}, done);
});
});
Expand Down
1 change: 1 addition & 0 deletions test/mocha.opts
@@ -1,2 +1,3 @@
--require test/setup.js
--ui tdd
--timeout 30000
177 changes: 2 additions & 175 deletions test/setup.js
@@ -1,175 +1,2 @@
var Promise = require('rsvp').Promise;
global.assert = require('assert');

var fs = require('graceful-fs');
var rimraf = require('rimraf');
var path = require('path');

var pkg = require('../lib/package');
var Package = pkg.Package;

global.jspm = require('../api');
global.ui = require('../lib/ui');
var config = require('../lib/config');

var tmpDir = path.resolve('test-tmp');

if (!fs.existsSync(tmpDir))
fs.mkdirSync(tmpDir);

global.project = function(callback) {
project.clearHandlers();
config.loaded = false;
rimraf(tmpDir, function(e) {
fs.mkdirSync(tmpDir);
process.chdir(tmpDir);
callback();
});
}

project.log = function(msg) {
if (project.showLogs)
console.log(msg);
}

project.showLogs = false;

project.clearHandlers = function() {
inputHandlers = [];
criticalInputHandlers = [];

logHandlers = {
err: [],
info: [],
ok: [],
warn: []
}
}

function applyHandler(msg) {
var curHandler = this.shift();

var args = [];
msg = msg.replace(/(\`[^\`]+\`|\%[^\%]+\%)/g, function(match) {
args.push(match.substr(1, match.length - 2));
var c = match.substr(0, 1);
return c + args.length + c;
});

arguments[0] = msg;
arguments[arguments.length] = args;
arguments.length++;

return Promise.resolve(curHandler && curHandler.apply(null, arguments));
}

var currentInput;
var inputQueue = [];
function inputHandler(msg, def) {
if (project.showInputs)
console.log(msg + ' [' + def + ']');

if (currentInput)
return inputQueue.push([msg, def]);
if (!inputHandlers.length && !def && !criticalInputHandlers.length)
throw 'No CLI handler or default for: \n' + msg;

return (currentInput = applyHandler.apply(inputHandlers.length || def ? inputHandlers : criticalInputHandlers, arguments))
.then(function(val) {
currentInput = null;
if (inputQueue.length)
inputHandler.apply(null, inputQueue.shift());
return val || def;
});
}

ui.input = inputHandler;
ui.confirm = inputHandler;

var oldLog = ui.log;
ui.log = function(type, msg) {
if (type == 'err' && !logHandlers.err.length) {
oldLog.apply(this, arguments);
throw new Error(msg);
}

if (logHandlers[type].length)
applyHandler.call(logHandlers[type], msg);

if (project.showLogs)
oldLog.apply(this, arguments);
}

var inputHandlers = [];
project.addInputHandler = function(fn) {
inputHandlers.push(fn);
}

var criticalInputHandlers = [];
project.addCriticalInputHandler = function(fn) {
criticalInputHandlers.push(fn);
}


var logCnt = 0;
var logHandlers = {
err: [],
info: [],
warn: [],
ok: []
};
project.assertLog = function(type, msg, args) {
logCnt++;
logHandlers[type].push(function(_msg, _args) {
if (msg)
assert.equal(msg, _msg);
if (args)
assert.equal(args, _args);
logCnt--;
});
}
project.assertLogsCalled = function() {
assert.equal(logCnt, 0);
}




project.registry = {};
pkg.locate = function(target) {
if (target.endpoint)
return Promise.resolve(target);

if (!project.registry[target.name])
throw 'No mock registry for ' + target.name;

var p = new Package(project.registry[target.name]);
p.setVersion(target.version);

return Promise.resolve(p);
}
pkg.checkOverride = function(fullName, cdn) {
return Promise.resolve();
}

project.versions = {};

pkg.loadEndpoint = function(endpoint) {
return {
getVersions: function(repo, callback, errback) {
if (!project.versions[endpoint + ':' + repo])
throw 'No project.versions["' + endpoint + ':' + repo + '"]';
process.nextTick(function() {
callback(project.versions[endpoint + ':' + repo]);
});
},
download: function(repo, version, hash, outDir, callback, errback) {
process.nextTick(function() {
callback({});
});
}
};
}



global.Promise = require('rsvp').Promise;
global.assert = require('assert');
45 changes: 27 additions & 18 deletions testlibs/config.js
Expand Up @@ -9,10 +9,10 @@ System.config({

System.config({
"map": {
"angular": "github:angular/bower-angular@1.3.5",
"angular": "github:angular/bower-angular@1.3.8",
"bootstrap": "github:twbs/bootstrap@3.3.1",
"css": "github:systemjs/plugin-css@0.1.0",
"d3": "github:mbostock/d3@3.4.13",
"d3": "github:mbostock/d3@3.5.3",
"jquery": "github:components/jquery@2.1.3",
"mocha": "npm:mocha@1.21.5",
"text": "github:systemjs/plugin-text@0.0.2",
Expand Down Expand Up @@ -46,14 +46,15 @@ System.config({
"css": "github:systemjs/plugin-css@0.1.0",
"jquery": "github:components/jquery@2.1.3"
},
"npm:amdefine@0.0.8": {
"npm:amdefine@0.1.0": {
"fs": "github:jspm/nodelibs-fs@0.1.0",
"path": "github:jspm/nodelibs-path@0.1.0",
"process": "github:jspm/nodelibs-process@0.1.0"
},
"npm:ao-mesher@0.2.10": {
"cwise-compiler": "npm:cwise-compiler@0.1.0",
"greedy-mesher": "npm:greedy-mesher@1.0.2",
"ndarray": "npm:ndarray@1.0.15",
"ndarray": "npm:ndarray@1.0.16",
"typedarray-pool": "npm:typedarray-pool@0.1.2"
},
"npm:ao-shader@0.2.3": {
Expand All @@ -71,7 +72,7 @@ System.config({
"path": "github:jspm/nodelibs-path@0.1.0",
"process": "github:jspm/nodelibs-process@0.1.0",
"systemjs-json": "github:systemjs/plugin-json@0.1.0",
"through": "npm:through@1.1.2"
"through": "npm:through@2.2.7"
},
"npm:buffer@3.0.1": {
"base64-js": "npm:base64-js@0.0.8",
Expand Down Expand Up @@ -103,7 +104,7 @@ System.config({
"fs": "github:jspm/nodelibs-fs@0.1.0",
"path": "github:jspm/nodelibs-path@0.1.0",
"process": "github:jspm/nodelibs-process@0.1.0",
"source-map": "npm:source-map@0.1.40"
"source-map": "npm:source-map@0.1.43"
},
"npm:esprima@1.0.4": {
"fs": "github:jspm/nodelibs-fs@0.1.0",
Expand All @@ -126,7 +127,7 @@ System.config({
"vkey": "npm:vkey@0.0.3"
},
"npm:gl-buffer@0.1.2": {
"ndarray": "npm:ndarray@1.0.15",
"ndarray": "npm:ndarray@1.0.16",
"ndarray-ops": "npm:ndarray-ops@1.1.1",
"typedarray-pool": "npm:typedarray-pool@0.1.2"
},
Expand All @@ -141,14 +142,14 @@ System.config({
"npm:gl-texture2d@0.1.12": {
"bit-twiddle": "npm:bit-twiddle@0.0.2",
"cwise-compiler": "npm:cwise-compiler@0.1.0",
"ndarray": "npm:ndarray@1.0.15",
"ndarray": "npm:ndarray@1.0.16",
"ndarray-ops": "npm:ndarray-ops@1.1.1",
"typedarray-pool": "npm:typedarray-pool@1.1.0",
"webglew": "npm:webglew@0.0.0"
},
"npm:gl-tile-map@0.3.0": {
"gl-texture2d": "npm:gl-texture2d@0.1.12",
"ndarray": "npm:ndarray@1.0.15",
"ndarray": "npm:ndarray@1.0.16",
"tile-mip-map": "npm:tile-mip-map@0.2.1",
"webglew": "npm:webglew@0.0.0"
},
Expand All @@ -158,15 +159,15 @@ System.config({
"npm:glsl-exports@0.0.0": {
"glsl-parser": "npm:glsl-parser@0.0.9",
"glsl-tokenizer": "npm:glsl-tokenizer@0.0.9",
"through": "npm:through@1.1.2"
"through": "npm:through@2.3.6"
},
"npm:glsl-parser@0.0.9": {
"glsl-tokenizer": "npm:glsl-tokenizer@0.0.9",
"through": "npm:through@1.1.2"
},
"npm:glsl-tokenizer@0.0.9": {
"process": "github:jspm/nodelibs-process@0.1.0",
"through": "npm:through@1.1.2"
"through": "npm:through@2.3.6"
},
"npm:greedy-mesher@1.0.2": {
"iota-array": "npm:iota-array@1.0.0",
Expand All @@ -193,7 +194,7 @@ System.config({
"npm:ndarray-fft@0.1.0": {
"bit-twiddle": "npm:bit-twiddle@0.0.2",
"cwise": "npm:cwise@0.3.4",
"ndarray": "npm:ndarray@1.0.15",
"ndarray": "npm:ndarray@1.0.16",
"ndarray-ops": "npm:ndarray-ops@1.1.1",
"typedarray-pool": "npm:typedarray-pool@0.1.2"
},
Expand All @@ -204,10 +205,10 @@ System.config({
"cwise-compiler": "npm:cwise-compiler@0.0.0"
},
"npm:ndarray-scratch@0.0.1": {
"ndarray": "npm:ndarray@1.0.15",
"ndarray": "npm:ndarray@1.0.16",
"typedarray-pool": "npm:typedarray-pool@0.1.2"
},
"npm:ndarray@1.0.15": {
"npm:ndarray@1.0.16": {
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"iota-array": "npm:iota-array@1.0.0"
},
Expand All @@ -225,8 +226,8 @@ System.config({
"string_decoder": "npm:string_decoder@0.10.31",
"util": "github:jspm/nodelibs-util@0.1.0"
},
"npm:source-map@0.1.40": {
"amdefine": "npm:amdefine@0.0.8",
"npm:source-map@0.1.43": {
"amdefine": "npm:amdefine@0.1.0",
"fs": "github:jspm/nodelibs-fs@0.1.0",
"path": "github:jspm/nodelibs-path@0.1.0",
"process": "github:jspm/nodelibs-process@0.1.0"
Expand All @@ -243,8 +244,16 @@ System.config({
"process": "github:jspm/nodelibs-process@0.1.0",
"stream": "github:jspm/nodelibs-stream@0.1.0"
},
"npm:through@2.2.7": {
"process": "github:jspm/nodelibs-process@0.1.0",
"stream": "github:jspm/nodelibs-stream@0.1.0"
},
"npm:through@2.3.6": {
"process": "github:jspm/nodelibs-process@0.1.0",
"stream": "github:jspm/nodelibs-stream@0.1.0"
},
"npm:tile-mip-map@0.2.1": {
"ndarray": "npm:ndarray@1.0.15",
"ndarray": "npm:ndarray@1.0.16",
"ndarray-downsample2x": "npm:ndarray-downsample2x@0.1.1",
"ndarray-ops": "npm:ndarray-ops@1.1.1"
},
Expand Down Expand Up @@ -273,7 +282,7 @@ System.config({
"gl-shader": "npm:gl-shader@0.0.6",
"gl-tile-map": "npm:gl-tile-map@0.3.0",
"gl-vao": "npm:gl-vao@0.0.3",
"ndarray": "npm:ndarray@1.0.15",
"ndarray": "npm:ndarray@1.0.16",
"ndarray-fill": "npm:ndarray-fill@0.1.0",
"ndarray-ops": "npm:ndarray-ops@1.1.1"
}
Expand Down

0 comments on commit f91375b

Please sign in to comment.