Skip to content

Commit

Permalink
Rearranging some Tests for Node.js testing
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Apr 20, 2012
1 parent c55726d commit 8350852
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/yui/tests/assets/mod.js
@@ -1,5 +1,5 @@
YUI.add('mod', function(Y) {
Y.MOD = true;
}, '', {
requires: [ 'node', 'yql' ]
requires: [ 'yql' ]
});
32 changes: 32 additions & 0 deletions src/yui/tests/browser-tests.js
@@ -0,0 +1,32 @@
YUI.add('browser-tests', function(Y) {

var suite = new Y.Test.Suite('Core Browser Tests');

suite.add(new Y.Test.Case({
test_attach_after: function() {
var Assert = Y.Assert;
YUI.add('after-test', function(Y) {
Y.afterTest = true;
Assert.isObject(Y.Node, 'Node not loaded before this module');
}, '1.0.0', {
after: [ 'node' ]
});

YUI().use('after-test', function(Y2) {
Assert.isTrue(Y2.afterTest, 'after-test module was not loaded');
});
},
test_rollup_false: function() {
var Assert = Y.Assert;
YUI().use('dd', function(Y) {
Assert.isUndefined(Y.Env._attached.dd, 'DD Alias Module was attached');
});
YUI().use('node', function(Y) {
Assert.isUndefined(Y.Env._attached.node, 'Node Alias Module was attached');
});
}
});

Y.Test.Runner.add(suite);

});
32 changes: 26 additions & 6 deletions src/yui/tests/config-test.js
@@ -1,17 +1,37 @@
YUI.add('config-test', function(Y) {


var testCore = new Y.Test.Case({

name: "Config tests",

test_config: function() {
_should: {
error: {
'test: YUI_config': (Y.UA.nodejs ? true : false)
}
},

'test: YUI_config': function() {
Y.Assert.isObject(YUI_config);
Y.Assert.areEqual(YUI_config.gfilter, Y.config.filter);
Y.Assert.isObject(Y.config.logExclude);
Y.Assert.isTrue(Y.config.gconfig);
YUI().use('node', function(Y2) {

YUI().use('oop', function(Y2) {
Y.Assert.isUndefined(Y2.config.logExclude);
Y.Assert.isUndefined(Y2.config.filter);
Y.Assert.isTrue(Y2.config.gconfig);
});
},

'test: local config': function() {
Y.Assert.isObject(Y.config.logExclude);
},

test_config: function() {
YUI().use('oop', function(Y2) {
Y.Assert.isUndefined(Y2.config.logExclude);
Y.Assert.isUndefined(Y2.config.filter);
Y.Assert.isTrue(Y2.config.globalConfig);
});

var o1 = { a: 1 };
var o2 = { b: 1 };
Expand All @@ -20,9 +40,9 @@ YUI.add('config-test', function(Y) {
var o5 = { e: 1 };
var o6 = { f: 1 };

YUI(o1, o2, o3, o4, o5, o6).use('node', function(Y2) {
YUI(o1, o2, o3, o4, o5, o6).use('oop', function(Y2) {
Y.Assert.areEqual(1, Y2.config.f);
Y.Assert.isTrue(Y2.config.gconfig);
Y.Assert.isTrue(Y2.config.globalConfig);
});
}
});
Expand Down
92 changes: 41 additions & 51 deletions src/yui/tests/core-tests.js
Expand Up @@ -34,6 +34,17 @@ YUI.add('core-tests', function(Y) {
};
/* }}} */

YUI.GlobalConfig = YUI.GlobalConfig || {};
YUI.GlobalConfig.useSync = true;

var resolvePath = function(p) {
if (Y.UA.nodejs) {
var path = require('path');
p = path.join(__dirname, p);
}
return p;
};

var testCore = new Y.Test.Case({

name: "Core tests",
Expand All @@ -43,8 +54,9 @@ YUI.add('core-tests', function(Y) {
test_attach_error_errFn: true
},
ignore: {
'getLocation() should return the location object': Y.UA.nodejs,
'getLocation() should return `undefined` when executing in node.js': (!Y.UA.nodejs || (Y.UA.nodejs && Y.config.win)) //If there is a window object, ignore too
'getLocation() should return the location object': (Y.UA.nodejs ? true : false),
'getLocation() should return `null` when executing in node.js': (!Y.UA.nodejs || (Y.UA.nodejs && Y.config.win)), //If there is a window object, ignore too
test_log_params: (typeof console == "undefined" || !console.info || Y.UA.nodejs)
}
},

Expand Down Expand Up @@ -110,8 +122,8 @@ YUI.add('core-tests', function(Y) {
Y.Assert.areSame(Y.config.win.location, Y.getLocation(), 'Did not return Y.config.win.location.');
},

'getLocation() should return `undefined` when executing in node.js': function () {
Y.Assert.isUndefined(Y.getLocation(), 'Did not return `undefined`');
'getLocation() should return `null` when executing in node.js': function () {
Y.Assert.isNull(Y.getLocation(), 'Did not return `null`');
},

test_cached_undefined_null: function() {
Expand Down Expand Up @@ -158,16 +170,16 @@ YUI.add('core-tests', function(Y) {
},
test_use_array: function() {
var Assert = Y.Assert;
YUI().use(['dd', 'node'], function(Y) {
Assert.isObject(Y.DD, 'DD was not loaded');
Assert.isObject(Y.Node, 'Node was not loaded');
YUI().use(['yui-throttle', 'oop'], function(Y) {
Assert.isObject(Y.throttle, 'Throttle was not loaded');
Assert.isObject(Y.each, 'OOP was not loaded');
});
},
test_use_strings: function() {
var Assert = Y.Assert;
YUI().use('dd', 'node', function(Y) {
Assert.isObject(Y.DD, 'DD was not loaded');
Assert.isObject(Y.Node, 'Node was not loaded');
YUI().use('yui-throttle', 'oop', function(Y) {
Assert.isObject(Y.throttle, 'Throttle was not loaded');
Assert.isObject(Y.each, 'OOP was not loaded');
});
},
test_one_submodule: function() {
Expand All @@ -177,7 +189,7 @@ YUI.add('core-tests', function(Y) {
'something':{
'submodules':{
'something1':{
fullpath: './assets/sub.js'
fullpath: resolvePath('./assets/sub.js')
}
}
}
Expand All @@ -186,15 +198,6 @@ YUI.add('core-tests', function(Y) {
Assert.isTrue(Y.something1);
});
},
test_rollup_false: function() {
var Assert = Y.Assert;
YUI().use('dd', function(Y) {
Assert.isUndefined(Y.Env._attached.dd, 'DD Alias Module was attached');
});
YUI().use('node', function(Y) {
Assert.isUndefined(Y.Env._attached.node, 'Node Alias Module was attached');
});
},
test_base_path: function() {
var Assert = Y.Assert;
for (var i in core_urls) {
Expand Down Expand Up @@ -253,15 +256,15 @@ YUI.add('core-tests', function(Y) {
YUI.applyConfig({
modules: {
davglass: {
fullpath: './assets/davglass.js'
fullpath: resolvePath('./assets/davglass.js')
}
}
});

YUI.applyConfig({
modules: {
foo: {
fullpath: './assets/foo.js'
fullpath: resolvePath('./assets/foo.js')
}
}
});
Expand Down Expand Up @@ -306,7 +309,7 @@ YUI.add('core-tests', function(Y) {
var Assert = Y.Assert,
test = this;

YUI().use('global-mod', function(Y) {
YUI({useSync: false }).use('global-mod', function(Y) {
test.resume(function() {
Assert.isTrue(Y.GlobalMod, 'Module in global config failed to load');
});
Expand Down Expand Up @@ -380,10 +383,10 @@ YUI.add('core-tests', function(Y) {

},
test_attach_error: function() {
/*
As of 3.6.0 this should now throw an error as the default
setting throwFail: false will supress the error #2531679
*/
//
// As of 3.6.0 this should now throw an error as the default
// setting throwFail: false will supress the error #2531679
//
var Assert = Y.Assert;
YUI.add('attach-error', function() { Y.push(); });

Expand All @@ -395,10 +398,10 @@ YUI.add('core-tests', function(Y) {
}).use('attach-error');
},
test_attach_error_silent: function() {
/*
As of 3.6.0 this should NOT throw an error as
setting throwFail: false will supress the error #2531679
*/
//
// As of 3.6.0 this should NOT throw an error as
// setting throwFail: false will supress the error #2531679
//
var Assert = Y.Assert;
YUI.add('attach-error', function() { Y.push(); });

Expand All @@ -411,11 +414,11 @@ YUI.add('core-tests', function(Y) {
}).use('attach-error');
},
test_attach_error_errFn: function() {
/*
As of 3.6.0 this should throw an error as
setting throwFail: false will supress the error and
errorFn returns false see #2531679
*/
//
// As of 3.6.0 this should throw an error as
// setting throwFail: false will supress the error and
// errorFn returns false see #2531679
//
var Assert = Y.Assert;
YUI.add('attach-error', function() { Y.push(); });

Expand All @@ -427,19 +430,6 @@ YUI.add('core-tests', function(Y) {
}
}).use('attach-error');
},
test_attach_after: function() {
var Assert = Y.Assert;
YUI.add('after-test', function(Y) {
Y.afterTest = true;
Assert.isObject(Y.Node, 'Node not loaded before this module');
}, '1.0.0', {
after: [ 'node' ]
});

YUI().use('after-test', function(Y2) {
Assert.isTrue(Y2.afterTest, 'after-test module was not loaded');
});
},
test_dump_core: function() {
var Assert = Y.Assert,
o = {},
Expand Down Expand Up @@ -470,15 +460,15 @@ YUI.add('core-tests', function(Y) {
Assert = Y.Assert;

YUI({
useSync: false,
modules: {
mod: {
fullpath: './assets/mod.js'
fullpath: resolvePath('./assets/mod.js')
}
}
}).use('mod', function(Y) {
test.resume(function() {
Assert.isTrue(Y.MOD, 'Failed to load external mod');
Assert.isObject(Y.Node, 'Failed to load Node requirement');
Assert.isObject(Y.YQL, 'Failed to load YQL requirement');
});
});
Expand Down
4 changes: 4 additions & 0 deletions src/yui/tests/index-automated.html
Expand Up @@ -41,6 +41,7 @@
<script type="text/javascript">

YUI.GlobalConfig = {
globalConfig: true,
modules: {
'global-mod': {
fullpath: './assets/globalmod.js'
Expand Down Expand Up @@ -100,6 +101,9 @@
'later-test': {
fullpath: 'later-test.js'
},
'browser-tests': {
fullpath: 'browser-tests.js'
},

'namespace-test': {
fullpath: 'namespace-test.js'
Expand Down
4 changes: 4 additions & 0 deletions src/yui/tests/index-coverage.html
Expand Up @@ -41,6 +41,7 @@
<script type="text/javascript">

YUI.GlobalConfig = {
globalConfig: true,
modules: {
'global-mod': {
fullpath: './assets/globalmod.js'
Expand Down Expand Up @@ -99,6 +100,9 @@
fullpath: 'later-test.js'
},

'browser-tests': {
fullpath: 'browser-tests.js'
},
'namespace-test': {
fullpath: 'namespace-test.js'
},
Expand Down
4 changes: 4 additions & 0 deletions src/yui/tests/index-full.html
Expand Up @@ -12,6 +12,7 @@
<script type="text/javascript">

YUI.GlobalConfig = {
globalConfig: true,
modules: {
'global-mod': {
fullpath: './assets/globalmod.js'
Expand All @@ -35,6 +36,9 @@
fullpath: './seed-tests.js',
requires: [ 'test']
},
'browser-tests': {
fullpath: 'browser-tests.js'
},
'core-tests': {
fullpath: './core-tests.js',
requires: [ 'classnamemanager']
Expand Down
4 changes: 4 additions & 0 deletions src/yui/tests/index-loader.html
Expand Up @@ -13,6 +13,7 @@
<script type="text/javascript">

YUI.GlobalConfig = {
globalConfig: true,
modules: {
'global-mod': {
fullpath: './assets/globalmod.js'
Expand All @@ -36,6 +37,9 @@
fullpath: './seed-tests.js',
requires: [ 'test']
},
'browser-tests': {
fullpath: 'browser-tests.js'
},
'core-tests': {
fullpath: './core-tests.js',
requires: [ 'classnamemanager']
Expand Down
4 changes: 4 additions & 0 deletions src/yui/tests/index.html
Expand Up @@ -17,6 +17,7 @@
<script type="text/javascript">

YUI.GlobalConfig = {
globalConfig: true,
modules: {
'global-mod': {
fullpath: './assets/globalmod.js'
Expand Down Expand Up @@ -62,6 +63,9 @@
fullpath: 'later-test.js'
},

'browser-tests': {
fullpath: 'browser-tests.js'
},
'namespace-test': {
fullpath: 'namespace-test.js'
}
Expand Down
6 changes: 6 additions & 0 deletions src/yui/tests/later-test.js
Expand Up @@ -3,6 +3,12 @@ YUI.add('later-test', function(Y) {
Y.SeedTests.add(new Y.Test.Case({

name: "Later tests",
_should: {
ignore: {
"test later(10, null, callback)": (Y.UA.nodejs ? true : false),
"test later(10, null, callback, null, true)": (Y.UA.nodejs ? true : false)
}
},

"test later(10, null, callback)": function() {
var test = this,
Expand Down

0 comments on commit 8350852

Please sign in to comment.