Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommonJS standard stuff #13

Open
joskuijpers opened this issue Apr 23, 2014 · 3 comments
Open

CommonJS standard stuff #13

joskuijpers opened this issue Apr 23, 2014 · 3 comments
Labels

Comments

@joskuijpers
Copy link
Contributor

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.

@joskuijpers
Copy link
Contributor Author

I forgot: I took some stuff from node.js util.js, that is: is* functions and an inherit() to make two constructors inherit each other. https://github.com/joskuijpers/Andromeda/blob/master/Andromeda/Resources/JavaScript/util.js
It is much cleaner to use than when writing it yourself (and making mistakes with null and undefined).

@joskuijpers
Copy link
Contributor Author

Because the implementation is bound to javascript, I also put the implementation in util.js.

@fatcerberus
Copy link
Contributor

minisphere includes an assert module based on the CommonJS specification since v4.1.0. No test module though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants