Skip to content

chore(promises): Wait for promises explicitly #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2016

Conversation

sjelin
Copy link
Contributor

@sjelin sjelin commented Nov 22, 2016

See #68 for details

@sjelin sjelin force-pushed the promise branch 3 times, most recently from d45aa6e to 4ab4f2f Compare November 23, 2016 02:37
Copy link
Contributor

@thorn0 thorn0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great overall 👍

}
}, flow);
}, 'Run ' + fnName + description + ' in control flow').then(seal(done), function(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The seal function isn't used any more, so its declaration can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -78,30 +94,38 @@ function wrapInControlFlow(flow, globalFn, fnName) {

flow.execute(function controlFlowExecute() {
return new webdriver.promise.Promise(function(fulfill, reject) {
function wrappedReject(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: inconsistent indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}


/**
* Wraps a function so it runs inside a webdriver.promise.ControlFlow and
* waits for the flow to complete before continuing.
* @param {!Function} globalFn The function to wrap.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to this PR: only one param of the 3 is documented

it('test B', () => {
currentTest = 'B';
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to test the error handling code paths somehow too.

@sjelin sjelin force-pushed the promise branch 3 times, most recently from 4b57ea0 to c67de4a Compare November 23, 2016 20:16
@@ -102,4 +102,24 @@ describe('things that should fail', function() {
expect(fakeDriver.getDecimalNumber()).toBeCloseTo(3.1);
expect(fakeDriver.getDecimalNumber()).not.toBeCloseTo(3.14);
});

describe('native promises', function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thorn0 this look good for error handling tests?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks. There is also all this code for dealing with stack traces though...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want me to double check that the stack trace is correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind. That code appeared to me more complicated than it actually is. Let's merge this. 👍

err.stack = '';
}
err.stack = err.stack + '\nFrom asynchronous test: \n' + driverError.stack;
callWhenIdle(flow, done.fail.bind(done, err));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to call flow.reset() here instead of waiting for idle. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we want to reset? If there are pending webdriver tasks we probably want to wait on them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we know that the test has already failed and we can cancel those tasks, why execute them? But I'm not sure. Let's leave it as it is.

* @param {!Function} globalFn The function to wrap.
* @parm {!string} fnName The name of the function being wrapped (e.g. `'it'`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parm -> param

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Nit: address spelling.
  • Nit: should end comment with a period.

err = new Error('Unknown Error');
err.stack = '';
}
err.stack = err.stack + '\nFrom asynchronous test: \n' + driverError.stack;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add fnName and description to this information for it to be a bit easier to identify errors?

err.stack += '\nFrom asynchronous test ' + fnName + description + ': \n' + driverError.stack;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jasmine adds that information automatically when we call done.fail

@sjelin
Copy link
Contributor Author

sjelin commented Dec 5, 2016

@cnishina you wanna review this?

@cnishina cnishina self-assigned this Dec 5, 2016
* 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: should end comment with a period.

* @param {!Function} globalFn The function to wrap.
* @parm {!string} fnName The name of the function being wrapped (e.g. `'it'`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Nit: address spelling.
  • Nit: should end comment with a period.

@sjelin
Copy link
Contributor Author

sjelin commented Dec 6, 2016

@cnishina all comments addressed. Can I have an LGTM? 😄

@cnishina cnishina merged commit 47863c4 into angular:jasminewd2 Dec 6, 2016
cnishina pushed a commit to cnishina/jasminewd that referenced this pull request Jan 6, 2017
cnishina pushed a commit that referenced this pull request Jan 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants