grunt-saucelabs
Advanced tools
Comparing version 8.2.1 to 8.2.2
'use strict'; | ||
var Q = require('q'); | ||
var merge = require('merge'); | ||
var utils = require('../src/utils'); | ||
@@ -30,38 +29,39 @@ | ||
return { | ||
options: options.baseSaucelabsTaskOptions, | ||
'tunnel-test': { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/custom/succeeds.html'], | ||
testname: 'saucelabs-custom:tunnel-test', | ||
tunneled: true | ||
}) | ||
} | ||
}, | ||
succeeds: { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/custom/succeeds.html'], | ||
testname: 'saucelabs-custom:succeeds' | ||
}) | ||
} | ||
}, | ||
fails: { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/custom/fails.html'], | ||
testname: 'saucelabs-custom:fails', | ||
onTestComplete: options.negateResult | ||
}) | ||
} | ||
}, | ||
'callback-succeeds': { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/custom/succeeds.html'], | ||
testname: 'saucelabs-custom:callback-succeeds', | ||
onTestComplete: function (result, callback) { callback(null, result.passed); } | ||
}) | ||
} | ||
}, | ||
'callback-async-succeeds': { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/custom/succeeds.html'], | ||
testname: 'saucelabs-custom:callback-async-succeeds', | ||
onTestComplete: function (result, callback) { return Q.delay(3000).thenResolve(result.passed).nodeify(callback); } | ||
}) | ||
} | ||
}, | ||
throttled: { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
browsers: [ | ||
@@ -81,6 +81,6 @@ { browserName: 'firefox', version: '19', platform: 'XP' }, | ||
testname: 'saucelabs-custom:throttled' | ||
}) | ||
} | ||
}, | ||
timeout: { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/custom/timeout.html'], | ||
@@ -102,5 +102,5 @@ testname: 'saucelabs-custom:timeout', | ||
} | ||
}) | ||
} | ||
} | ||
}; | ||
}; | ||
}; |
'use strict'; | ||
module.exports = function (grunt, options) { | ||
var merge = require('merge'); | ||
return { | ||
options: options.baseSaucelabsTaskOptions, | ||
succeeds: { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/jasmine/succeeds.html'], | ||
testname: 'saucelabs-jasmine:succeeds' | ||
}) | ||
} | ||
}, | ||
fails: { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/jasmine/fails.html'], | ||
testname: 'saucelabs-jasmine:fails', | ||
onTestComplete: options.negateResult | ||
}) | ||
} | ||
} | ||
}; | ||
}; | ||
}; |
'use strict'; | ||
module.exports = function (grunt, options) { | ||
var merge = require('merge'); | ||
return { | ||
options: options.baseSaucelabsTaskOptions, | ||
succeeds: { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/mocha/test/browser/index.html'], | ||
testname: 'saucelabs-mocha:succeeds' | ||
}) | ||
} | ||
}, | ||
fails: { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/mocha/test/browser/fails.html'], | ||
testname: 'saucelabs-mocha:fails', | ||
onTestComplete: options.negateResult | ||
}) | ||
} | ||
} | ||
}; | ||
}; | ||
}; |
'use strict'; | ||
module.exports = function (grunt, options) { | ||
var merge = require('merge'); | ||
return { | ||
options: options.baseSaucelabsTaskOptions, | ||
succeeds: { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/qunit/index.html'], | ||
testname: 'saucelabs-qunit:succeeds' | ||
}) | ||
} | ||
}, | ||
fails: { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/qunit/fails.html'], | ||
testname: 'saucelabs-qunit:fails', | ||
onTestComplete: options.negateResult | ||
}) | ||
} | ||
}, | ||
@@ -24,9 +24,9 @@ error: { | ||
// result property (when the job is queried via the REST API) is null. | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/qunit/error.html'], | ||
testname: 'saucelabs-qunit:error', | ||
onTestComplete: options.negateResult | ||
}) | ||
} | ||
} | ||
}; | ||
}; | ||
}; |
'use strict'; | ||
module.exports = function (grunt, options) { | ||
var merge = require('merge'); | ||
return { | ||
options: options.baseSaucelabsTaskOptions, | ||
succeeds: { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/yui/index.html'], | ||
testname: 'saucelabs-yui:succeeds' | ||
}) | ||
} | ||
}, | ||
fails: { | ||
options: merge(true, {}, options.baseSaucelabsTaskOptions, { | ||
options: { | ||
urls: ['http://127.0.0.1:9999/yui/fails.html'], | ||
testname: 'saucelabs-yui:fails', | ||
onTestComplete: options.negateResult | ||
}) | ||
} | ||
} | ||
}; | ||
}; | ||
}; |
@@ -34,6 +34,5 @@ 'use strict'; | ||
build: process.env.TRAVIS_JOB_ID, | ||
browsers: [{ | ||
browserName: 'googlechrome', | ||
platform: 'XP' | ||
}], | ||
browsers: [ | ||
['XP', 'chrome', ''] | ||
], | ||
tunneled: false, | ||
@@ -40,0 +39,0 @@ sauceConfig: { |
{ | ||
"name": "grunt-saucelabs", | ||
"description": "Grunt task running tests using Sauce Labs. Supports QUnit, Jasmine, Mocha and YUI tests", | ||
"version": "8.2.1", | ||
"version": "8.2.2", | ||
"homepage": "https://github.com/axemclion/grunt-saucelabs", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -56,33 +56,5 @@ grunt-saucelabs | ||
platform: 'XP' | ||
}], | ||
onTestComplete: function(result, callback) { | ||
// Called after a unit test is done, per page, per browser | ||
// 'result' param is the object returned by the test framework's reporter | ||
// 'callback' is a Node.js style callback function. You must invoke it after you | ||
// finish your work. | ||
// Pass a non-null value as the callback's first parameter if you want to throw an | ||
// exception. If your function is synchronous you can also throw exceptions | ||
// directly. | ||
// Passing true or false as the callback's second parameter passes or fails the | ||
// test. Passing undefined does not alter the test result. Please note that this | ||
// only affects the grunt task's result. You have to explicitly update the Sauce | ||
// Labs job's status via its REST API, if you want so. | ||
// The example below negates the result, and also updates the Sauce Labs job's status | ||
var user = process.env.SAUCE_USERNAME; | ||
var pass = process.env.SAUCE_ACCESS_KEY; | ||
request.put({ | ||
url: ['https://saucelabs.com/rest/v1', user, 'jobs', result.job_id].join('/'), | ||
auth: { user: user, pass: pass }, | ||
json: { passed: !result.passed } | ||
}, function (error, response, body) { | ||
if (error) { | ||
callback(error); | ||
} else if (response.statusCode !== 200) { | ||
callback(new Error('Unexpected response status')); | ||
} else { | ||
callback(null, !result.passed); | ||
} | ||
}); | ||
} | ||
}] | ||
// optionally, he `browsers` param can be a flattened array: | ||
// [["XP", "firefox", 19], ["XP", "chrome", 31]] | ||
} | ||
@@ -112,3 +84,3 @@ } | ||
* __browsers__: An array of objects representing the [various browsers](https://saucelabs.com/docs/platforms) on which this test should run. _Optional_ | ||
* __onTestComplete__: A callback that is called every time a unit test for a page is complete. Runs per page, per browser configuration. Receives two arguments `(result, callback)`. `result` is the javascript object exposed to sauce labs as the results of the test. `callback` must be called, node-style (having arguments `err`, `result` where result is a true/false boolean which sets the test result reported to the command line) _Optional_ | ||
* __onTestComplete__: A callback that is called every time a unit test for a page is complete. Runs per page, per browser configuration. Receives two arguments `(result, callback)`. `result` is the javascript object exposed to sauce labs as the results of the test. `callback` must be called, node-style (having arguments `err`, `result` where result is a true/false boolean which sets the test result reported to the command line). See [example below](#ontestcomplete-callback) _Optional_ | ||
* __maxRetries__: Specifies how many times the timed out tests should be retried (default: 0). _Optional_ | ||
@@ -215,2 +187,60 @@ | ||
OnTestComplete callback | ||
----------------------- | ||
An optional parameter to the grunt task is `OnTestComplete`, a callback which is called at the end of every test, before results are logged to the console. | ||
You can use this callback to intercept results from SauceLabs and re-report the results (or use the information for your own purposes) | ||
Receives two arguments `(result, callback)`. `result` is the javascript object exposed to sauce labs as the results of the test. `callback` must be called, node-style (having arguments `err`, `result` where result is a true/false boolean which sets the test result reported to the command line) | ||
When running the tests for this project, we need to test the case where a test *fails* on Sauce. In this case, we want to record a test Failure as a Success for us. | ||
``` | ||
'saucelabs-qunit': { | ||
all: { | ||
options: { | ||
username: 'saucelabs-user-name', // if not provided it'll default to ENV SAUCE_USERNAME (if applicable) | ||
key: 'saucelabs-key', // if not provided it'll default to ENV SAUCE_ACCESS_KEY (if applicable) | ||
urls: ['www.example.com/qunitTests', 'www.example.com/mochaTests'], | ||
build: process.env.CI_BUILD_NUMBER, | ||
testname: 'Sauce Unit Test for example.com', | ||
browsers: [{ | ||
browserName: 'firefox', | ||
version: '19', | ||
platform: 'XP' | ||
}], | ||
onTestComplete: function(result, callback) { | ||
// Called after a unit test is done, per page, per browser | ||
// 'result' param is the object returned by the test framework's reporter | ||
// 'callback' is a Node.js style callback function. You must invoke it after you | ||
// finish your work. | ||
// Pass a non-null value as the callback's first parameter if you want to throw an | ||
// exception. If your function is synchronous you can also throw exceptions | ||
// directly. | ||
// Passing true or false as the callback's second parameter passes or fails the | ||
// test. Passing undefined does not alter the test result. Please note that this | ||
// only affects the grunt task's result. You have to explicitly update the Sauce | ||
// Labs job's status via its REST API, if you want so. | ||
// The example below negates the result, and also updates the Sauce Labs job's status | ||
var user = process.env.SAUCE_USERNAME; | ||
var pass = process.env.SAUCE_ACCESS_KEY; | ||
request.put({ | ||
url: ['https://saucelabs.com/rest/v1', user, 'jobs', result.job_id].join('/'), | ||
auth: { user: user, pass: pass }, | ||
json: { passed: !result.passed } | ||
}, function (error, response, body) { | ||
if (error) { | ||
callback(error); | ||
} else if (response.statusCode !== 200) { | ||
callback(new Error('Unexpected response status')); | ||
} else { | ||
callback(null, !result.passed); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
Examples | ||
@@ -236,2 +266,5 @@ -------- | ||
--------- | ||
####8.2.2#### | ||
* `browsers` param can optionally be an array identical to the one used by the Sauce API. ex: `["XP", "firefox", "19"]` | ||
####8.2.1#### | ||
@@ -238,0 +271,0 @@ * update dependencies |
@@ -54,3 +54,3 @@ 'use strict'; | ||
this.url = url; | ||
this.platform = [browser.platform || '', browser.browserName || '', browser.version || '']; | ||
this.platform = _.isArray(browser) ? browser : [browser.platform || '', browser.browserName || '', browser.version || '']; | ||
this.build = build; | ||
@@ -57,0 +57,0 @@ this.testName = testName; |
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
996325
31431
311