mojito-markup-test
Advanced tools
Comparing version 0.0.10 to 0.1.0
{ | ||
"name": "mojito-markup-test", | ||
"description": "Utility for view markup validation in mojito unit tests.", | ||
"version": "0.0.10", | ||
"version": "0.1.0", | ||
"author": "David Gomez <dgomez@yahoo-inc.com>", | ||
@@ -14,2 +14,5 @@ "contributors": [ | ||
}, | ||
"dependencies": { | ||
"express": "3.5.x" | ||
}, | ||
"devDependencies": { | ||
@@ -16,0 +19,0 @@ "mojito": "0.9.x", |
@@ -32,5 +32,16 @@ /* | ||
spec = { | ||
root: path.join(__dirname, 'fixtures/app'), | ||
options: { | ||
root: path.join(__dirname, 'fixtures/app'), | ||
appConfig: { | ||
resourceStore: { | ||
lazyMojits: true, | ||
lazyLangs: true | ||
} | ||
} | ||
}, | ||
type: 'CompositeMojit', | ||
action: 'index' | ||
action: 'index', | ||
context: { | ||
lang: 'en-US' | ||
} | ||
}; | ||
@@ -97,3 +108,11 @@ | ||
spec = { | ||
root: path.join(__dirname, 'fixtures/app'), | ||
options: { | ||
root: path.join(__dirname, 'fixtures/app'), | ||
appConfig: { | ||
resourceStore: { | ||
lazyMojits: true, | ||
lazyLangs: true | ||
} | ||
} | ||
}, | ||
type: 'InvalidMojit', | ||
@@ -100,0 +119,0 @@ action: 'index' |
@@ -13,190 +13,83 @@ /* | ||
var pathlib = require('path'), | ||
rs = require('mojito/lib/store'), | ||
cwd = process.cwd(), | ||
var cwd = process.cwd(), | ||
express = require('express'), | ||
Mojito = require('mojito'), | ||
MAX_CACHED_APPS = 5, | ||
cachedApps = {}, | ||
utils, | ||
store, | ||
createApp = function (spec) { | ||
O = Y.Object, | ||
A = Y.Array, | ||
var options = spec.options || {}, | ||
key = JSON.stringify( | ||
// Stringified options, with sorted properties | ||
Y.mix({}, options, true, Y.Object.keys(options).sort()) | ||
), | ||
app = cachedApps[key]; | ||
DEFAULT_LANG = 'en-US', | ||
DEFAULT_ENV = 'server', | ||
if (app && !spec.skipCache) { | ||
return app; | ||
} | ||
Dispatcher = Y.mojito.Dispatcher, | ||
// TODO mojito should accept options.root | ||
process.chdir(options.root || cwd); | ||
/** | ||
* Mock logger | ||
*/ | ||
logger = { | ||
log: Y.bind(Y.log, Y) | ||
}, | ||
app = cachedApps[key] = express(); | ||
/** | ||
* Mock base instance config | ||
*/ | ||
baseSpec = { | ||
req: {}, | ||
res: {}, | ||
headers: {}, | ||
appConfig: {} | ||
}, | ||
// We clone the options since mojito actually modifies the object, | ||
// and if the modified options object is reused, then the generated key would | ||
// differ. Cloning ensures that the same options object can be used, while | ||
// maintaining the same cache key. | ||
Mojito.extend(app, Y.clone(options, true)); | ||
fullMerge = function (receiver, supplier) { | ||
Y.mix(receiver, supplier, false, null, 0, true); | ||
}, | ||
// TODO: this is only necessary for YUI modules to appear in istanbul code coverage. | ||
app.mojito.store.Y = Y; | ||
configureYUI = function () { | ||
var modules, | ||
load, | ||
lang; | ||
Y.use.apply(Y, ['mojito', 'mojito-util', 'mojito-hooks', 'mojito-dispatcher', 'mojito-hb', 'mojito-mu']); | ||
modules = store.yui.getModulesConfig('server', false); | ||
Y.applyConfig(modules); | ||
load = Object.keys(modules.modules); | ||
// NOTE: Not all of these module names are guaranteed to be valid, | ||
// but the loader tolerates them anyways. | ||
for (lang in store.yui.langs) { | ||
if (store.yui.langs.hasOwnProperty(lang) && lang) { | ||
load.push('lang/datatype-date-format_' + lang); | ||
} | ||
if (Y.Object.size(cachedApps) > MAX_CACHED_APPS) { | ||
delete cachedApps[Y.Object.keys(cachedApps)[0]]; | ||
} | ||
// attaching all modules available for this application for the server side | ||
Y.applyConfig({ useSync: true }); | ||
Y.use.apply(Y, load); | ||
Y.applyConfig({ useSync: false }); | ||
store.Y = Y; | ||
// TODO mojito should accept options.root | ||
process.chdir(cwd); | ||
return app; | ||
}, | ||
preloadStore = function (cfg) { | ||
if (!store || !cfg.reuse) { | ||
store = rs.createStore(cfg); | ||
store._staticDetails = {}; | ||
store._appY = Y; | ||
store.preload(); | ||
configureYUI(); | ||
} | ||
}, | ||
isMojitDefined = function (env, type) { | ||
var found = Y.Array.find(store.listAllMojits(env), function (name) { | ||
return name === type; | ||
}); | ||
return !Y.Lang.isNull(found); | ||
}, | ||
getMojitTypeDetails = function (env, ctx, type, callback) { | ||
var mojitType; | ||
try { | ||
mojitType = store.getMojitTypeDetails(env, ctx, type); | ||
} catch (e) { | ||
return callback(e); | ||
} | ||
callback(null, mojitType); | ||
}, | ||
render = function (spec, callback) { | ||
var env = spec.env || DEFAULT_ENV, | ||
root = spec.root || cwd, | ||
ctx = spec.context || {}, | ||
type = spec.type, | ||
appConfig = spec.appConfig || {}, | ||
viewSpec; | ||
var app = spec.app || createApp(spec), | ||
context = spec.context || {}, | ||
store = app.mojito.store, | ||
dispatcher = store.Y.mojito.Dispatcher.init(app.mojito.store), | ||
command = { | ||
instance: spec, | ||
context: context, | ||
params: spec.params | ||
}, | ||
adapter = new Y.mojito.OutputBuffer(null, function (error, data, meta) { | ||
if (error) { | ||
return callback(error); | ||
} | ||
preloadStore({ | ||
root: root, | ||
context: ctx, | ||
appConfig: appConfig, | ||
reuse: spec.reuseStore | ||
}); | ||
var body = Y.one('body'), | ||
node; | ||
if (!isMojitDefined(env, type)) { | ||
callback(new Error( | ||
Y.Lang.sub('Mojit {type} is not defined.', {type: type}) | ||
)); | ||
return; | ||
} | ||
node = Y.Node.create(data); | ||
body.get('children').remove(); | ||
body.append(node); | ||
getMojitTypeDetails(env, ctx, type, function (err, instance) { | ||
callback(null, data, meta, node); | ||
}); | ||
if (err) { | ||
callback(err); | ||
return; | ||
Y.mix(adapter, { | ||
req: spec.req || {}, | ||
res: spec.res || {}, | ||
page: { | ||
staticAppConfig: spec.appConfig || store.getStaticAppConfig(), | ||
appConfig: spec.appConfig || store.getAppConfig(context), | ||
routes: app.getRouteMap() | ||
} | ||
}); | ||
//configure spec | ||
viewSpec = Y.merge(baseSpec, instance, spec); | ||
// dispatcher instantiation | ||
var dispatcher = Dispatcher.init(store), | ||
markup = '', | ||
finalMeta = {}, | ||
append = function (data, meta) { | ||
markup += data; | ||
fullMerge(finalMeta, meta); | ||
}, | ||
//we get data through this | ||
outputAdapter = { | ||
/** | ||
* Mock request data | ||
*/ | ||
req: viewSpec.req, | ||
res: viewSpec.res, | ||
headers: viewSpec.headers, | ||
flush: function (data, meta) { | ||
append(data, meta); | ||
}, | ||
/** | ||
* Reset doc, build a node with markup and attach it | ||
* to Y.Browser.document.body | ||
*/ | ||
done: function (data, meta) { | ||
var body = Y.one('body'), | ||
node; | ||
//merge view data/meta | ||
append(data, meta); | ||
node = Y.Node.create(markup); | ||
body.get('children').remove(); | ||
body.append(node); | ||
callback(null, markup, finalMeta, node); | ||
}, | ||
error: function (err) { | ||
callback(err); | ||
}, | ||
page: { | ||
appConfig: appConfig, | ||
staticAppConfig: appConfig | ||
} | ||
}, | ||
/** | ||
* Mock command | ||
*/ | ||
command = { | ||
instance: viewSpec, | ||
action: spec.action, | ||
context: { | ||
lang: spec.lang || DEFAULT_LANG | ||
}, | ||
params: spec.params | ||
}; | ||
//dispatch mojit | ||
dispatcher.dispatch(command, outputAdapter); | ||
}); | ||
dispatcher.dispatch(command, adapter); | ||
}, | ||
@@ -221,2 +114,3 @@ | ||
requires: [ | ||
'mojito-output-buffer', | ||
'mojito-dispatcher', | ||
@@ -223,0 +117,0 @@ 'jsdom-node' |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
22274
1
383
1
+ Addedexpress@3.5.x
+ Addedbasic-auth-connect@1.0.0(transitive)
+ Addedbatch@0.5.0(transitive)
+ Addedbuffer-crc32@0.2.1(transitive)
+ Addedbytes@0.2.10.3.0(transitive)
+ Addedcommander@1.3.2(transitive)
+ Addedcompressible@1.0.0(transitive)
+ Addedcompression@1.0.0(transitive)
+ Addedconnect@2.14.5(transitive)
+ Addedconnect-timeout@1.0.0(transitive)
+ Addedcookie@0.1.00.1.2(transitive)
+ Addedcookie-parser@1.0.1(transitive)
+ Addedcookie-signature@1.0.3(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcsurf@1.1.0(transitive)
+ Addeddebug@0.7.40.8.00.8.1(transitive)
+ Addederrorhandler@1.0.0(transitive)
+ Addedexpress@3.5.3(transitive)
+ Addedexpress-session@1.0.2(transitive)
+ Addedfresh@0.2.2(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedkeypress@0.1.0(transitive)
+ Addedmerge-descriptors@0.0.2(transitive)
+ Addedmethod-override@1.0.0(transitive)
+ Addedmethods@0.1.0(transitive)
+ Addedmime@1.2.11(transitive)
+ Addedmkdirp@0.4.0(transitive)
+ Addedmorgan@1.0.0(transitive)
+ Addedmultiparty@2.2.0(transitive)
+ Addednegotiator@0.3.00.4.2(transitive)
+ Addedparseurl@1.0.1(transitive)
+ Addedpause@0.0.1(transitive)
+ Addedqs@0.6.6(transitive)
+ Addedrange-parser@1.0.0(transitive)
+ Addedraw-body@1.1.4(transitive)
+ Addedreadable-stream@1.1.14(transitive)
+ Addedresponse-time@1.0.0(transitive)
+ Addedscmp@0.0.3(transitive)
+ Addedsend@0.3.0(transitive)
+ Addedserve-index@1.0.1(transitive)
+ Addedserve-static@1.1.0(transitive)
+ Addedsetimmediate@1.0.1(transitive)
+ Addedstatic-favicon@1.0.2(transitive)
+ Addedstream-counter@0.2.0(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addeduid2@0.0.30.0.4(transitive)
+ Addedutils-merge@1.0.0(transitive)
+ Addedvhost@1.0.0(transitive)