Skip to content

Commit

Permalink
added cli tests for modules
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Feb 23, 2013
1 parent a7de99b commit 77f924d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bin/casperjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import sys

def test_cmd(cmd):
try:
return subprocess.check_output([__file__] + cmd.split(' '))
return subprocess.check_output([__file__] + cmd.split(' ')).strip()
except subprocess.CalledProcessError as err:
sys.stderr.write('FAIL: %s\n' % err)
sys.stderr.write(' return code: %d\n' % err.returncode)
Expand Down Expand Up @@ -55,11 +55,13 @@ if len(SYS_ARGS) and SYS_ARGS[0] == '__selfcommandtest':
scripts_path = os.path.join(CASPER_PATH, 'tests', 'commands')
assert(test_cmd('--help').find(pkg_version) > -1)
assert(test_cmd('--version').strip() == pkg_version)
assert(test_cmd(os.path.join(scripts_path, 'script.js')) == 'it works\n')
assert(test_cmd(os.path.join(scripts_path, 'script.js')) == 'it works')
test_output = test_cmd('test --no-colors ' + os.path.join(scripts_path, 'mytest.js'))
assert('PASS ok1' in test_output)
assert('PASS ok2' in test_output)
assert('PASS ok3' in test_output)
module_test = test_cmd(os.path.join(CASPER_PATH, 'tests', 'clitests', 'modules', 'test.js'))
assert(module_test == 'hello, world')
print('Python executable tests passed.')
sys.exit(0)

Expand Down
4 changes: 4 additions & 0 deletions tests/clitests/modules/mod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*global patchRequire*/
var require = patchRequire(require);
var utils = require('utils');
exports.hello = utils.format('hello, %s', require('./sub/mod').name);
1 change: 1 addition & 0 deletions tests/clitests/modules/sub/mod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.name = 'world';
4 changes: 4 additions & 0 deletions tests/clitests/modules/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var casper = require('casper').create();
var mod = require('./mod');
console.log(mod.hello);
casper.exit();

0 comments on commit 77f924d

Please sign in to comment.