jasminewd2
Advanced tools
Comparing version 0.1.0-beta.1 to 0.1.0
# Changelog for jasminewd2 | ||
# 0.1.0 | ||
Release for the selenium-webdriver 3.0.1 upgrade. | ||
# 0.1.0-beta.1 | ||
@@ -4,0 +8,0 @@ |
63
index.js
@@ -10,13 +10,2 @@ /** | ||
/** | ||
* Wraps a function so that all passed arguments are ignored. | ||
* @param {!Function} fn The function to wrap. | ||
* @return {!Function} The wrapped function. | ||
*/ | ||
function seal(fn) { | ||
return function() { | ||
fn(); | ||
}; | ||
} | ||
/** | ||
* Validates that the parameter is a function. | ||
@@ -64,5 +53,23 @@ * @param {Object} functionToValidate The function to validate. | ||
/** | ||
* Calls a function once the control flow is idle | ||
* @param {webdriver.promise.ControlFlow} flow The Web Driver control flow | ||
* @param {!Function} fn The function to call | ||
*/ | ||
function callWhenIdle(flow, fn) { | ||
if (flow.isIdle()) { | ||
fn(); | ||
} else { | ||
flow.once(webdriver.promise.ControlFlow.EventType.IDLE, function() { | ||
fn(); | ||
}); | ||
} | ||
} | ||
/** | ||
* Wraps a function so it runs inside a webdriver.promise.ControlFlow and | ||
* waits for the flow to complete before continuing. | ||
* @param {!webdriver.promise.ControlFlow} flow The WebDriver control flow. | ||
* @param {!Function} globalFn The function to wrap. | ||
* @param {!string} fnName The name of the function being wrapped (e.g. `'it'`). | ||
* @return {!Function} The new function. | ||
@@ -79,6 +86,10 @@ */ | ||
var async = fn.length > 0; | ||
testFn = fn.bind(this); | ||
var testFn = fn.bind(this); | ||
flow.execute(function controlFlowExecute() { | ||
return new webdriver.promise.Promise(function(fulfill, reject) { | ||
function wrappedReject(err) { | ||
var wrappedErr = new Error(err); | ||
reject(wrappedErr); | ||
} | ||
if (async) { | ||
@@ -89,6 +100,3 @@ // If testFn is async (it expects a done callback), resolve the promise of this | ||
var proxyDone = fulfill; | ||
proxyDone.fail = function(err) { | ||
var wrappedErr = new Error(err); | ||
reject(wrappedErr); | ||
}; | ||
proxyDone.fail = wrappedReject; | ||
testFn(proxyDone); | ||
@@ -98,13 +106,20 @@ } else { | ||
// be assumed to have completed synchronously. | ||
fulfill(testFn()); | ||
var ret = testFn(); | ||
if (webdriver.promise.isPromise(ret)) { | ||
ret.then(fulfill, wrappedReject); | ||
} else { | ||
fulfill(ret); | ||
} | ||
} | ||
}, flow); | ||
}, 'Run ' + fnName + description + ' in control flow').then(seal(done), function(err) { | ||
if (!err) { | ||
err = new Error('Unknown Error'); | ||
err.stack = ''; | ||
}, 'Run ' + fnName + description + ' in control flow').then( | ||
callWhenIdle.bind(null, flow, done), function(err) { | ||
if (!err) { | ||
err = new Error('Unknown Error'); | ||
err.stack = ''; | ||
} | ||
err.stack = err.stack + '\nFrom asynchronous test: \n' + driverError.stack; | ||
callWhenIdle(flow, done.fail.bind(done, err)); | ||
} | ||
err.stack = err.stack + '\nFrom asynchronous test: \n' + driverError.stack; | ||
done.fail(err); | ||
}); | ||
); | ||
}; | ||
@@ -111,0 +126,0 @@ } |
@@ -14,8 +14,10 @@ { | ||
"author": "Julie Ralph <ju.ralph@gmail.com>", | ||
"devDependencies": { | ||
"dependencies": { | ||
"jasmine": "2.4.1", | ||
"jshint": "2.5.0", | ||
"selenium-webdriver": "^3.0.0", | ||
"typescript": "^2.0.0" | ||
"selenium-webdriver": "3.0.1" | ||
}, | ||
"devDependencies": { | ||
"jshint": "^2.9.4", | ||
"typescript": "^2.0.10" | ||
}, | ||
"repository": { | ||
@@ -34,5 +36,5 @@ "type": "git", | ||
"engines": { | ||
"node": ">= 6.9.0" | ||
"node": ">= 6.9.x" | ||
}, | ||
"version": "0.1.0-beta.1" | ||
"version": "0.1.0" | ||
} |
@@ -18,2 +18,4 @@ jasminewd [![Build Status](https://travis-ci.org/angular/jasminewd.png?branch=master)](https://travis-ci.org/angular/jasminewd) | ||
- If a test returns a promise, waits for both the control flow and the promise to resolve. | ||
- Enhances `expect` so that it automatically unwraps promises before performing the assertion. | ||
@@ -62,1 +64,11 @@ | ||
``` | ||
`async` functions / `await` | ||
--------------------------- | ||
`async` functions and the `await` keyword are likely coming in ES2017 (ES8), and | ||
available via several compilers. At the moment, they often break the WebDriver | ||
control flow. | ||
([GitHub issue](https://github.com/SeleniumHQ/selenium/issues/3037)). You can | ||
still use them, but if you do then you will have to use `await`/Promises for | ||
almost all your synchronization. See `spec/asyncAwaitSpec.ts` for details. |
Sorry, the diff of this file is not supported yet
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
20311
2
290
73
2
5
+ Addedjasmine@2.4.1
+ Addedselenium-webdriver@3.0.1
+ Addedadm-zip@0.4.16(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedexit@0.1.2(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@3.2.117.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedjasmine@2.4.1(transitive)
+ Addedjasmine-core@2.4.1(transitive)
+ Addedlru-cache@2.7.3(transitive)
+ Addedminimatch@0.3.03.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedsax@1.4.1(transitive)
+ Addedselenium-webdriver@3.0.1(transitive)
+ Addedsigmund@1.0.1(transitive)
+ Addedtmp@0.0.30(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxml2js@0.4.23(transitive)
+ Addedxmlbuilder@11.0.1(transitive)