Skip to content

CommonJS standard stuff #13

@joskuijpers

Description

@joskuijpers

After I implemented my modules, I also added assert.js and test.js, according to CommonJS/Unit Testing/1.0.
It provides a number of assert functions, such as assert(), assert.equal(), assert.deepEqual() and assert.throws(). These can be used to prevent some errors.

Then there is test.js that contains only one function: run(). You provide an object with functions starting with the letters 'test' and it will execute all these. Very nice for making unit tests. In a module, you run the code:

exports['test 1'] = function() { assert.notEqual(5,1, "idiocy"); };

if(require.main == module)
    require("test").run(exports);

This means that you can include unit tests in your module, and run those tests if your module become the main module. This is how CommonJS describes it.

I think it is a neat little addition that does not cause trouble when added to pegasus but it will advertize good programming style.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions