New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mojito-markup-test

Package Overview
Dependencies
Maintainers
4
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mojito-markup-test - npm Package Compare versions

Comparing version 0.0.10 to 0.1.0

5

package.json
{
"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",

25

tests/utility.server-tests.js

@@ -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'

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc