Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[gh238] [bz5667423] application.json files in NPM packages can contri…

…bute as well
  • Loading branch information...
commit d1390d7f619c79a7bcdc66b6327ce27b7dee019c 1 parent 1fd2775
Drew Folta authored January 09, 2013
1  .gitignore
@@ -4,6 +4,7 @@
4 4
 *.bak
5 5
 *~
6 6
 node_modules
  7
+!tests/fixtures/app-jsons/node_modules
7 8
 !tests/fixtures/packages/node_modules
8 9
 !tests/fixtures/packages/node_modules/*/node_modules
9 10
 arrowreport
48  lib/app/addons/rs/config.js
@@ -165,6 +165,48 @@ YUI.add('addon-rs-config', function(Y, NAME) {
165 165
 
166 166
 
167 167
         /**
  168
+         * Creates a YCB configuration bundle using contents from multiple files.
  169
+         * The appropriate dimensions.json file will be mixed in, and doesn't need
  170
+         * to be part of the list of files.
  171
+         * @method createMultipartYCB
  172
+         * @param {array} paths list of files to load
  173
+         * @return {YCB|undefined} return a YCB library object, or undefined if an error occurs
  174
+         */
  175
+        createMultipartYCB: function(paths) {
  176
+            var p,
  177
+                path,
  178
+                config,
  179
+                s,
  180
+                section,
  181
+                settings = {},
  182
+                bundle = [];
  183
+            bundle.push(this.getDimensions()[0]);
  184
+            for (p = 0; p < paths.length; p += 1) {
  185
+                path = paths[p];
  186
+                config = this.readConfigSync(path);
  187
+                if (!Y.Lang.isArray(config)) {
  188
+                    Y.log('not a YCB file: ' + path, 'error', NAME);
  189
+                    return;
  190
+                }
  191
+                for (s = 0; s < config.length; s += 1) {
  192
+                    section = config[s];
  193
+                    if (!Y.Lang.isArray(section.settings)) {
  194
+                        Y.log('missing "settings" in YCB file: ' + path, 'error', NAME);
  195
+                        return;
  196
+                    }
  197
+                    if (settings[section.settings]) {
  198
+                        Y.log('settings "' + section.settings + '" exists in both \n' + path + ' and\n' + settings[section.settings], 'error', NAME);
  199
+                        return;
  200
+                    }
  201
+                    settings[section.settings] = path;
  202
+                    bundle.push(section);
  203
+                }
  204
+            }
  205
+            return new libycb.Ycb(bundle);
  206
+        },
  207
+
  208
+
  209
+        /**
168 210
          * Using AOP, this is called after the ResourceStore's version.
169 211
          * @method findResourceVersionByConvention
170 212
          * @param {object} source metadata about where the resource is located
@@ -199,6 +241,10 @@ YUI.add('addon-rs-config', function(Y, NAME) {
199 241
             if (mojitType && 'shared' !== mojitType) {
200 242
                 use = true;
201 243
             }
  244
+            // use application.{json,yaml,yml} in bundles as well
  245
+            if ('bundle' === fs.rootType && 'application' === fs.basename) {
  246
+                use = true;
  247
+            }
202 248
             if (!use) {
203 249
                 return;
204 250
             }
@@ -237,7 +283,7 @@ YUI.add('addon-rs-config', function(Y, NAME) {
237 283
                 affinity: 'common',
238 284
                 selector: '*'
239 285
             };
240  
-            if ('app' !== source.fs.rootType) {
  286
+            if ('mojit' === source.fs.rootType) {
241 287
                 res.mojit = mojitType;
242 288
             }
243 289
             res.name = libpath.join(source.fs.subDir, baseParts.join('.'));
8  lib/app/addons/rs/selector.js
@@ -36,16 +36,10 @@ YUI.add('addon-rs-selector', function(Y, NAME) {
36 36
          * @return {nothing}
37 37
          */
38 38
         initializer: function(config) {
39  
-            var dims,
40  
-                json;
41 39
             this.appRoot = config.appRoot;
42 40
             this.mojitoRoot = config.mojitoRoot;
43 41
 
44  
-            dims = config.host.config.getDimensions();
45  
-            json = config.host.config.readConfigSimple(libpath.join(this.appRoot, 'application.json'));
46  
-            json = dims.concat(json);
47  
-            // TODO:  use rs.config for this too
48  
-            this._appConfigYCB = new libycb.Ycb(json);
  42
+            this._appConfigYCB = config.host.getAppConfigYCB();
49 43
             this._poslCache = {};   // context: POSL
50 44
         },
51 45
 
69  lib/app/autoload/store.server.js
@@ -223,7 +223,15 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
223 223
             this._validDims = this._parseValidDims(this.config.getDimensions());
224 224
             this.validateContext(this._config.context);
225 225
             this._fwConfig = this.config.readConfigSimple(this._libs.path.join(this._config.mojitoRoot, 'config.json'));
  226
+
  227
+            // We use this during preload() before we even know about all the
  228
+            // application.jsons.  This might be OK, since we'll have the real
  229
+            // values during the second pass.
  230
+            // In practice, this only applies to "mojitDirs" and "mojitsDirs",
  231
+            // which can only be given in the app-level application.json.
226 232
             this._appConfigStatic = this.getAppConfig({});
  233
+
  234
+            this._appConfigYCB = null;  // libycb object
227 235
         },
228 236
         destructor: function() {},
229 237
 
@@ -349,13 +357,20 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
349 357
                 key,
350 358
                 ycb;
351 359
 
  360
+            ctx = this.blendStaticContext(ctx);
352 361
             key = JSON.stringify(ctx || {});
353 362
 
354 363
             if (this._appConfigCache[key]) {
355 364
                 return JSON.parse(this._appConfigCache[key]);
356 365
             }
357 366
 
358  
-            ycb = this.config.readConfigYCB(this._libs.path.join(this._config.root, 'application.json'), ctx);
  367
+            if (this._appConfigYCB) {
  368
+                ycb = this._appConfigYCB.read(ctx);
  369
+            } else {
  370
+                // This is generally only used to populate the initial this._appConfigStatic.
  371
+                // After preload() we'll have this._appConfigYCB.
  372
+                ycb = this.config.readConfigYCB(this._libs.path.join(this._config.root, 'application.json'), ctx);
  373
+            }
359 374
 
360 375
             appConfig = Y.mojito.util.blend(this._fwConfig.appConfigBase, this._config.appConfig);
361 376
             appConfig = Y.mojito.util.blend(appConfig, ycb);
@@ -364,6 +379,19 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
364 379
 
365 380
             return appConfig;
366 381
         },
  382
+
  383
+
  384
+        /**
  385
+         * Returns the YCB library object for the application config.
  386
+         * This is rarely what you want to use.  getAppConfig() is a better choice.
  387
+         * @method getAppConfigYCB
  388
+         * @return {YCB} YCB library object for the application config
  389
+         */
  390
+        getAppConfigYCB: function() {
  391
+            return this._appConfigYCB;
  392
+        },
  393
+
  394
+
367 395
         /**
368 396
          * Preloads everything in the app, and as well pertinent parts of
369 397
          * the framework.
@@ -374,10 +402,19 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
374 402
         preload: function() {
375 403
             // We need to do an initial sweep to find the resource store addons.
376 404
             this.preloadResourceVersions();
  405
+
  406
+            // Now that we've found all the application.jsons, we can aggregate them.
  407
+            this._initAppConfig();
  408
+
  409
+            // We need to rebuild _appConfigStatic -before- we load the addons,
  410
+            // since they might (they do) cache the results of getStaticAppConfig().
  411
+            this._appConfigStatic = this.getAppConfig({});
  412
+
377 413
             // And then use them.
378 414
             this.loadAddons();
379 415
             // Then, do another sweep so that the loaded addons can be used.
380 416
             this.preloadResourceVersions();
  417
+
381 418
             this.makeResourceVersions();
382 419
             this.resolveResourceVersions();
383 420
         },
@@ -2081,6 +2118,36 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
2081 2118
             });
2082 2119
             Y.use.apply(Y, Object.keys(modules));
2083 2120
             Y.applyConfig({ useSync: false });
  2121
+        },
  2122
+
  2123
+
  2124
+        /**
  2125
+         * Initializes the special multi-file YCB library for all the application.jsons.
  2126
+         * The object is used by getAppConfig().
  2127
+         * @private
  2128
+         * @method _initAppConfig
  2129
+         * @return {nothing}
  2130
+         */
  2131
+        _initAppConfig: function() {
  2132
+            var r,
  2133
+                res,
  2134
+                ress,
  2135
+                paths = [];
  2136
+
  2137
+            // TODO: detect conflicting peers (i.e. both application.json and application.yaml)
  2138
+
  2139
+            ress = this.getResourceVersions({type: 'config', name: 'application'});
  2140
+            for (r = 0; r < ress.length; r += 1) {
  2141
+                res = ress[r];
  2142
+                paths.push(res.source.fs.fullPath);
  2143
+            }
  2144
+            this._appConfigYCB = this.config.createMultipartYCB(paths);
  2145
+            if (!this._appConfigYCB) {
  2146
+                throw new Error("failed to create a YCB config from the following files:\n  " + paths.join("\n  "));
  2147
+            }
  2148
+            // New way to load means invalidating the whole cache.
  2149
+            // In practice, the cache likely only has the static version.
  2150
+            this._appConfigCache = {};
2084 2151
         }
2085 2152
 
2086 2153
 
7  tests/fixtures/app-jsons/application-nosettings.json
... ...
@@ -0,0 +1,7 @@
  1
+[
  2
+    {
  3
+        "testKey1": "testVal1",
  4
+        "testKey2": "testVal2",
  5
+        "testKey3": "testVal3"
  6
+    }
  7
+]
8  tests/fixtures/app-jsons/application-notycb.json
... ...
@@ -0,0 +1,8 @@
  1
+{
  2
+    "foo": {
  3
+        "settings": [ "master" ],
  4
+        "testKey1": "testVal1",
  5
+        "testKey2": "testVal2",
  6
+        "testKey3": "testVal3"
  7
+    }
  8
+}
8  tests/fixtures/app-jsons/application.json
... ...
@@ -0,0 +1,8 @@
  1
+[
  2
+    {
  3
+        "settings": [ "master" ],
  4
+        "testKey1": "testVal1",
  5
+        "testKey2": "testVal2",
  6
+        "testKey3": "testVal3"
  7
+    }
  8
+]
8  tests/fixtures/app-jsons/application2.json
... ...
@@ -0,0 +1,8 @@
  1
+[
  2
+    {
  3
+        "settings": [ "master" ],
  4
+        "testKey1": "testVal1-app2",
  5
+        "testKey2": "testVal2-app2",
  6
+        "testKey3": "testVal3-app2"
  7
+    }
  8
+]
14  tests/fixtures/app-jsons/node_modules/devices/application.json
... ...
@@ -0,0 +1,14 @@
  1
+[
  2
+    {
  3
+        "settings": [ "device:iphone" ],
  4
+        "selector": "iphone"
  5
+    },
  6
+    {
  7
+        "settings": [ "device:android" ],
  8
+        "selector": "droid"
  9
+    },
  10
+    {
  11
+        "settings": [ "device:android", "environment:dev" ],
  12
+        "selector": "devdroid"
  13
+    }
  14
+]
18  tests/fixtures/app-jsons/node_modules/devices/package.json
... ...
@@ -0,0 +1,18 @@
  1
+{
  2
+    "name": "devices",
  3
+    "version": "666.0.0",
  4
+    "description": "devices package",
  5
+    "author": "Team Mojito (http://developer.yahoo.com/cocktails/mojito)",
  6
+    "dependencies": {},
  7
+    "main": ".",
  8
+    "engines": {
  9
+        "node": ">= 0.4.0",
  10
+        "npm": ">= 1.0.0"
  11
+    },
  12
+    "devDependencies": {},
  13
+    "yahoo": {
  14
+        "mojito": {
  15
+            "type": "bundle"
  16
+        }
  17
+    }
  18
+}
14  tests/fixtures/app-jsons/node_modules/runtimes/application.json
... ...
@@ -0,0 +1,14 @@
  1
+[
  2
+    {
  3
+        "settings": [ "runtime:server" ],
  4
+        "selector": "shelves",
  5
+        "testKey1": "testVal1-server",
  6
+        "pathos": "portended"
  7
+    },
  8
+    {
  9
+        "settings": [ "runtime:client" ],
  10
+        "selector": "right",
  11
+        "testKey2": "testVal2-client",
  12
+        "testKey4": "testVal4-client"
  13
+    }
  14
+]
18  tests/fixtures/app-jsons/node_modules/runtimes/package.json
... ...
@@ -0,0 +1,18 @@
  1
+{
  2
+    "name": "runtimes",
  3
+    "version": "666.0.0",
  4
+    "description": "runtimes package",
  5
+    "author": "Team Mojito (http://developer.yahoo.com/cocktails/mojito)",
  6
+    "dependencies": {},
  7
+    "main": ".",
  8
+    "engines": {
  9
+        "node": ">= 0.4.0",
  10
+        "npm": ">= 1.0.0"
  11
+    },
  12
+    "devDependencies": {},
  13
+    "yahoo": {
  14
+        "mojito": {
  15
+            "type": "bundle"
  16
+        }
  17
+    }
  18
+}
13  tests/fixtures/app-jsons/package.json
... ...
@@ -0,0 +1,13 @@
  1
+{
  2
+    "name": "root",
  3
+    "version": "666.0.0",
  4
+    "description": "root package",
  5
+    "author": "Team Mojito (http://developer.yahoo.com/cocktails/mojito)",
  6
+    "dependencies": {},
  7
+    "main": ".",
  8
+    "engines": {
  9
+        "node": ">= 0.4.0",
  10
+        "npm": ">= 1.0.0"
  11
+    },
  12
+    "devDependencies": {}
  13
+}
139  tests/unit/lib/app/addons/rs/test-config.js
@@ -3,7 +3,7 @@
3 3
  * Copyrights licensed under the New BSD License.
4 4
  * See the accompanying LICENSE file for terms.
5 5
  */
6  
-YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
  6
+YUI().use('addon-rs-config', 'mojito-util', 'mojito-test-extra', 'base', 'oop', 'test', function(Y) {
7 7
 
8 8
     var suite = new YUITest.TestSuite('mojito-addon-rs-config-tests'),
9 9
         libfs = require('fs'),
@@ -58,31 +58,6 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
58 58
     }
59 59
 
60 60
 
61  
-    function cmp(x, y, msg, path) {
62  
-        if (Y.Lang.isArray(x)) {
63  
-            A.isArray(x, msg || 'first arg should be an array');
64  
-            A.isArray(y, msg || 'second arg should be an array');
65  
-            A.areSame(x.length, y.length, msg || 'arrays are different lengths');
66  
-            for (var i = 0; i < x.length; i += 1) {
67  
-                cmp(x[i], y[i], msg);
68  
-            }
69  
-            return;
70  
-        }
71  
-        if (Y.Lang.isObject(x)) {
72  
-            A.isObject(x, msg || 'first arg should be an object');
73  
-            A.isObject(y, msg || 'second arg should be an object');
74  
-            A.areSame(Object.keys(x).length, Object.keys(y).length, msg || 'object keys are different lengths');
75  
-            for (var i in x) {
76  
-                if (x.hasOwnProperty(i)) {
77  
-                    cmp(x[i], y[i], msg);
78  
-                }
79  
-            }
80  
-            return;
81  
-        }
82  
-        A.areSame(x, y, msg || 'args should be the same');
83  
-    }
84  
-
85  
-
86 61
     function makeSource(dir, dirType, subdir, file, isFile) {
87 62
         var source = {
88 63
             fs: {
@@ -116,7 +91,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
116 91
             store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
117 92
             var have = store.config.getDimensions();
118 93
             var want = readJSON(mojitoRoot, 'dimensions.json');
119  
-            cmp(want, have);
  94
+            Y.TEST_CMP(want, have);
120 95
 
121 96
             // app-specified
122 97
             fixtures = libpath.join(__dirname, '../../../../../fixtures/ycb');
@@ -124,7 +99,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
124 99
             store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
125 100
             have = store.config.getDimensions();
126 101
             want = readJSON(fixtures, 'dimensions.json');
127  
-            cmp(want, have);
  102
+            Y.TEST_CMP(want, have);
128 103
         },
129 104
 
130 105
 
@@ -137,49 +112,71 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
137 112
             var source = makeSource(fixtures, 'app', '.', 'server.js', true);
138 113
             var have = store.findResourceVersionByConvention(source, null);
139 114
             var want = undefined;
140  
-            cmp(have, want, 'skip non-json files');
  115
+            Y.TEST_CMP(have, want, 'skip non-json files');
141 116
 
142 117
             // include all json files in the app
143 118
             source = makeSource(fixtures, 'app', '.', 'x.json', true);
144 119
             have = store.findResourceVersionByConvention(source, null);
145 120
             want = { type: 'config' };
146  
-            cmp(have, want, 'include all json files in the app');
  121
+            Y.TEST_CMP(have, want, 'include all json files in the app');
147 122
 
148 123
             // ... explicitly including package.json
149 124
             source = makeSource(fixtures, 'app', '.', 'package.json', true);
150 125
             have = store.findResourceVersionByConvention(source, null);
151 126
             want = { type: 'config' };
152  
-            cmp(have, want, 'include package.json in the app');
  127
+            Y.TEST_CMP(have, want, 'include package.json in the app');
153 128
 
154 129
             // exclude all json files in a bundle
155 130
             source = makeSource(fixtures, 'bundle', '.', 'x.json', true);
156 131
             have = store.findResourceVersionByConvention(source, null);
157 132
             want = undefined;
158  
-            cmp(have, want, 'exclude all json files in a bundle');
  133
+            Y.TEST_CMP(have, want, 'exclude all json files in a bundle');
159 134
 
160 135
             // ... explicitly excluding package.json
161 136
             source = makeSource(fixtures, 'bundle', '.', 'package.json', true);
162 137
             have = store.findResourceVersionByConvention(source, null);
163 138
             want = undefined;
164  
-            cmp(have, want, 'exclude package.json in a bundle');
  139
+            Y.TEST_CMP(have, want, 'exclude package.json in a bundle');
165 140
 
166 141
             // include all json files in a mojit
167 142
             source = makeSource(fixtures, 'mojit', '.', 'x.json', true);
168 143
             have = store.findResourceVersionByConvention(source, 'foo');
169 144
             want = { type: 'config' };
170  
-            cmp(have, want, 'include all json files in a mojit');
  145
+            Y.TEST_CMP(have, want, 'include all json files in a mojit');
171 146
 
172 147
             // ... except for the 'shared' mojit
173 148
             source = makeSource(fixtures, 'mojit', '.', 'x.json', true);
174 149
             have = store.findResourceVersionByConvention(source, 'shared');
175 150
             want = undefined;
176  
-            cmp(have, want, 'exclude all json files in the "shared" mojit');
  151
+            Y.TEST_CMP(have, want, 'exclude all json files in the "shared" mojit');
177 152
 
178 153
             // ... explicitly including package.json
179 154
             source = makeSource(fixtures, 'mojit', '.', 'package.json', true);
180 155
             have = store.findResourceVersionByConvention(source, 'shared');
181 156
             want = { type: 'config' };
182  
-            cmp(have, want, 'include package.json in the "shared" mojit');
  157
+            Y.TEST_CMP(have, want, 'include package.json in the "shared" mojit');
  158
+
  159
+            // include application.json in packages
  160
+            source = {
  161
+                fs: {
  162
+                    fullPath: libpath.join(fixtures, 'node_modules', 'foo', 'application.json'),
  163
+                    rootDir: libpath.join(fixtures, 'node_modules', 'foo'),
  164
+                    rootType: 'bundle',
  165
+                    subDir: '.',
  166
+                    subDirArray: ['.'],
  167
+                    isFile: true,
  168
+                    basename: 'application',
  169
+                    ext: '.json'
  170
+                },
  171
+                pkg: {
  172
+                    name: 'foo',
  173
+                    version: '999.666.999',
  174
+                    depth: 999
  175
+                }
  176
+            };
  177
+            have = store.findResourceVersionByConvention(source, 'shared');
  178
+            want = { type: 'config' };
  179
+            Y.TEST_CMP(have, want, 'include application.json in NPM modules');
183 180
         },
184 181
 
185 182
 
@@ -191,7 +188,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
191 188
             var source = makeSource(fixtures, 'app', '.', 'application.json', true);
192 189
             var res = store.parseResourceVersion(source, 'config');
193 190
             A.isNotUndefined(res);
194  
-            cmp(res.source, source);
  191
+            Y.TEST_CMP(res.source, source);
195 192
             A.areSame('config', res.type);
196 193
             A.areSame('common', res.affinity);
197 194
             A.areSame('*', res.selector);
@@ -202,7 +199,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
202 199
             source = makeSource(fixtures, 'mojit', '.', 'defaults.json', true);
203 200
             res = store.parseResourceVersion(source, 'config', undefined, 'x');
204 201
             A.isNotUndefined(res);
205  
-            cmp(res.source, source);
  202
+            Y.TEST_CMP(res.source, source);
206 203
             A.areSame('config', res.type);
207 204
             A.areSame('common', res.affinity);
208 205
             A.areSame('*', res.selector);
@@ -220,7 +217,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
220 217
             var path = libpath.join(fixtures, 'application.json');
221 218
             var have = store.config.readConfigSimple(path);
222 219
             var want = readJSON(fixtures, 'application.json');
223  
-            cmp(have, want);
  220
+            Y.TEST_CMP(have, want);
224 221
         },
225 222
 
226 223
 
@@ -276,7 +273,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
276 273
                 "selector": "shelves",
277 274
                 "pathos": "portended"
278 275
             };
279  
-            cmp(have, want);
  276
+            Y.TEST_CMP(have, want);
280 277
         },
281 278
 
282 279
 
@@ -303,16 +300,10 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
303 300
             var path = libpath.join(fixtures, 'routes.json');
304 301
             var have = store.config.readConfigYCB(path, {});
305 302
             var want = {};
306  
-            cmp(have, want);
307  
-        }
  303
+            Y.TEST_CMP(have, want);
  304
+        },
308 305
 
309 306
         
310  
-    }));
311  
-    
312  
-    suite.add(new YUITest.TestCase({
313  
-        
314  
-        name: 'config rs addon tests',
315  
-
316 307
         "readConfigSync JSON file":  function () {
317 308
 
318 309
             var fixtures = libpath.join(__dirname, '../../../../../fixtures'),
@@ -327,6 +318,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
327 318
             A.areSame("val", obj.key);
328 319
         },
329 320
 
  321
+
330 322
         "readConfigSync YAML file":  function () {
331 323
 
332 324
             var fixtures = libpath.join(__dirname, '../../../../../fixtures'),
@@ -341,6 +333,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
341 333
             A.areSame("val", obj.key);
342 334
         },
343 335
 
  336
+
344 337
         "readConfigSync YML file":  function () {
345 338
 
346 339
             var fixtures = libpath.join(__dirname, '../../../../../fixtures'),
@@ -355,6 +348,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
355 348
             A.areSame("val", obj.key);
356 349
         },
357 350
 
  351
+
358 352
         "readConfigSync no ext file":  function () {
359 353
 
360 354
             var fixtures = libpath.join(__dirname, '../../../../../fixtures'),
@@ -369,6 +363,7 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
369 363
             A.areSame("val", obj.key);
370 364
         },
371 365
 
  366
+
372 367
         "readConfigSync YAML file with TAB not space":  function () {
373 368
 
374 369
             var fixtures = libpath.join(__dirname, '../../../../../fixtures'),
@@ -383,7 +378,55 @@ YUI().use('addon-rs-config', 'mojito-util', 'base', 'oop', 'test', function(Y) {
383 378
             catch (err) {
384 379
                 A.areSame('Error parsing file:', err.message.substr(0, 19));
385 380
             }
  381
+        },
  382
+
  383
+
  384
+        'create multipart ycb': function () {
  385
+            var fixtures = libpath.join(__dirname, '../../../../../fixtures/app-jsons'),
  386
+                store = new MockRS({ root: fixtures });
  387
+            store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
  388
+
  389
+            var paths, ycb, config;
  390
+            paths = [
  391
+                libpath.join(fixtures, 'application.json'),
  392
+                libpath.join(fixtures, 'node_modules', 'devices', 'application.json'),
  393
+                libpath.join(fixtures, 'node_modules', 'runtimes', 'application.json'),
  394
+            ];
  395
+            ycb = store.config.createMultipartYCB(paths);
  396
+            A.isObject(ycb);
  397
+            config = ycb.read({runtime: 'client'});
  398
+            A.isObject(config);
  399
+            A.areSame('testVal2-client', config.testKey2);
  400
+            config = ycb.read({device: 'android'});
  401
+            A.isObject(config);
  402
+            A.areSame('droid', config.selector);
  403
+
  404
+            // detect non-ycb file
  405
+            paths = [
  406
+                libpath.join(fixtures, 'application.json'),
  407
+                libpath.join(fixtures, 'application-notycb.json')
  408
+            ];
  409
+            ycb = store.config.createMultipartYCB(paths);
  410
+            A.isUndefined(ycb);
  411
+
  412
+            // detect missing settings
  413
+            paths = [
  414
+                libpath.join(fixtures, 'application.json'),
  415
+                libpath.join(fixtures, 'application-nosettings.json')
  416
+            ];
  417
+            ycb = store.config.createMultipartYCB(paths);
  418
+            A.isUndefined(ycb);
  419
+
  420
+            // detect duplicate settings
  421
+            paths = [
  422
+                libpath.join(fixtures, 'application.json'),
  423
+                libpath.join(fixtures, 'application2.json')
  424
+            ];
  425
+            ycb = store.config.createMultipartYCB(paths);
  426
+            A.isUndefined(ycb);
386 427
         }
  428
+
  429
+
387 430
     }));
388 431
     
389 432
     Y.Test.Runner.add(suite);
57  tests/unit/lib/app/addons/rs/test-selector.js
@@ -4,6 +4,7 @@
4 4
  * See the accompanying LICENSE file for terms.
5 5
  */
6 6
 YUI().use(
  7
+    'mojito-test-extra',
7 8
     'base',
8 9
     'oop',
9 10
     'addon-rs-config',
@@ -13,7 +14,9 @@ YUI().use(
13 14
     
14 15
         var suite = new Y.Test.Suite('mojito-addon-rs-selector-tests'),
15 16
             libpath = require('path'),
  17
+            libycb = require('ycb'),
16 18
             mojitoRoot = libpath.join(__dirname, '../../../../../../lib'),
  19
+            fixtures = libpath.join(__dirname, '../../../../../fixtures/store');
17 20
             A = Y.Assert;
18 21
 
19 22
 
@@ -33,6 +36,11 @@ YUI().use(
33 36
                     '*': true
34 37
                 };
35 38
             },
  39
+            getAppConfigYCB: function() {
  40
+                return this.config.createMultipartYCB([
  41
+                    libpath.join(fixtures, 'application.json')
  42
+                ]);
  43
+            },
36 44
             validateContext: function() {},
37 45
             cloneObj: function(o) {
38 46
                 return Y.clone(o);
@@ -40,74 +48,47 @@ YUI().use(
40 48
         });
41 49
 
42 50
 
43  
-        function cmp(x, y, msg, path) {
44  
-            if (Y.Lang.isArray(x)) {
45  
-                A.isArray(x, msg || 'first arg should be an array');
46  
-                A.isArray(y, msg || 'second arg should be an array');
47  
-                A.areSame(x.length, y.length, msg || 'arrays are different lengths');
48  
-                for (var i = 0; i < x.length; i += 1) {
49  
-                    cmp(x[i], y[i], msg);
50  
-                }
51  
-                return;
52  
-            }
53  
-            if (Y.Lang.isObject(x)) {
54  
-                A.isObject(x, msg || 'first arg should be an object');
55  
-                A.isObject(y, msg || 'second arg should be an object');
56  
-                A.areSame(Object.keys(x).length, Object.keys(y).length, msg || 'object keys are different lengths');
57  
-                for (var i in x) {
58  
-                    if (x.hasOwnProperty(i)) {
59  
-                        cmp(x[i], y[i], msg);
60  
-                    }
61  
-                }
62  
-                return;
63  
-            }
64  
-            A.areSame(x, y, msg || 'args should be the same');
65  
-        }
66  
-
67  
-
68 51
         suite.add(new Y.Test.Case({
69 52
 
70 53
             name: 'selector rs addon tests',
71 54
 
72 55
             'read dimensions': function() {
73 56
                 // from mojito
74  
-                var fixtures = libpath.join(__dirname, '../../../../../fixtures/store');
75 57
                 var store = new MockRS({ root: fixtures });
76 58
                 store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
77 59
                 store.plug(Y.mojito.addons.rs.selector, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
78 60
 
79 61
                 var have = store.selector.getPOSLFromContext({});
80 62
                 var want = ['*'];
81  
-                cmp(have, want);
  63
+                Y.TEST_CMP(have, want);
82 64
 
83 65
                 var have = store.selector.getPOSLFromContext({runtime:'client'});
84 66
                 var want = ['right', '*'];
85  
-                cmp(have, want);
  67
+                Y.TEST_CMP(have, want);
86 68
 
87 69
                 var have = store.selector.getPOSLFromContext({runtime:'server'});
88 70
                 var want = ['shelves', '*'];
89  
-                cmp(have, want);
  71
+                Y.TEST_CMP(have, want);
90 72
 
91 73
                 var have = store.selector.getPOSLFromContext({device:'android'});
92 74
                 var want = ['droid', '*'];
93  
-                cmp(have, want);
  75
+                Y.TEST_CMP(have, want);
94 76
 
95 77
                 var have = store.selector.getPOSLFromContext({runtime:'server', device:'android'});
96 78
                 var want = ['shelves', 'droid', '*'];
97  
-                cmp(have, want);
  79
+                Y.TEST_CMP(have, want);
98 80
 
99 81
                 var have = store.selector.getPOSLFromContext({device:'android', environment:'dev'});
100 82
                 var want = ['devdroid', 'droid', '*'];
101  
-                cmp(have, want);
  83
+                Y.TEST_CMP(have, want);
102 84
 
103 85
                 var have = store.selector.getPOSLFromContext({runtime:'server', device:'android', environment:'dev'});
104 86
                 var want = ['shelves', 'devdroid', 'droid', '*'];
105  
-                cmp(have, want);
  87
+                Y.TEST_CMP(have, want);
106 88
             },
107 89
 
108 90
 
109 91
             'get all posls': function() {
110  
-                var fixtures = libpath.join(__dirname, '../../../../../fixtures/store');
111 92
                 var store = new MockRS({ root: fixtures });
112 93
                 store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
113 94
                 store.plug(Y.mojito.addons.rs.selector, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
@@ -121,12 +102,11 @@ YUI().use(
121 102
                     [ 'right', 'devdroid', 'droid', '*' ],
122 103
                     [ 'right', 'droid', '*' ]
123 104
                 ];
124  
-                cmp(want, have);
  105
+                Y.TEST_CMP(want, have);
125 106
             },
126 107
 
127 108
 
128 109
             'list used dimensions': function() {
129  
-                var fixtures = libpath.join(__dirname, '../../../../../fixtures/store');
130 110
                 var store = new MockRS({ root: fixtures });
131 111
                 store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
132 112
                 store.plug(Y.mojito.addons.rs.selector, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
@@ -137,12 +117,11 @@ YUI().use(
137 117
                     device: ['iphone', 'android'],
138 118
                     environment: ['dev']
139 119
                 }
140  
-                cmp(want, have);
  120
+                Y.TEST_CMP(want, have);
141 121
             },
142 122
 
143 123
 
144 124
             'list used contexts': function() {
145  
-                var fixtures = libpath.join(__dirname, '../../../../../fixtures/store');
146 125
                 var store = new MockRS({ root: fixtures });
147 126
                 store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
148 127
                 store.plug(Y.mojito.addons.rs.selector, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
@@ -162,7 +141,7 @@ YUI().use(
162 141
                     { runtime: 'client', environment: 'dev' },
163 142
                     { runtime: 'client' }
164 143
                 ];
165  
-                cmp(want, have);
  144
+                Y.TEST_CMP(want, have);
166 145
             }
167 146
 
168 147
 
27  tests/unit/lib/app/autoload/test-store.server.js
@@ -5,6 +5,7 @@
5 5
  */
6 6
 YUI().use(
7 7
     'oop',
  8
+    'mojito-test-extra',
8 9
     'mojito-resource-store',
9 10
     'addon-rs-config',
10 11
     'addon-rs-selector',
@@ -23,30 +24,6 @@ YUI().use(
23 24
             OA = Y.ObjectAssert;
24 25
 
25 26
 
26  
-        function cmp(x, y, msg) {
27  
-            if (Y.Lang.isArray(x)) {
28  
-                A.isArray(x, msg || 'first arg should be an array');
29  
-                A.isArray(y, msg || 'second arg should be an array');
30  
-                A.areSame(x.length, y.length, msg || 'arrays are different lengths');
31  
-                for (var i = 0; i < x.length; i += 1) {
32  
-                    cmp(x[i], y[i], msg);
33  
-                }
34  
-                return;
35  
-            }
36  
-            if (Y.Lang.isObject(x)) {
37  
-                A.isObject(x, msg || 'first arg should be an object');
38  
-                A.isObject(y, msg || 'second arg should be an object');
39  
-                A.areSame(Object.keys(x).length, Object.keys(y).length, msg || 'object keys are different lengths');
40  
-                for (var i in x) {
41  
-                    if (x.hasOwnProperty(i)) {
42  
-                        cmp(x[i], y[i], msg);
43  
-                    }
44  
-                }
45  
-                return;
46  
-            }
47  
-            A.areSame(x, y, msg || 'args should be the same');
48  
-        }
49  
-
50 27
         suite.add(new Y.Test.Case({
51 28
 
52 29
             name: 'Store tests -- preload fixture "store"',
@@ -294,7 +271,7 @@ YUI().use(
294 271
                     appResources: Y.clone(store._appResources, true),
295 272
                     mojitResources: Y.clone(store._mojitResources, true)
296 273
                 };
297  
-                cmp(post, pre);
  274
+                Y.TEST_CMP(post, pre);
298 275
             },
299 276
 
300 277
             'instance with base pointing to non-existant spec': function() {

0 notes on commit d1390d7

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