Skip to content
Browse files

Merge branch 'multi-app-json' of git://github.com/drewfish/mojito int…

…o multi-appjson
  • Loading branch information...
2 parents 2bde38a + d1390d7 commit e5a717da2a5181c93b8625bd657618b6e8ffe062 @caridy committed
View
1 .gitignore
@@ -4,6 +4,7 @@
*.bak
*~
node_modules
+!tests/fixtures/app-jsons/node_modules
!tests/fixtures/packages/node_modules
!tests/fixtures/packages/node_modules/*/node_modules
arrowreport
View
48 lib/app/addons/rs/config.js
@@ -165,6 +165,48 @@ YUI.add('addon-rs-config', function(Y, NAME) {
/**
+ * Creates a YCB configuration bundle using contents from multiple files.
+ * The appropriate dimensions.json file will be mixed in, and doesn't need
+ * to be part of the list of files.
+ * @method createMultipartYCB
+ * @param {array} paths list of files to load
+ * @return {YCB|undefined} return a YCB library object, or undefined if an error occurs
+ */
+ createMultipartYCB: function(paths) {
+ var p,
+ path,
+ config,
+ s,
+ section,
+ settings = {},
+ bundle = [];
+ bundle.push(this.getDimensions()[0]);
+ for (p = 0; p < paths.length; p += 1) {
+ path = paths[p];
+ config = this.readConfigSync(path);
+ if (!Y.Lang.isArray(config)) {
+ Y.log('not a YCB file: ' + path, 'error', NAME);
+ return;
+ }
+ for (s = 0; s < config.length; s += 1) {
+ section = config[s];
+ if (!Y.Lang.isArray(section.settings)) {
+ Y.log('missing "settings" in YCB file: ' + path, 'error', NAME);
+ return;
+ }
+ if (settings[section.settings]) {
+ Y.log('settings "' + section.settings + '" exists in both \n' + path + ' and\n' + settings[section.settings], 'error', NAME);
+ return;
+ }
+ settings[section.settings] = path;
+ bundle.push(section);
+ }
+ }
+ return new libycb.Ycb(bundle);
+ },
+
+
+ /**
* Using AOP, this is called after the ResourceStore's version.
* @method findResourceVersionByConvention
* @param {object} source metadata about where the resource is located
@@ -199,6 +241,10 @@ YUI.add('addon-rs-config', function(Y, NAME) {
if (mojitType && 'shared' !== mojitType) {
use = true;
}
+ // use application.{json,yaml,yml} in bundles as well
+ if ('bundle' === fs.rootType && 'application' === fs.basename) {
+ use = true;
+ }
if (!use) {
return;
}
@@ -237,7 +283,7 @@ YUI.add('addon-rs-config', function(Y, NAME) {
affinity: 'common',
selector: '*'
};
- if ('app' !== source.fs.rootType) {
+ if ('mojit' === source.fs.rootType) {
res.mojit = mojitType;
}
res.name = libpath.join(source.fs.subDir, baseParts.join('.'));
View
8 lib/app/addons/rs/selector.js
@@ -36,16 +36,10 @@ YUI.add('addon-rs-selector', function(Y, NAME) {
* @return {nothing}
*/
initializer: function(config) {
- var dims,
- json;
this.appRoot = config.appRoot;
this.mojitoRoot = config.mojitoRoot;
- dims = config.host.config.getDimensions();
- json = config.host.config.readConfigSimple(libpath.join(this.appRoot, 'application.json'));
- json = dims.concat(json);
- // TODO: use rs.config for this too
- this._appConfigYCB = new libycb.Ycb(json);
+ this._appConfigYCB = config.host.getAppConfigYCB();
this._poslCache = {}; // context: POSL
},
View
69 lib/app/autoload/store.server.js
@@ -223,7 +223,15 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
this._validDims = this._parseValidDims(this.config.getDimensions());
this.validateContext(this._config.context);
this._fwConfig = this.config.readConfigSimple(this._libs.path.join(this._config.mojitoRoot, 'config.json'));
+
+ // We use this during preload() before we even know about all the
+ // application.jsons. This might be OK, since we'll have the real
+ // values during the second pass.
+ // In practice, this only applies to "mojitDirs" and "mojitsDirs",
+ // which can only be given in the app-level application.json.
this._appConfigStatic = this.getAppConfig({});
+
+ this._appConfigYCB = null; // libycb object
},
destructor: function() {},
@@ -349,13 +357,20 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
key,
ycb;
+ ctx = this.blendStaticContext(ctx);
key = JSON.stringify(ctx || {});
if (this._appConfigCache[key]) {
return JSON.parse(this._appConfigCache[key]);
}
- ycb = this.config.readConfigYCB(this._libs.path.join(this._config.root, 'application.json'), ctx);
+ if (this._appConfigYCB) {
+ ycb = this._appConfigYCB.read(ctx);
+ } else {
+ // This is generally only used to populate the initial this._appConfigStatic.
+ // After preload() we'll have this._appConfigYCB.
+ ycb = this.config.readConfigYCB(this._libs.path.join(this._config.root, 'application.json'), ctx);
+ }
appConfig = Y.mojito.util.blend(this._fwConfig.appConfigBase, this._config.appConfig);
appConfig = Y.mojito.util.blend(appConfig, ycb);
@@ -364,6 +379,19 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
return appConfig;
},
+
+
+ /**
+ * Returns the YCB library object for the application config.
+ * This is rarely what you want to use. getAppConfig() is a better choice.
+ * @method getAppConfigYCB
+ * @return {YCB} YCB library object for the application config
+ */
+ getAppConfigYCB: function() {
+ return this._appConfigYCB;
+ },
+
+
/**
* Preloads everything in the app, and as well pertinent parts of
* the framework.
@@ -374,10 +402,19 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
preload: function() {
// We need to do an initial sweep to find the resource store addons.
this.preloadResourceVersions();
+
+ // Now that we've found all the application.jsons, we can aggregate them.
+ this._initAppConfig();
+
+ // We need to rebuild _appConfigStatic -before- we load the addons,
+ // since they might (they do) cache the results of getStaticAppConfig().
+ this._appConfigStatic = this.getAppConfig({});
+
// And then use them.
this.loadAddons();
// Then, do another sweep so that the loaded addons can be used.
this.preloadResourceVersions();
+
this.makeResourceVersions();
this.resolveResourceVersions();
},
@@ -2081,6 +2118,36 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
});
Y.use.apply(Y, Object.keys(modules));
Y.applyConfig({ useSync: false });
+ },
+
+
+ /**
+ * Initializes the special multi-file YCB library for all the application.jsons.
+ * The object is used by getAppConfig().
+ * @private
+ * @method _initAppConfig
+ * @return {nothing}
+ */
+ _initAppConfig: function() {
+ var r,
+ res,
+ ress,
+ paths = [];
+
+ // TODO: detect conflicting peers (i.e. both application.json and application.yaml)
+
+ ress = this.getResourceVersions({type: 'config', name: 'application'});
+ for (r = 0; r < ress.length; r += 1) {
+ res = ress[r];
+ paths.push(res.source.fs.fullPath);
+ }
+ this._appConfigYCB = this.config.createMultipartYCB(paths);
+ if (!this._appConfigYCB) {
+ throw new Error("failed to create a YCB config from the following files:\n " + paths.join("\n "));
+ }
+ // New way to load means invalidating the whole cache.
+ // In practice, the cache likely only has the static version.
+ this._appConfigCache = {};
}
View
7 tests/fixtures/app-jsons/application-nosettings.json
@@ -0,0 +1,7 @@
+[
+ {
+ "testKey1": "testVal1",
+ "testKey2": "testVal2",
+ "testKey3": "testVal3"
+ }
+]
View
8 tests/fixtures/app-jsons/application-notycb.json
@@ -0,0 +1,8 @@
+{
+ "foo": {
+ "settings": [ "master" ],
+ "testKey1": "testVal1",
+ "testKey2": "testVal2",
+ "testKey3": "testVal3"
+ }
+}
View
8 tests/fixtures/app-jsons/application.json
@@ -0,0 +1,8 @@
+[
+ {
+ "settings": [ "master" ],
+ "testKey1": "testVal1",
+ "testKey2": "testVal2",
+ "testKey3": "testVal3"
+ }
+]
View
8 tests/fixtures/app-jsons/application2.json
@@ -0,0 +1,8 @@
+[
+ {
+ "settings": [ "master" ],
+ "testKey1": "testVal1-app2",
+ "testKey2": "testVal2-app2",
+ "testKey3": "testVal3-app2"
+ }
+]
View
14 tests/fixtures/app-jsons/node_modules/devices/application.json
@@ -0,0 +1,14 @@
+[
+ {
+ "settings": [ "device:iphone" ],
+ "selector": "iphone"
+ },
+ {
+ "settings": [ "device:android" ],
+ "selector": "droid"
+ },
+ {
+ "settings": [ "device:android", "environment:dev" ],
+ "selector": "devdroid"
+ }
+]
View
18 tests/fixtures/app-jsons/node_modules/devices/package.json
@@ -0,0 +1,18 @@
+{
+ "name": "devices",
+ "version": "666.0.0",
+ "description": "devices package",
+ "author": "Team Mojito (http://developer.yahoo.com/cocktails/mojito)",
+ "dependencies": {},
+ "main": ".",
+ "engines": {
+ "node": ">= 0.4.0",
+ "npm": ">= 1.0.0"
+ },
+ "devDependencies": {},
+ "yahoo": {
+ "mojito": {
+ "type": "bundle"
+ }
+ }
+}
View
14 tests/fixtures/app-jsons/node_modules/runtimes/application.json
@@ -0,0 +1,14 @@
+[
+ {
+ "settings": [ "runtime:server" ],
+ "selector": "shelves",
+ "testKey1": "testVal1-server",
+ "pathos": "portended"
+ },
+ {
+ "settings": [ "runtime:client" ],
+ "selector": "right",
+ "testKey2": "testVal2-client",
+ "testKey4": "testVal4-client"
+ }
+]
View
18 tests/fixtures/app-jsons/node_modules/runtimes/package.json
@@ -0,0 +1,18 @@
+{
+ "name": "runtimes",
+ "version": "666.0.0",
+ "description": "runtimes package",
+ "author": "Team Mojito (http://developer.yahoo.com/cocktails/mojito)",
+ "dependencies": {},
+ "main": ".",
+ "engines": {
+ "node": ">= 0.4.0",
+ "npm": ">= 1.0.0"
+ },
+ "devDependencies": {},
+ "yahoo": {
+ "mojito": {
+ "type": "bundle"
+ }
+ }
+}
View
13 tests/fixtures/app-jsons/package.json
@@ -0,0 +1,13 @@
+{
+ "name": "root",
+ "version": "666.0.0",
+ "description": "root package",
+ "author": "Team Mojito (http://developer.yahoo.com/cocktails/mojito)",
+ "dependencies": {},
+ "main": ".",
+ "engines": {
+ "node": ">= 0.4.0",
+ "npm": ">= 1.0.0"
+ },
+ "devDependencies": {}
+}
View
139 tests/unit/lib/app/addons/rs/test-config.js
@@ -3,7 +3,7 @@
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
-YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
+YUI().use('addon-rs-config', 'mojito-util', 'mojito-test-extra', 'base', 'oop', 'test', function(Y) {
var suite = new YUITest.TestSuite('mojito-addon-rs-config-tests'),
libfs = require('fs'),
@@ -58,31 +58,6 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
}
- function cmp(x, y, msg, path) {
- if (Y.Lang.isArray(x)) {
- A.isArray(x, msg || 'first arg should be an array');
- A.isArray(y, msg || 'second arg should be an array');
- A.areSame(x.length, y.length, msg || 'arrays are different lengths');
- for (var i = 0; i < x.length; i += 1) {
- cmp(x[i], y[i], msg);
- }
- return;
- }
- if (Y.Lang.isObject(x)) {
- A.isObject(x, msg || 'first arg should be an object');
- A.isObject(y, msg || 'second arg should be an object');
- A.areSame(Object.keys(x).length, Object.keys(y).length, msg || 'object keys are different lengths');
- for (var i in x) {
- if (x.hasOwnProperty(i)) {
- cmp(x[i], y[i], msg);
- }
- }
- return;
- }
- A.areSame(x, y, msg || 'args should be the same');
- }
-
-
function makeSource(dir, dirType, subdir, file, isFile) {
var source = {
fs: {
@@ -116,7 +91,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
var have = store.config.getDimensions();
var want = readJSON(mojitoRoot, 'dimensions.json');
- cmp(want, have);
+ Y.TEST_CMP(want, have);
// app-specified
fixtures = libpath.join(__dirname, '../../../../../fixtures/ycb');
@@ -124,7 +99,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
have = store.config.getDimensions();
want = readJSON(fixtures, 'dimensions.json');
- cmp(want, have);
+ Y.TEST_CMP(want, have);
},
@@ -137,49 +112,71 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
var source = makeSource(fixtures, 'app', '.', 'server.js', true);
var have = store.findResourceVersionByConvention(source, null);
var want = undefined;
- cmp(have, want, 'skip non-json files');
+ Y.TEST_CMP(have, want, 'skip non-json files');
// include all json files in the app
source = makeSource(fixtures, 'app', '.', 'x.json', true);
have = store.findResourceVersionByConvention(source, null);
want = { type: 'config' };
- cmp(have, want, 'include all json files in the app');
+ Y.TEST_CMP(have, want, 'include all json files in the app');
// ... explicitly including package.json
source = makeSource(fixtures, 'app', '.', 'package.json', true);
have = store.findResourceVersionByConvention(source, null);
want = { type: 'config' };
- cmp(have, want, 'include package.json in the app');
+ Y.TEST_CMP(have, want, 'include package.json in the app');
// exclude all json files in a bundle
source = makeSource(fixtures, 'bundle', '.', 'x.json', true);
have = store.findResourceVersionByConvention(source, null);
want = undefined;
- cmp(have, want, 'exclude all json files in a bundle');
+ Y.TEST_CMP(have, want, 'exclude all json files in a bundle');
// ... explicitly excluding package.json
source = makeSource(fixtures, 'bundle', '.', 'package.json', true);
have = store.findResourceVersionByConvention(source, null);
want = undefined;
- cmp(have, want, 'exclude package.json in a bundle');
+ Y.TEST_CMP(have, want, 'exclude package.json in a bundle');
// include all json files in a mojit
source = makeSource(fixtures, 'mojit', '.', 'x.json', true);
have = store.findResourceVersionByConvention(source, 'foo');
want = { type: 'config' };
- cmp(have, want, 'include all json files in a mojit');
+ Y.TEST_CMP(have, want, 'include all json files in a mojit');
// ... except for the 'shared' mojit
source = makeSource(fixtures, 'mojit', '.', 'x.json', true);
have = store.findResourceVersionByConvention(source, 'shared');
want = undefined;
- cmp(have, want, 'exclude all json files in the "shared" mojit');
+ Y.TEST_CMP(have, want, 'exclude all json files in the "shared" mojit');
// ... explicitly including package.json
source = makeSource(fixtures, 'mojit', '.', 'package.json', true);
have = store.findResourceVersionByConvention(source, 'shared');
want = { type: 'config' };
- cmp(have, want, 'include package.json in the "shared" mojit');
+ Y.TEST_CMP(have, want, 'include package.json in the "shared" mojit');
+
+ // include application.json in packages
+ source = {
+ fs: {
+ fullPath: libpath.join(fixtures, 'node_modules', 'foo', 'application.json'),
+ rootDir: libpath.join(fixtures, 'node_modules', 'foo'),
+ rootType: 'bundle',
+ subDir: '.',
+ subDirArray: ['.'],
+ isFile: true,
+ basename: 'application',
+ ext: '.json'
+ },
+ pkg: {
+ name: 'foo',
+ version: '999.666.999',
+ depth: 999
+ }
+ };
+ have = store.findResourceVersionByConvention(source, 'shared');
+ want = { type: 'config' };
+ Y.TEST_CMP(have, want, 'include application.json in NPM modules');
},
@@ -191,7 +188,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
var source = makeSource(fixtures, 'app', '.', 'application.json', true);
var res = store.parseResourceVersion(source, 'config');
A.isNotUndefined(res);
- cmp(res.source, source);
+ Y.TEST_CMP(res.source, source);
A.areSame('config', res.type);
A.areSame('common', res.affinity);
A.areSame('*', res.selector);
@@ -202,7 +199,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
source = makeSource(fixtures, 'mojit', '.', 'defaults.json', true);
res = store.parseResourceVersion(source, 'config', undefined, 'x');
A.isNotUndefined(res);
- cmp(res.source, source);
+ Y.TEST_CMP(res.source, source);
A.areSame('config', res.type);
A.areSame('common', res.affinity);
A.areSame('*', res.selector);
@@ -220,7 +217,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
var path = libpath.join(fixtures, 'application.json');
var have = store.config.readConfigSimple(path);
var want = readJSON(fixtures, 'application.json');
- cmp(have, want);
+ Y.TEST_CMP(have, want);
},
@@ -276,7 +273,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
"selector": "shelves",
"pathos": "portended"
};
- cmp(have, want);
+ Y.TEST_CMP(have, want);
},
@@ -303,16 +300,10 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
var path = libpath.join(fixtures, 'routes.json');
var have = store.config.readConfigYCB(path, {});
var want = {};
- cmp(have, want);
- }
+ Y.TEST_CMP(have, want);
+ },
- }));
-
- suite.add(new YUITest.TestCase({
-
- name: 'config rs addon tests',
-
"readConfigSync JSON file": function () {
var fixtures = libpath.join(__dirname, '../../../../../fixtures'),
@@ -327,6 +318,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
A.areSame("val", obj.key);
},
+
"readConfigSync YAML file": function () {
var fixtures = libpath.join(__dirname, '../../../../../fixtures'),
@@ -341,6 +333,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
A.areSame("val", obj.key);
},
+
"readConfigSync YML file": function () {
var fixtures = libpath.join(__dirname, '../../../../../fixtures'),
@@ -355,6 +348,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
A.areSame("val", obj.key);
},
+
"readConfigSync no ext file": function () {
var fixtures = libpath.join(__dirname, '../../../../../fixtures'),
@@ -369,6 +363,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
A.areSame("val", obj.key);
},
+
"readConfigSync YAML file with TAB not space": function () {
var fixtures = libpath.join(__dirname, '../../../../../fixtures'),
@@ -383,7 +378,55 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
catch (err) {
A.areSame('Error parsing file:', err.message.substr(0, 19));
}
+ },
+
+
+ 'create multipart ycb': function () {
+ var fixtures = libpath.join(__dirname, '../../../../../fixtures/app-jsons'),
+ store = new MockRS({ root: fixtures });
+ store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
+
+ var paths, ycb, config;
+ paths = [
+ libpath.join(fixtures, 'application.json'),
+ libpath.join(fixtures, 'node_modules', 'devices', 'application.json'),
+ libpath.join(fixtures, 'node_modules', 'runtimes', 'application.json'),
+ ];
+ ycb = store.config.createMultipartYCB(paths);
+ A.isObject(ycb);
+ config = ycb.read({runtime: 'client'});
+ A.isObject(config);
+ A.areSame('testVal2-client', config.testKey2);
+ config = ycb.read({device: 'android'});
+ A.isObject(config);
+ A.areSame('droid', config.selector);
+
+ // detect non-ycb file
+ paths = [
+ libpath.join(fixtures, 'application.json'),
+ libpath.join(fixtures, 'application-notycb.json')
+ ];
+ ycb = store.config.createMultipartYCB(paths);
+ A.isUndefined(ycb);
+
+ // detect missing settings
+ paths = [
+ libpath.join(fixtures, 'application.json'),
+ libpath.join(fixtures, 'application-nosettings.json')
+ ];
+ ycb = store.config.createMultipartYCB(paths);
+ A.isUndefined(ycb);
+
+ // detect duplicate settings
+ paths = [
+ libpath.join(fixtures, 'application.json'),
+ libpath.join(fixtures, 'application2.json')
+ ];
+ ycb = store.config.createMultipartYCB(paths);
+ A.isUndefined(ycb);
}
+
+
}));
Y.Test.Runner.add(suite);
View
57 tests/unit/lib/app/addons/rs/test-selector.js
@@ -4,6 +4,7 @@
* See the accompanying LICENSE file for terms.
*/
YUI().use(
+ 'mojito-test-extra',
'base',
'oop',
'addon-rs-config',
@@ -13,7 +14,9 @@ YUI().use(
var suite = new Y.Test.Suite('mojito-addon-rs-selector-tests'),
libpath = require('path'),
+ libycb = require('ycb'),
mojitoRoot = libpath.join(__dirname, '../../../../../../lib'),
+ fixtures = libpath.join(__dirname, '../../../../../fixtures/store');
A = Y.Assert;
@@ -33,6 +36,11 @@ YUI().use(
'*': true
};
},
+ getAppConfigYCB: function() {
+ return this.config.createMultipartYCB([
+ libpath.join(fixtures, 'application.json')
+ ]);
+ },
validateContext: function() {},
cloneObj: function(o) {
return Y.clone(o);
@@ -40,74 +48,47 @@ YUI().use(
});
- function cmp(x, y, msg, path) {
- if (Y.Lang.isArray(x)) {
- A.isArray(x, msg || 'first arg should be an array');
- A.isArray(y, msg || 'second arg should be an array');
- A.areSame(x.length, y.length, msg || 'arrays are different lengths');
- for (var i = 0; i < x.length; i += 1) {
- cmp(x[i], y[i], msg);
- }
- return;
- }
- if (Y.Lang.isObject(x)) {
- A.isObject(x, msg || 'first arg should be an object');
- A.isObject(y, msg || 'second arg should be an object');
- A.areSame(Object.keys(x).length, Object.keys(y).length, msg || 'object keys are different lengths');
- for (var i in x) {
- if (x.hasOwnProperty(i)) {
- cmp(x[i], y[i], msg);
- }
- }
- return;
- }
- A.areSame(x, y, msg || 'args should be the same');
- }
-
-
suite.add(new Y.Test.Case({
name: 'selector rs addon tests',
'read dimensions': function() {
// from mojito
- var fixtures = libpath.join(__dirname, '../../../../../fixtures/store');
var store = new MockRS({ root: fixtures });
store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
store.plug(Y.mojito.addons.rs.selector, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
var have = store.selector.getPOSLFromContext({});
var want = ['*'];
- cmp(have, want);
+ Y.TEST_CMP(have, want);
var have = store.selector.getPOSLFromContext({runtime:'client'});
var want = ['right', '*'];
- cmp(have, want);
+ Y.TEST_CMP(have, want);
var have = store.selector.getPOSLFromContext({runtime:'server'});
var want = ['shelves', '*'];
- cmp(have, want);
+ Y.TEST_CMP(have, want);
var have = store.selector.getPOSLFromContext({device:'android'});
var want = ['droid', '*'];
- cmp(have, want);
+ Y.TEST_CMP(have, want);
var have = store.selector.getPOSLFromContext({runtime:'server', device:'android'});
var want = ['shelves', 'droid', '*'];
- cmp(have, want);
+ Y.TEST_CMP(have, want);
var have = store.selector.getPOSLFromContext({device:'android', environment:'dev'});
var want = ['devdroid', 'droid', '*'];
- cmp(have, want);
+ Y.TEST_CMP(have, want);
var have = store.selector.getPOSLFromContext({runtime:'server', device:'android', environment:'dev'});
var want = ['shelves', 'devdroid', 'droid', '*'];
- cmp(have, want);
+ Y.TEST_CMP(have, want);
},
'get all posls': function() {
- var fixtures = libpath.join(__dirname, '../../../../../fixtures/store');
var store = new MockRS({ root: fixtures });
store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
store.plug(Y.mojito.addons.rs.selector, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
@@ -121,12 +102,11 @@ YUI().use(
[ 'right', 'devdroid', 'droid', '*' ],
[ 'right', 'droid', '*' ]
];
- cmp(want, have);
+ Y.TEST_CMP(want, have);
},
'list used dimensions': function() {
- var fixtures = libpath.join(__dirname, '../../../../../fixtures/store');
var store = new MockRS({ root: fixtures });
store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
store.plug(Y.mojito.addons.rs.selector, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
@@ -137,12 +117,11 @@ YUI().use(
device: ['iphone', 'android'],
environment: ['dev']
}
- cmp(want, have);
+ Y.TEST_CMP(want, have);
},
'list used contexts': function() {
- var fixtures = libpath.join(__dirname, '../../../../../fixtures/store');
var store = new MockRS({ root: fixtures });
store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
store.plug(Y.mojito.addons.rs.selector, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
@@ -162,7 +141,7 @@ YUI().use(
{ runtime: 'client', environment: 'dev' },
{ runtime: 'client' }
];
- cmp(want, have);
+ Y.TEST_CMP(want, have);
}
View
27 tests/unit/lib/app/autoload/test-store.server.js
@@ -5,6 +5,7 @@
*/
YUI().use(
'oop',
+ 'mojito-test-extra',
'mojito-resource-store',
'addon-rs-config',
'addon-rs-selector',
@@ -23,30 +24,6 @@ YUI().use(
OA = Y.ObjectAssert;
- function cmp(x, y, msg) {
- if (Y.Lang.isArray(x)) {
- A.isArray(x, msg || 'first arg should be an array');
- A.isArray(y, msg || 'second arg should be an array');
- A.areSame(x.length, y.length, msg || 'arrays are different lengths');
- for (var i = 0; i < x.length; i += 1) {
- cmp(x[i], y[i], msg);
- }
- return;
- }
- if (Y.Lang.isObject(x)) {
- A.isObject(x, msg || 'first arg should be an object');
- A.isObject(y, msg || 'second arg should be an object');
- A.areSame(Object.keys(x).length, Object.keys(y).length, msg || 'object keys are different lengths');
- for (var i in x) {
- if (x.hasOwnProperty(i)) {
- cmp(x[i], y[i], msg);
- }
- }
- return;
- }
- A.areSame(x, y, msg || 'args should be the same');
- }
-
suite.add(new Y.Test.Case({
name: 'Store tests -- preload fixture "store"',
@@ -294,7 +271,7 @@ YUI().use(
appResources: Y.clone(store._appResources, true),
mojitResources: Y.clone(store._mojitResources, true)
};
- cmp(post, pre);
+ Y.TEST_CMP(post, pre);
},
'instance with base pointing to non-existant spec': function() {

0 comments on commit e5a717d

Please sign in to comment.
Something went wrong with that request. Please try again.