Permalink
Browse files

Add support for custom YUI configuration so that custom YUI modules c…

…an be tested
  • Loading branch information...
1 parent 54f3d1c commit bea4ae1bf90e1a1db341c3c95ca3759f0dff5295 @gotwarlost committed Dec 7, 2012
View
11 examples/yui3-custom-modules/lib/foo.js
@@ -0,0 +1,11 @@
+YUI.add('foo', function (Y) {
+
+ var secret = 'foobar';
+
+ Y.namespace('Foo').Whisper = {
+ getSecret: function () {
+ return secret;
+ }
+ };
+
+}, '0.0.1', {});
View
20 examples/yui3-custom-modules/package.json
@@ -0,0 +1,20 @@
+{
+ "author": "Krishnan Anantheswaran <kananthmail-github@yahoo.com>",
+ "name": "yui3-test-custom-sample",
+ "description": "Sample project to test yui3 embedded runner with custom YUI modules",
+ "version": "0.0.1",
+ "repository": {
+ "url": ""
+ },
+ "scripts": {
+ "test": "ytestrunner --yui3 -c --yconfig test/config.json"
+ },
+ "engines": {
+ "node": ">0.4.12"
+ },
+ "dependencies": {},
+ "devDependencies": {
+ "yui": "*",
+ "ytestrunner": "*"
+ }
+}
View
5 examples/yui3-custom-modules/test/config.json
@@ -0,0 +1,5 @@
+{
+ "modules": {
+ "foo": "lib/foo.js"
+ }
+}
View
19 examples/yui3-custom-modules/test/foo-test.js
@@ -0,0 +1,19 @@
+YUI.add('foo-test', function (Y, NAME) {
+
+ var util = require('util');
+ //util.puts(util.inspect(Y, undefined, 10));
+ var whisper = Y.Foo.Whisper,
+ suite = new Y.Test.Suite(NAME),
+ A = Y.Assert;
+
+ suite.add(new Y.Test.Case({
+ 'test my module': function () {
+ A.areEqual('foobar', whisper.getSecret());
+ }
+ }));
+
+ Y.Test.Runner.add(suite);
+
+}, '0.0.1', { requires: ['test', 'foo'] });
+
+
View
2 lib/cli.js
@@ -104,6 +104,7 @@ function usage() {
values: [
{ name: 'root', arg: 'dir', desc: 'the source root', defaultValue : '.' },
{ name: 'yui3', desc: 'flag that enables the YUI3 test harness rather than the YUITest harness' },
+ { name: 'yconfig', arg: 'file', desc: 'A JSON/ JS file that will be `require`d by the YUI3 test runner. The output of the require will be assumed to be a YUI configuration that is applied to the YUI instance' },
{ name: 'verbose', alias: '-v', desc: 'run tests and instrumentation in verbose mode' },
{ name: 'help', alias: '-h', desc: 'print this message' },
{ name: 'tmp', arg: 'dir', desc: 'tmp directory under which instrumented files will be written', defaultValue: '/tmp' },
@@ -188,6 +189,7 @@ function getOptions(args) {
verbose: Boolean,
help: Boolean,
colors: Boolean,
+ yconfig: path,
init: path,
include: [ Array, String ],
View
14 lib/yui3-test-runner.js
@@ -56,6 +56,7 @@ function Yui3TestRunner(options) {
BaseTestRunner.apply(this, arguments);
this.moduleNames = [];
this.seenModules = {};
+ this.yconfig = options.yconfig;
}
util.inherits(Yui3TestRunner, BaseTestRunner);
@@ -66,7 +67,17 @@ util.inherits(Yui3TestRunner, BaseTestRunner);
* @protected
*/
Yui3TestRunner.prototype.init = function () {
+ var configObject = {};
loadYUI(this.testLibPath);
+ if (this.yconfig) {
+ try {
+ configObject = require(this.yconfig);
+ } catch (ex) {
+ console.error('require("' + this.yconfig + '" did not work; ensure that your custom config is valid JSON or a valid configuration object exported by a node module');
+ throw ex;
+ }
+ YUI.applyConfig(configObject);
+ }
};
/**
* implements the interface method to load a test file
@@ -97,7 +108,7 @@ Yui3TestRunner.prototype.loadFile = function (file) {
}
that.seenModules[name] = file;
that.moduleNames.push(name);
- YUI.add.apply(YUI, arguments);
+ YUI.add.apply(YUI, Array.prototype.slice.call(arguments));
},
fakeYUI = function () { throw new Error('Attempt to call the YUI function at load time, disallowed'); };
@@ -140,5 +151,4 @@ Yui3TestRunner.prototype.startTests = function (callback) {
Y.use.apply(Y, args);
};
-
module.exports = Yui3TestRunner;

0 comments on commit bea4ae1

Please sign in to comment.