loader-tests.js revision fe3e9cc499cae1f5b989a36d993c60518e9ec89c
var jsFailure = !((ua.ie && ua.ie < 9) || (ua.opera && ua.opera < 11.6) || (ua.webkit && ua.webkit < 530.17));
name: "Loader Tests",
_should: {
ignore: {
'test_failure': !jsFailure,
'test_timeout': !jsFailure
}
},
test_resolve_no_calc: function() {
ignoreRegistered: true,
});
},
test_resolve_manual_calc: function() {
ignoreRegistered: true,
});
},
test_resolve_auto_calc: function() {
ignoreRegistered: true,
});
},
test_resolve_combo: function() {
combine: true,
ignoreRegistered: true,
});
},
test_resolve_filter_debug: function() {
filter: 'debug',
combine: true,
ignoreRegistered: true,
});
},
test_resolve_filter_min: function() {
filter: 'min',
combine: true,
ignoreRegistered: true,
});
},
test_resolve_filter_raw: function() {
filter: 'raw',
combine: true,
ignoreRegistered: true,
});
},
test_custom_filter: function() {
filter: {
searchExp: 'JS&',
replaceStr: 'js+'
},
groups: {
mods: {
root: '',
base: '',
combine: true,
modules: {
'mods-actioninfos': {
},
'mods-test': {
}
}
}
},
});
Assert.areEqual('http://test.com/?actioninfos/actioninfos.js+test/test.JS', out.js[0], 'Failed to replace string in combo');
},
test_custom_filter_group: function() {
groups: {
mods: {
filter: {
searchExp: 'JS&',
replaceStr: 'js+'
},
root: '',
base: '',
combine: true,
modules: {
'mods-actioninfos': {
},
'mods-test': {
}
}
}
},
});
Assert.areEqual('http://test.com/?actioninfos/actioninfos.js+test/test.JS', out.js[0], 'Failed to replace string in combo');
},
test_resolve_combo_sep: function() {
comboSep: '==!!==',
combine: true,
ignoreRegistered: true,
});
},
test_resolve_combo_sep_group: function() {
comboSep: '==!!==',
combine: true,
ignoreRegistered: true,
require: ['foo'],
groups: {
extra: {
combine: true,
comboSep: '==;;==',
root: '',
base: '',
modules: {
foo: {
},
bar: {
requires: ['dd']
}
}
}
}
});
Assert.isTrue((out.js[out.js.length - 1].indexOf('==!!==') === -1), 'Group comboSep contains Main comboSep');
},
test_resolve_maxurl_length: function() {
maxURLLength: 1024,
combine: true,
ignoreRegistered: true,
});
},
test_resolve_maxurl_length_higher: function() {
maxURLLength: 8024,
combine: true,
ignoreRegistered: true,
});
},
test_resolve_maxurl_length_too_low: function() {
maxURLLength: 14,
combine: true,
ignoreRegistered: true,
require: ['oop']
});
},
test_resolve_maxurl_length_group: function() {
combine: true,
ignoreRegistered: true,
require: ['foo'],
groups: {
extra: {
combine: true,
maxURLLength: 45,
root: '',
base: '',
modules: {
foo: {
},
bar: {
requires: ['dd']
}
}
}
}
});
},
test_resolve_filters: function() {
combine: true,
ignoreRegistered: true,
});
},
test_group_filters: function() {
var test = this;
YUI({
debug: true,
filter: 'DEBUG',
groups: {
local: {
filter: 'raw',
combine: false,
base: './assets/',
modules: {
foo: {
requires: [ 'oop' ]
}
}
}
}
}).use('foo', function(Y) {
});
});
},
test_module_attrs: function() {
var test = this;
YUI({
modules: {
'attrs-js': {
attributes: {
id: 'attrs-js-test'
}
},
'attrs-css': {
type: 'css',
attributes: {
id: 'attrs-css-test'
}
}
}
});
});
},
test_global_attrs: function() {
var test = this;
YUI({
'class': 'yui-css-module'
},
jsAttributes: {
'class': 'yui-js-module'
},
modules: {
'attrs2-js': {
},
'attrs2-css': {
}
}
});
});
},
test_iter: function() {
var test = this;
YUI({
filter: 'debug',
gallery: 'gallery-2010.08.04-19-46',
'2in3': '4',
'yui2': '2.9.0'
Y.LOADED = true;
});
YUI({
filter: 'debug',
gallery: 'gallery-2010.08.04-19-46',
'2in3': '4',
'yui2': '2.9.0'
Y.LOADED = true;
});
});
},
test_progress: function() {
var test = this,
counter = 0;
YUI({
'2in3': '4',
'yui2': '2.9.0',
onSuccess: function(e) {
},
onProgress: function(e) {
proContext = this;
counter++;
}
},
Y.LOADED = true;
});
});
},
test_failure: function() {
var test = this,
fMsg;
YUI({
onFailure: function(e) {
fMsg = e;
},
modules: {
'bogus-module': {
}
}
}).use('bogus-module', function(Y) {
var e = fMsg;
});
});
},
test_timeout: function() {
var test = this,
fMsg;
YUI({
timeout: 1,
onTimeout: function(e) {
},
modules: {
'bogus-module': {
}
}
}).use('bogus-module', function(Y) {
});
},
test_condpattern: function() {
var test = this;
YUI({
groups: {
testpatterns: {
patterns: {
modtest: {
return (mname === 'mod')
},
}
}
}
}
}
}).use('mod', function(Y) {
});
});
},
test_cond_with_test_function: function() {
var test = this;
YUI({
modules: {
cond2: {
condition: {
trigger: 'jsonp',
test: function() {
return true;
}
}
}
}
}).use('jsonp', function(Y) {
});
});
},
test_cond_no_test_or_ua: function() {
var test = this;
YUI({
modules: {
cond: {
condition: {
trigger: 'yql'
}
}
}
}).use('yql', function(Y) {
});
});
},
test_css_stamp: function() {
var test = this,
links = document.getElementsByTagName('link').length + document.getElementsByTagName('style').length;
var links2 = document.getElementsByTagName('link').length + document.getElementsByTagName('style').length;
});
});
},
test_forcemap: function() {
var test = this;
ignoreRegistered: true,
force : ['yui-base'],
require : ['json']
});
},
test_global_mods: function() {
var conf = {
combine: false,
require: ['widget-base'],
ignoreRegistered: true // force loader to include modules already on the page
},
Assert.areEqual(mods1.css.length, mods2.css.length, 'CSS Modules are not equal in 2 loader instances');
},
test_skin_default: function() {
Assert.areSame(loader.skin.defaultSkin, Y.Env.meta.skin.defaultSkin, 'Default skin was not set from default');
},
test_skin_string: function() {
skin: 'night'
});
},
test_skin_object: function() {
skin: {
defaultSkin: 'foobar'
}
});
},
test_skin_overrides: function() {
skin: {
overrides: {
slider: [
'sam',
'sam-dark',
'round',
'round-dark',
'capsule',
'capsule-dark',
'audio',
'audio-light'
]
}
},
require: [ 'slider' ]
});
Assert.areSame(loader.skin.overrides.slider.length, out.css.length, 'Failed to load all override skins');
},
test_load_optional: function() {
loadOptional: true,
ignoreRegistered: true,
require: [ 'dd-plugin' ]
});
var hasOptional = false;
hasOptional = true;
}
});
},
test_load_css_without_type: function() {
combine: false,
ignoreRegistered: true,
modules: {
somecss: {
}
},
require: [ 'somecss' ]
});
},
test_load_as_string: function() {
combine: false,
ignoreRegistered: true,
modules: {
},
});
},
test_combine_no_core_top_level: function() {
/*
I don't like this test, it's not EXACTLY how I would do it..
This assumes that anything in the top level modules config
is to not obey the combine parameter unless the module def
contains the combine flag.
Maybe this needs a new flag for combineTopLevel: true or something
so that Loader can work stand-alone.
*/
root: '',
base: '',
combine: true,
modules: {
foobar: {
combine: true,
type: 'js',
},
},
});
Assert.areSame('http://foobar.com/combo?foo/foo.js', out.js[2], 'Failed to combine manual JS file properly');
},
test_combine_no_core_group: function() {
groups: {
local: {
root: '',
base: '',
combine: true,
modules: {
foobar: {
type: 'js',
},
baz: {
},
bar: {
},
somecss: {
}
}
}
},
});
Assert.areSame('http://foobar.com/combo?bar.js&path/to/baz.js&foo/foo.js', out.js[0], 'Failed to combine JS files properly');
Assert.areSame('http://foobar.com/combo?my/css/files.css', out.css[0], 'Failed to combine CSS files properly');
},
test_outside_group: function() {
combine: true,
ignoreRegistered: true,
require: [ 'gallery-calendar' ],
groups: {
mygallery: {
base:'./js/yui-library/',
combine:true,
comboBase: '/yui/?',
root:'yui-library/',
modules: {
'gallery-calendar':{
}
}
},
outside: {
combine:false,
modules:{
'calendar-skin': {
fullpath: '/css/calendar-skin.css',
type:'css'
}
}
}
}
});
},
test_outside_nocombine: function() {
combine: false,
ignoreRegistered: true,
require: [ 'gallery-calendar' ],
groups: {
mygallery: {
base:'./js/yui-library/',
combine:true,
comboBase: '/yui/?',
root:'yui-library/',
modules: {
'gallery-calendar':{
requires: [ 'gallery-calendar2' ]
},
'gallery-calendar2':{
requires: [ 'gallery-calendar3' ]
},
'gallery-calendar3':{
}
}
}
}
});
},
test_submodules: function() {
ignoreRegistered: true,
combine: false,
root: '',
base: '',
filter: 'raw',
modules: {
sub1: {
submodules: {
subsub1: {
},
subsub2: {
lang: 'en',
skinnable: true
}
}
}
},
require: [ 'subsub2' ]
});
Assert.areSame('sub1/lang/subsub2.js', out.js[0], 'Failed to combine submodule with module path for LANG JS');
Assert.areSame('sub1/assets/skins/sam/subsub2.css', out.css[0], 'Failed to combine submodule with module path CSS');
},
test_plugins: function() {
ignoreRegistered: true,
combine: false,
root: '',
base: '',
filter: 'raw',
modules: {
plug1: {
plugins: {
subplug1: {
lang: 'en',
skinnable: true
},
subplug2: {
lang: 'en',
skinnable: true,
requires: [ 'subplug1' ]
}
}
}
},
require: [ 'subplug2' ]
});
Assert.areSame('plug1/lang/subplug2.js', out.js[0], 'Failed to combine plugin with module path LANG JS');
Assert.areSame('plug1/lang/subplug1.js', out.js[1], 'Failed to combine plugin with module path LANG JS');
Assert.areSame('plug1/assets/skins/sam/subplug1.css', out.css[0], 'Failed to combine plugin with module path CSS');
Assert.areSame('plug1/assets/skins/sam/subplug2.css', out.css[1], 'Failed to combine plugin with module path CSS');
},
test_fullpath_with_combine: function() {
ignoreRegistered: true,
combine: true,
root: '',
base: '',
groups: {
test: {
combine: true,
modules: {
"fullpath-module": {
combine: false,
}
}
}
},
});
Assert.areEqual(out.js[0], 'http://ryancannon.com/bugs/fullpath/fullpath.js', 'Failed to return proper full path url');
Assert.areEqual(out.js[1], 'http://my.combo.server.com/?yui-base/yui-base-min.js&oop/oop-min.js', 'Failed to return proper full path url');
}
});
});