nodetk is a set of small libraries intended to facilitate the use of nodejs.
Works with node v.0.3.0.
nodetk is a set of small libraries intended to facilitate the use of nodejs. It includes:
How to use these libraries / tools :
In your .bashrc (or whatever rc) file, set the bin dir in your PATH env variable: export PATH=$PATH:/path/to/nodetk/bin
If you which to use the "serve nodejs package / mudules" feature, you should have
the dir where are located the nodejs libs in your NODE_PATH:
and the src dir in your NODE_PATH env variable:
You should then be able to use the nodetk modules with something like:
var callbacks = require("nodetk/orchestration/callbacks");
You now have the following available commands:
nodetests [-v] [-d]
The -v option displays some info about what tests are rand. The -d option enables the debug functions.
You do not need (and should not) add the nodetk path at the top of your test files...
This module provides a Connect middleware to serve other nodejs modules to the browser, so they can be used on both server side and client side. This is using the Yabble library on browser side, and wrapping served modules on fly so you can use same code on browser. This middleware can also be used to serve static files.
Example of use:
This module is also used in rest-mongo, see rest-mongo tests running on browser side.
The fs module provides several functions to have a higher level API.
Tests : src/nodetk/tests/test_fs.js.
This module provides functions to facilitate functions calls orchestration.
This module provides a function to get a base64url random string.
This module provides function to go from JSON obj to [opaque] string or vice & versa.
The cypher used is aes256, the crypted data are in hex. The signing process uses HMAC with SHA1. Tests : src/nodetk/tests/test_serializer.js.
Provides a few functions helpful when using an HTTP server.
The routes arg is used to search where to route the current req (fct called with req and res). If nothing found, next() is called. Pathnames in routes obj must be strings, not regexps.
This package provides some testing functionalities.
testing/custom_assert defines the same functions as the node assert module + the same_sets functions. All the module functions are wrapped so that the tests runner can count the number of asserts ran and act accordingly.
same_sets(actual, expected): check actual and expected arrays have the same values (order doesn't matter).
testing/nodetests is the script to run test files in a given directory (and sub-directories).
testing/server provides a function to get an HTTP server for testing (a server responding what you tell it to, nothing more).
testing/tests_runner is used by nodetests to run tests present in a file.
testing/tools is a module providing functions to help when testing HTTP servers:
get_expected_res(expected_status_code): Returns a res object making 3 asserts. Check the status code is the one expected, content-type is text/plain and body is not empty.
get_expected_redirect_res(location): Idem, check the status code is 303 and location is the one expected.
HTTP client and HTTP server utility functions.
GET/POST(url, data, callback, options): GET or POST to url with data (as URL parameters for GET, and in request body for POST). Once the request is complete, calls callback(http_code, headers, body). The URL scheme can be http or https. The options parameter is optional, and if given, is a hash with the following possible members:
emulate_browser: Add some firefox headers if set to True
additional_headers: hash containing some headers to add / redefine.
check_url(url, options, callback, fallback):
Try to fetch the response for this URL and call the callback with a hash object containing:
This function will follow redirects until 200 class answer is found or too many redirects number have been reached. In such case, callback is not called and fallback is called.
The options arguments may contain the max_redirects property, which by default is set to 3.
serve_static_file(fpath, response, [before, after]): Send file (located at fpath) as response (http.ServerResponse). before and after are two string optional arguments, which will be added at the beginning / end of the served file.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.fsf.org/licensing/licenses/agpl-3.0.html