nightwatch
Advanced tools
Comparing version 0.5.9 to 0.5.10
var fs = require('fs'), | ||
path = require('path'), | ||
ejs = require('ejs'); | ||
mkpath = require('mkpath'), | ||
path = require('path'), | ||
ejs = require('ejs'); | ||
@@ -14,5 +15,5 @@ exports.save = function(results, opts, callback) { | ||
for (var moduleName in results.modules) { | ||
if (results.modules.hasOwnProperty(moduleName)) { | ||
var module = results.modules[moduleName]; | ||
for (var moduleKey in results.modules) { | ||
if (results.modules.hasOwnProperty(moduleKey)) { | ||
var module = results.modules[moduleKey]; | ||
var tests = 0, errors = 0, failures = 0; | ||
@@ -26,2 +27,4 @@ for (var x in module) { | ||
} | ||
var pathParts = moduleKey.split(path.sep); | ||
var moduleName = pathParts.pop(); | ||
var rendered = ejs.render(tmpl, { | ||
@@ -38,3 +41,9 @@ locals: { | ||
var filename = path.join(opts.output_folder, opts.filename_prefix + moduleName + '.xml'); | ||
var output_folder = opts.output_folder; | ||
if (pathParts.length) { | ||
output_folder = path.join(output_folder, pathParts.join(path.sep)); | ||
mkpath.sync(output_folder); | ||
} | ||
var filename = path.join(output_folder, opts.filename_prefix + moduleName + '.xml'); | ||
fs.writeFile(filename, rendered, callback); | ||
@@ -41,0 +50,0 @@ } |
@@ -24,3 +24,3 @@ /** | ||
function runModule(module, opts, moduleName, moduleCallback, finishCallback) { | ||
function runModule(module, opts, moduleName, moduleKey, moduleCallback, finishCallback) { | ||
var client; | ||
@@ -48,3 +48,3 @@ try { | ||
var onTestFinished = function (results, errors, startTime) { | ||
globalResults.modules[moduleName][currentTest] = { | ||
globalResults.modules[moduleKey][currentTest] = { | ||
passed : results.passed, | ||
@@ -309,2 +309,3 @@ failed : results.failed, | ||
}); | ||
cb(null, modules); | ||
@@ -364,16 +365,15 @@ }, opts); | ||
* @param {string} modulePath | ||
* @param {Array} src_folders | ||
* @param {object} opts | ||
* @returns {string} | ||
*/ | ||
function getPathDiff(modulePath, src_folders) { | ||
var pathParts = modulePath.split(path.sep); | ||
pathParts.pop(); | ||
var moduleFolder = pathParts.join(path.sep); | ||
function getPathDiff(modulePath, opts) { | ||
if (!opts || !opts.src_folders) { | ||
return ''; | ||
} | ||
var diffInFolder = '', srcFolder; | ||
for (var i = 0; i < src_folders.length; i++) { | ||
srcFolder = path.resolve(src_folders[i]); | ||
if (moduleFolder.indexOf(srcFolder) === 0) { | ||
diffInFolder = moduleFolder.substring(srcFolder.length); | ||
for (var i = 0; i < opts.src_folders.length; i++) { | ||
srcFolder = path.resolve(opts.src_folders[i]); | ||
if (modulePath.indexOf(srcFolder) === 0) { | ||
diffInFolder = modulePath.substring(srcFolder.length + 1); | ||
break; | ||
@@ -457,4 +457,7 @@ } | ||
var moduleName = modulePath.split(path.sep).pop(); | ||
globalResults.modules[moduleName] = []; | ||
var moduleParts = modulePath.split(path.sep); | ||
var moduleName = moduleParts.pop(); | ||
var subFolder = getPathDiff(moduleParts.join(path.sep), additional_opts); | ||
var moduleKey = path.join(subFolder, moduleName); | ||
globalResults.modules[moduleKey] = {}; | ||
@@ -466,3 +469,3 @@ if (opts.output) { | ||
} | ||
runModule(module, opts, moduleName, function(err, modulekeys) { | ||
runModule(module, opts, moduleName, moduleKey, function(err, modulekeys) { | ||
if (fullpaths.length) { | ||
@@ -480,5 +483,3 @@ setTimeout(function() { | ||
} else { | ||
var diffInFolder = getPathDiff(modulePath, additional_opts.src_folders); | ||
var output = path.join(additional_opts.output_folder, diffInFolder); | ||
mkpath(output, function(err) { | ||
mkpath(additional_opts.output_folder, function(err) { | ||
if (err) { | ||
@@ -493,10 +494,11 @@ console.log(Logger.colors.yellow('Output folder doesn\'t exist and cannot be created.')); | ||
Reporter.save(globalResults, { | ||
output_folder : output, | ||
output_folder : additional_opts.output_folder, | ||
filename_prefix : opts.report_prefix | ||
}, function(err) { | ||
if (err) { | ||
console.log(Logger.colors.yellow('Warning: Failed to save report file to folder: ' + output)); | ||
console.log(Logger.colors.yellow('Warning: Failed to save report file to folder: ' + additional_opts.output_folder)); | ||
console.log(err.stack); | ||
} | ||
}); | ||
finishCallback(null); | ||
@@ -503,0 +505,0 @@ }); |
{ | ||
"name": "nightwatch", | ||
"description": "A node.js bindings implementation for selenium 2.0/webdriver", | ||
"version": "0.5.9", | ||
"version": "0.5.10", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Andrei Rusu", |
@@ -7,3 +7,3 @@ { | ||
"postdata" : "{\"desiredCapabilities\":{\"browserName\":\"firefox\",\"javascriptEnabled\":true,\"acceptSslCerts\":true,\"platform\":\"ANY\"}}", | ||
"response" : "{\"status\": 0, \"sessionId\": \"1352110219202\", \"value\": { \"javascriptEnabled\": true, \"browserName\": \"firefox\"}, \"state\": null}", | ||
"response" : "{\"status\": 0, \"sessionId\": \"1352110219202\", \"value\": { \"javascriptEnabled\": true, \"browserName\": \"firefox\", \"version\": \"TEST\", \"platform\": \"TEST\"}, \"state\": null}", | ||
"responseHeaders" : { | ||
@@ -10,0 +10,0 @@ }, |
var BASE_PATH = process.env.NIGHTWATCH_COV | ||
? 'lib-cov' | ||
: 'lib'; | ||
var Runner = require('../../../'+ BASE_PATH +'/runner/run.js'); | ||
var path = require('path'); | ||
module.exports = { | ||
setUp : function(cb) { | ||
this.Runner = require('../../../'+ BASE_PATH +'/runner/run.js'); | ||
cb(); | ||
}, | ||
tearDown : function(callback) { | ||
delete require.cache[require.resolve('../../../'+ BASE_PATH +'/runner/run.js')]; | ||
callback(); | ||
}, | ||
testRunEmptyFolder : function(test) { | ||
Runner.run([process.cwd() + '/sampletests/empty'], {}, { | ||
var testsPath = path.join(process.cwd(), '/sampletests/empty'); | ||
this.Runner.run([testsPath], {}, { | ||
output_folder : false | ||
@@ -17,3 +29,4 @@ }, function(err) { | ||
testRunSimple : function(test) { | ||
Runner.run([process.cwd() + '/sampletests/simple'], { | ||
var testsPath = path.join(process.cwd(), '/sampletests/simple'); | ||
this.Runner.run([testsPath], { | ||
seleniumPort : 10195, | ||
@@ -36,3 +49,4 @@ silent : true, | ||
testRunWithExcludeFolder : function(test) { | ||
Runner.run([process.cwd() + '/sampletests/withexclude'], { | ||
var testsPath = path.join(process.cwd(), '/sampletests/withexclude'); | ||
this.Runner.run([testsPath], { | ||
seleniumPort : 10195, | ||
@@ -54,3 +68,5 @@ silent : true, | ||
testRunWithExcludePattern : function(test) { | ||
Runner.run([process.cwd() + '/sampletests/withexclude'], { | ||
var testsPath = path.join(process.cwd(), '/sampletests/withexclude'); | ||
var testPattern = path.join('excluded', 'excluded-*'); | ||
this.Runner.run([testsPath], { | ||
seleniumPort : 10195, | ||
@@ -62,3 +78,3 @@ silent : true, | ||
}, | ||
exclude : ['excluded/excluded-*'] | ||
exclude : [testPattern] | ||
}, { | ||
@@ -74,4 +90,4 @@ output_folder : false | ||
test.expect(5); | ||
Runner.run([process.cwd() + '/sampletests/async'], { | ||
var testsPath = path.join(process.cwd(), '/sampletests/async'); | ||
this.Runner.run([testsPath], { | ||
seleniumPort : 10195, | ||
@@ -95,4 +111,4 @@ silent : true, | ||
test.expect(6); | ||
Runner.run([process.cwd() + '/sampletests/mixed'], { | ||
var testsPath = path.join(process.cwd(), '/sampletests/mixed'); | ||
this.Runner.run([testsPath], { | ||
seleniumPort : 10195, | ||
@@ -115,3 +131,5 @@ silent : true, | ||
testRunWithTags : function(test) { | ||
Runner.run([process.cwd() + '/sampletests'], { | ||
var testsPath = path.join(process.cwd(), 'sampletests'); | ||
this.Runner.run([testsPath], { | ||
seleniumPort : 10195, | ||
@@ -127,7 +145,38 @@ silent : true, | ||
}, function(err, results) { | ||
test.ok(('demoTagTest' in results.modules.sample)); | ||
test.ok(Object.keys(results.modules).length === 1); | ||
test.ok(('demoTagTest' in results.modules.sample), 'demoTagTest was ran'); | ||
test.ok(Object.keys(results.modules).length === 1, 'There was only 1 test running.'); | ||
test.done(); | ||
}); | ||
}, | ||
testRunWithOutput : function(test) { | ||
var src_folders = [ | ||
path.join(process.cwd(), 'sampletests/withsubfolders') | ||
]; | ||
this.Runner.run(src_folders, { | ||
seleniumPort : 10195, | ||
silent : true, | ||
output : false, | ||
globals : { | ||
test : test | ||
} | ||
}, { | ||
output_folder : 'output', | ||
src_folders : src_folders | ||
}, function(err, results) { | ||
test.equals(err, null); | ||
var fs = require('fs'); | ||
fs.readdir(src_folders[0], function(err, list) { | ||
test.deepEqual(list, ['simple', 'tags'], 'The subfolders have been created.'); | ||
var simpleReportFile = 'output/simple/FIREFOX_TEST_TEST_sample.xml'; | ||
var tagsReportFile = 'output/tags/FIREFOX_TEST_TEST_sample.xml'; | ||
test.ok(fs.existsSync(simpleReportFile), 'The simple report file was not created.'); | ||
test.ok(fs.existsSync(tagsReportFile), 'The tags report file was not created.'); | ||
test.done(); | ||
}); | ||
}); | ||
} | ||
}; |
@@ -18,5 +18,7 @@ var BASE_PATH = process.env.NIGHTWATCH_COV ? 'lib-cov' : 'lib'; | ||
test.deepEqual(api.capabilities, { | ||
'javascriptEnabled': true, | ||
'browserName': 'firefox' | ||
}); | ||
javascriptEnabled: true, | ||
browserName: 'firefox', | ||
version: 'TEST', | ||
platform: 'TEST' | ||
}); | ||
test.done(); | ||
@@ -23,0 +25,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
340945
131
9894
123