2 * Nodeunit functional tests. Requires internet connection to validate phantom
6 var childProcess = require('child_process')
8 var path = require('path')
9 var phantomjs = require('../lib/phantomjs')
12 exports.testDownload = function (test) {
14 test.ok(fs.existsSync(phantomjs.path), 'Binary file should have been downloaded')
19 exports.testPhantomExecutesTestScript = function (test) {
23 path.join(__dirname, 'loadspeed.js'),
24 'http://www.google.com/'
27 childProcess.execFile(phantomjs.path, childArgs, function (err, stdout, stderr) {
28 var value = (stdout.indexOf('msec') !== -1)
29 test.ok(value, 'Test script should have executed and returned run time')
35 exports.testPhantomExitCode = function (test) {
37 childProcess.execFile(phantomjs.path, [path.join(__dirname, 'exit.js')], function (err, stdout, stderr) {
38 test.equals(err.code, 123, 'Exit code should be returned from phantom script')
44 exports.testBinFile = function (test) {
47 var binPath = process.platform === 'win32' ?
48 path.join(__dirname, '..', 'lib', 'phantom', 'phantomjs.exe') :
49 path.join(__dirname, '..', 'bin', 'phantomjs')
51 childProcess.execFile(binPath, ['--version'], function (err, stdout, stderr) {
52 test.equal(phantomjs.version, stdout.trim(), 'Version should be match')
58 exports.testCleanPath = function (test) {
60 test.equal('/Users/dan/bin', phantomjs.cleanPath('/Users/dan/bin:./bin'))
61 test.equal('/Users/dan/bin:/usr/bin', phantomjs.cleanPath('/Users/dan/bin:./bin:/usr/bin'))
62 test.equal('/usr/bin', phantomjs.cleanPath('./bin:/usr/bin'))
63 test.equal('', phantomjs.cleanPath('./bin'))
64 test.equal('/Work/bin:/usr/bin', phantomjs.cleanPath('/Work/bin:/Work/phantomjs/node_modules/.bin:/usr/bin'))