Giter Site home page Giter Site logo

module-api-tests's Introduction

module-api-tests

Explores side-effects, anti-patterns in the commonjs exports api, because some things just can't be assumed.

module.exports === exports === this ...

...unless you overwrite or reassign module.exports or exports:

  1. Overwrite module.exports, assign attrs to exports and/or this:

    module.exports = { name: 'module.exports' };

    exports.name = 'exports'; this.name ='this';

  2. Overwrite exports, assign attrs to module.exports and/or this:

    module.exports.name = 'module.exports';

    exports = { name: exports' }; this.name ='this';

In both cases, module.exports wins:

require('module-test').name === 'module.exports';
  1. And unlike the AMD define() pattern:

    delete module.exports; return 'something else'; // return this explicitly

returning a value explicitly from a module with a return statement does not export that value. Again, module.exports wins.

  1. Adding attributes to this, exports or module.exports:

    module.exports.name = 'module.exports'; exports.name = 'exports'; this.name ='this';

In this case, last assignment wins:

require('assignment').name === 'this';

tests

View the generated test page on rawgit.

jasmine-node

Misko Hevery's (mhevery) jasmine-node package was used to drive these tests initially.

jasmine-node --verbose ./test/suite.spec.js

testem

Toby Ho's (@airporty) testem package was used to drive these tests in the browser as well as on node.

The testem.json file defines a custom test page to run jasmine tests in browsers

testem 

...and defines a launcher for jasmine-node:

testem -l jasmine-node

... and uses the before_tests hook to run browserify.

browserify

James Halliday's (@substack) node-to-browser source bundler utility, browserify:

browserify ./test/suite.spec.js > ./test/bundle-spec.js

... is used to generated the html-only version of all the javascript tests used by both testem and viewable in a standalone page on rawgit.

rawgit

The custom test page can be viewed on rawgit, Ryan Grove's (@yaypie) invaluable service for remote viewing your repo's html in a browser so you don't have to run a server locally.

(Note: The testem script does not execute on rawgit, only the jasmine and test scripts in the browserified bundle.)

module-api-tests's People

Contributors

dfkaye avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.