Skip to content
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

Wrap a single test in test-amp-form.js that expect a console error with allowConsoleError #14592

Closed

Conversation

danielrozenberg
Copy link
Member

Followup to #14432

This only fixes one test which was previously assigned to me, because each and every test in this file is weird in its own way and I don't want to go down this rabbit hole

@rsimha
Copy link
Contributor

rsimha commented Apr 12, 2018

@choumx knows these tests better than I do.

@danielrozenberg
Copy link
Member Author

/to @rsimha I rebased it with the changes introduced in #14590 - without this PR, the test will raise a warning about not using allowConsoleError. With this PR, it raises a warning about using allowConsoleError without using console.error

@rsimha
Copy link
Contributor

rsimha commented Apr 13, 2018

As discussed offline, it's possible your test is doing something asynchronously, that's causing the console error to appear after the anonymous function passed to allowConsoleError has returned. You'll need to make the part(s) of your test that expect the error synchronous before wrapping them in allowConsoleError.

Examples:

This will warn...

console.error('foo');

... as will this...

allowConsoleError(() => {
  noError();
});

... but this will work...

noError();

... and so will this...

allowConsoleError(() => {
  console.error('foo');
});

@@ -55,13 +55,16 @@ describes.repeated('', {
let sandbox;
const timer = Services.timerFor(window);

function getAmpForm(form, canonical = 'https://example.com/amps.html') {
function getUnresolvedAmpForm(form, canonical = 'https://example.com/amps.html') {

Choose a reason for hiding this comment

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

Nit: getAmpFormSync.

};
ampForm.handleSubmitEvent_(event);
const findTemplateStub = ampForm.templates_.findAndRenderTemplate;
allowConsoleError(() => {

Choose a reason for hiding this comment

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

This has the same problem I mentioned in chat. The returned promise won't be chained (unless this has been since fixed).

Copy link
Contributor

Choose a reason for hiding this comment

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

Noted. Not yet fixed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure what you're referring to

Choose a reason for hiding this comment

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

Place a breakpoint on line 577. I believe it won't get triggered.

This is because sinon chains returned promises, but allowConsoleError() currently swallows it. What we need is for allowConsoleError(f) to detect promises returned in by f and chain them. Then, we'll do:

return allowConsoleError(() => { 
  ...
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed in #15228. With this, you can return allowConsoleError. Improperly written tests will fail presubmit checks.

@aghassemi
Copy link
Contributor

Thanks for the Pull Request. Since this PR has been stale for a while, I am closing it. Please feel free to reopen as needed.

@aghassemi aghassemi closed this May 30, 2018
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.

None yet

5 participants