6643N/A#!/usr/bin/env node
6643N/A
6643N/Avar fs = require('fs'),
6643N/A path = require('path'),
6643N/A mods = {};
6643N/A
6643N/Avar json = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'js') + '/yui3.json'));
6643N/A
6643N/Avar wrapper = fs.readFileSync(__dirname + '/loader_template.js', 'utf8');
6643N/A
6643N/Avar testMod = function(v) {
6643N/A //Removes YUI core modules
6643N/A if ((v.indexOf('yui') === -1) && (v.indexOf('loader') !== 0) &&
6643N/A (v.indexOf('css') === -1) && (v !== 'queue-run') && (v !== 'features') && (v !== 'get') &&
6643N/A (v !== 'intl-base')) {
6643N/A return true;
6643N/A }
6643N/A return false;
6643N/A}
6643N/A
6643N/AObject.keys(json).forEach(function(v) {
6643N/A if (testMod(v)) { //Removes YUI core modules
6643N/A mods[v] = json[v];
6643N/A if (json[v].submodules) {
6643N/A Object.keys(json[v].submodules).forEach(function(k) {
6643N/A if (testMod(k)) { //Removes YUI core modules
6643N/A mods[k] = json[v].submodules[k];
6643N/A }
6643N/A });
6643N/A }
6643N/A }
6643N/A});
6643N/A
6643N/Avar writeTest = function(key, mod) {
6643N/A var str = ' "Testing ' + key + '": function(data) {\n';
6643N/A str += ' var loader = new Y.Loader({\n';
6643N/A str += ' require: ["' + key + '"],\n';
6643N/A str += ' ignoreRegistered: true,\n';
6643N/A str += ' allowRollup: false\n';
6643N/A str += ' });\n';
6643N/A str += ' loader.calculate();\n';
6643N/A if (mod.use) {
6643N/A str += ' //Testing A rollup module\n';
6643N/A mod.use.forEach(function(s) {
6643N/A if (mods[s] && mods[s].use) {
6643N/A str += ' //Testing A rollup of a rollup module ( datatype )\n';
6643N/A mods[s].use.forEach(function(s) {
6643N/A str += ' Assert.isTrue((loader.sorted.indexOf("' + s + '")) > -1, "Module (' + s + ') not found in sorted array");\n';
6643N/A });
6643N/A } else {
6643N/A str += ' Assert.isTrue((loader.sorted.indexOf("' + s + '")) > -1, "Module (' + s + ') not found in sorted array");\n';
6643N/A }
6643N/A });
6643N/A } else {
6643N/A str += ' //Testing A normal module\n';
6643N/A str += ' Assert.isTrue((loader.sorted.indexOf("' + key + '")) > -1, "Module (' + key + ') not found in sorted array");\n';
6643N/A }
6643N/A str += ' }';
6643N/A return str;
6643N/A};
6643N/A
6643N/Avar tests = [];
6643N/A
6643N/AObject.keys(mods).forEach(function(k) {
6643N/A tests.push(writeTest(k, mods[k]));
6643N/A});
6643N/A
6643N/Avar str = '{\n';
6643N/Astr += ' name: "Loader Tests",\n';
6643N/Astr += ' ' + tests.join(',\n'),
6643N/Astr += ' \n}';
6643N/A
6643N/Awrapper = wrapper.replace('!!TESTCASE!!', str);
6643N/A
6643N/Afs.writeFileSync(path.join(__dirname, '../', 'tests/cli') + '/loader.js', wrapper);
console.log(Object.keys(mods).length + ' tests written to: ./tests/cli/loader.js');