Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

How can I load a custom YUI module when writing a test? #5

Closed
ktslwy opened this Issue · 10 comments

2 participants

@ktslwy

For example:

YUI.add('my-tests', function (Y, NAME) {

......

}, '0.0.1', {requires: ['test', 'my custom yui module']});

@gotwarlost
Owner

Yeah, it looks like yui3 test support is half-hearted in terms of loading custom modules. I think what is missing is a way to pass a config object to YUI so it can find custom modules.

Is this an accurate description of the problem?

@ktslwy

Exactly. I am packaging some custom YUI modules in the node module and I want to have some test coverage on them. What is the best way to do it? I tried YUI.applyConfig but it doesn't work.

@gotwarlost
Owner

yeah - the test loader uses a fake YUI object that doesn't implement the methods you want for purposes of loading the tests. It's only when all the tests are loaded that it uses a real one to use them.

I need to think about how to support your use case.

Could I bug you to give me a simple test case that should work in ytestrunner?

@ktslwy

Yeah. Will something like this work:

YUI.add('my-module', function(Y) {

    var secret = 'foobar';

    Y.namespace('My').Module = {
        getSecret: function () {
            return secret;
        }
    }

}, '0.0.1', {});
YUI.add('my-module-tests', function (Y, NAME) {

    'use strict';

    var myModule = Y.My.Module;
        suite = new Y.Test.Suite(NAME),
        A = Y.Assert;

    suite.add(new Y.Test.Case({
        'test my module': function () {
            A.areEqual('foobar', myModule.getSecret());
        }
    }));

    Y.Test.Runner.add(suite);

}, '0.0.1', {requires: ['test', 'my-module']});
@gotwarlost
Owner

thanks - i will take a look over this weekend to support this use-case.

@gotwarlost
Owner

Fixed in v0.3.1

Pass --yconfig to ytestrunner to load a custom YUI config.

File can be a JSON file with the required YUI config or a JS file that exports one. All ytestrunner does is require it and applies the output of the operation as a config to YUI.

See example under examples/yui3-custom-modules

Command line can be found in package.json as test script

Let me know if this works for you.

@gotwarlost
Owner

@ktslwy did you get a chance to try this out? Let me know how it goes so I can close the issue.

Thanks!

@ktslwy

Thanks. It works. Is the coverage report to custom YUI modules supported also? The coverage is showing as unknown:

Line coverage: Unknown, Function coverage: Unknown

I have used --cov-include to specify the file already.

@gotwarlost
Owner

OK, this should be fixed in v0.3.3. It wasn't hooking the YUI loader and now it does.

Note that this will only work with istanbul code coverage (which is now the default), and not with YUI test coverage.

$ npm test
npm WARN package.json yui3-test-custom-sample@0.0.1 No README.md file found!

> yui3-test-custom-sample@0.0.1 test /ytestrunner/examples/yui3-custom-modules
> ytestrunner --yui3 -c --yconfig test/config.json

info: (testrunner): Testing began at Mon Dec 10 2012 23:24:12 GMT-0800 (PST).
info: (testrunner): Test suite "foo-test" started.
info: (testrunner): Test case "testCase_yui_3_8_0pr2_1_1355210652528_6" started.
pass: (testrunner): test my module: passed.
✔ test my module
info: (testrunner): 
Test case "testCase_yui_3_8_0pr2_1_1355210652528_6" completed.
Passed:1 Failed:0 Total:1 (0 ignored)
info: (testrunner): 
Test suite "foo-test" completed.
Passed:1 Failed:0 Total:1 (0 ignored)
info: (testrunner): 
Testing completed at Mon Dec 10 2012 23:24:12 GMT-0800 (PST).
Passed:1 Failed:0 Total:1 (0 ignored)
================================================================================
Final summary: Passed: 1, Failed: 0, Skipped: 0, Total: 1, Load errors: 0, Statement coverage: 100%, Branch coverage: 100%, Function coverage: 100%, Line coverage: 100%
@gotwarlost gotwarlost closed this
@ktslwy

Tested and works. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.