Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / phantomjs / test / tests.js
1 /**
2  * Nodeunit functional tests.  Requires internet connection to validate phantom
3  * functions correctly.
4  */
5
6 var childProcess = require('child_process')
7 var fs = require('fs')
8 var path = require('path')
9 var phantomjs = require('../lib/phantomjs')
10
11
12 exports.testDownload = function (test) {
13   test.expect(1)
14   test.ok(fs.existsSync(phantomjs.path), 'Binary file should have been downloaded')
15   test.done()
16 }
17
18
19 exports.testPhantomExecutesTestScript = function (test) {
20   test.expect(1)
21
22   var childArgs = [
23     path.join(__dirname, 'loadspeed.js'),
24     'http://www.google.com/'
25   ]
26
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')
30     test.done()
31   })
32 }
33
34
35 exports.testPhantomExitCode = function (test) {
36   test.expect(1)
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')
39     test.done()
40   })
41 }
42
43
44 exports.testBinFile = function (test) {
45   test.expect(1)
46
47   var binPath = process.platform === 'win32' ? 
48       path.join(__dirname, '..', 'lib', 'phantom', 'phantomjs.exe') :
49       path.join(__dirname, '..', 'bin', 'phantomjs')
50
51   childProcess.execFile(binPath, ['--version'], function (err, stdout, stderr) {
52     test.equal(phantomjs.version, stdout.trim(), 'Version should be match')
53     test.done()
54   })
55 }
56
57
58 exports.testCleanPath = function (test) {
59   test.expect(5)
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'))
65   test.done()
66 }