aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonan Amicel <ronan.amicel@gmail.com>2012-10-12 12:44:25 +0200
committerRonan Amicel <ronan.amicel@gmail.com>2012-10-13 17:01:49 +0200
commit696b66860447d76db05f4b431e8e8508a24b2c7f (patch)
tree3e73778b0d900e54bb53c4c2bc2c89c02301c85a
parentAdd require.nodejs module (diff)
downloadfabtools-696b66860447d76db05f4b431e8e8508a24b2c7f.tar.xz
Add test tasks for Node.js modules
-rw-r--r--fabtools/tests/fabfiles/nodejs.py100
1 files changed, 100 insertions, 0 deletions
diff --git a/fabtools/tests/fabfiles/nodejs.py b/fabtools/tests/fabfiles/nodejs.py
new file mode 100644
index 0000000..8d47d87
--- /dev/null
+++ b/fabtools/tests/fabfiles/nodejs.py
@@ -0,0 +1,100 @@
+from __future__ import with_statement
+
+try:
+ import json
+except ImportError:
+ import simplejson as json
+
+from fabric.api import *
+from fabtools import nodejs
+from fabtools import require
+from fabtools.files import is_file
+
+
+@task
+def install_nodejs():
+ """
+ Test low level API
+ """
+
+ # Install Node.js from source
+ if nodejs.version() != nodejs.DEFAULT_VERSION:
+ nodejs.install_from_source()
+
+ assert is_file('/usr/local/bin/node')
+ assert nodejs.version() == nodejs.DEFAULT_VERSION
+
+ # Install / uninstall global package
+ if not nodejs.package_version('underscore'):
+ nodejs.install_package('underscore', version='1.4.2')
+
+ assert nodejs.package_version('underscore') == '1.4.2'
+ assert is_file('/usr/local/lib/node_modules/underscore/underscore.js')
+
+ nodejs.uninstall_package('underscore')
+
+ assert nodejs.package_version('underscore') == None
+ assert not is_file('/usr/local/lib/node_modules/underscore/underscore.js')
+
+ # Install / uninstall local package
+ if not nodejs.package_version('underscore', local=True):
+ nodejs.install_package('underscore', version='1.4.2', local=True)
+
+ assert is_file('node_modules/underscore/underscore.js')
+ assert nodejs.package_version('underscore', local=True) == '1.4.2'
+
+ nodejs.uninstall_package('underscore', local=True)
+
+ assert nodejs.package_version('underscore', local=True) == None
+ assert not is_file('node_modules/underscore/underscore.js')
+
+ # Install dependencies from package.json file
+ require.directory('nodetest')
+ with cd('nodetest'):
+ require.file('package.json', contents=json.dumps({
+ 'name': 'nodetest',
+ 'version': '1.0.0',
+ 'dependencies': {
+ 'underscore': '1.4.2'
+ }
+ }))
+
+ nodejs.install_dependencies()
+
+ assert is_file('node_modules/underscore/underscore.js')
+ assert nodejs.package_version('underscore', local=True) == '1.4.2'
+
+
+@task
+def require_nodejs():
+ """
+ Test high level API
+ """
+
+ # Require Node.js
+
+ require.nodejs.installed_from_source()
+
+ assert is_file('/usr/local/bin/node')
+ assert nodejs.version() == nodejs.DEFAULT_VERSION
+
+ # Require a global package
+
+ nodejs.uninstall_package('underscore')
+
+ require.nodejs.package('underscore', version='1.4.1')
+ assert nodejs.package_version('underscore') == '1.4.1'
+
+ require.nodejs.package('underscore', version='1.4.0')
+ assert nodejs.package_version('underscore') == '1.4.0'
+
+ require.nodejs.package('underscore', version='1.4.2')
+ assert nodejs.package_version('underscore') == '1.4.2'
+
+ # Require a local package
+
+ nodejs.uninstall_package('underscore', local=True)
+
+ require.nodejs.package('underscore', version='1.4.2', local=True)
+
+ assert nodejs.package_version('underscore', local=True) == '1.4.2'