Skip to content

Mock xhr-fetch#10776

Closed
Raphaeljunior wants to merge 79 commits intoampproject:masterfrom
Raphaeljunior:xhr-mock
Closed

Mock xhr-fetch#10776
Raphaeljunior wants to merge 79 commits intoampproject:masterfrom
Raphaeljunior:xhr-mock

Conversation

@Raphaeljunior
Copy link
Copy Markdown
Contributor

  • Mocks out fetch in realWin and fakeWin and avails it through expectFetch as follows.

Closes #10477

@googlebot
Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Aug 3, 2017
@rsimha
Copy link
Copy Markdown
Contributor

rsimha commented Aug 3, 2017

@Raphaeljunior, once #10671 is merged, the dependency errors on Travis should no longer be an issue.

"eslint": "3.18.0",
"eslint-plugin-google-camelcase": "0.0.2",
"express": "4.14.0",
"fetch-mock": "^5.12.1",
Copy link
Copy Markdown
Contributor

@rsimha rsimha Aug 3, 2017

Choose a reason for hiding this comment

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

Can you also update yarn.lock by running yarn upgrade --save-dev and including the diffs in this PR?

/cc @erwinmombay

Edit: nvm, looks like you've done it in a new commit. Thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't use yarn upgrade, use yarn install.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's an error that happens on travis.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because you upgraded the yarn.lock to use unsupported versions. Revert changes to yarn.lock, then run yarn install and it'll work again.

@googlebot
Copy link
Copy Markdown

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot googlebot added cla: no and removed cla: yes labels Aug 7, 2017
@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Aug 7, 2017
@Raphaeljunior
Copy link
Copy Markdown
Contributor Author

@jridgewell PR ready for review.

@dreamofabear dreamofabear self-requested a review August 10, 2017 16:06
Copy link
Copy Markdown

@dreamofabear dreamofabear left a comment

Choose a reason for hiding this comment

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

Nice work! Two more things:

  • Add some detail to the PR description -- what is the new default behavior? How do I use this new functionality?
  • Revert package-lock.json since we haven't switched to using it from yarn.lock yet.

/**
* @fileoverview
* Asserts xhr fetch has been mocked out and under control
**/
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: Single *.

/**
 *
 */

@@ -0,0 +1,48 @@
/**
* Copyright 2016 The AMP HTML Authors. All Rights Reserved.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2017

import {setStyles} from '../src/style';
import * as sinon from 'sinon';

import fetchMock from 'fetch-mock';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: Insert newline after this.

* @param {{
* win: !FakeWindowSpec,
* win: !FakeWindow
Spec,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Revert.

* @param {string} name
* @param {!Object} spec
* @param {!Object} specconsole.log(fetchMock.sandbox());
debugger;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Revert.

env.expectFetch = function(url, response) {
return fetchMock.mock(url, response);
};
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Let's move this block of code to a top-level helper function to avoid code dupe.

message: 'Use a sandbox instead to avoid repeated `#restore` calls',
},
'(\\w*([sS]py|[sS]tub|[mM]ock|clock).restore)': {
'(\\w*([sS]py|[sS]tub|\\.[mM]ock|clock).restore)': {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To prevent the presubmit.js from blocking fetchMock.restore()

@@ -1,4 +1,4 @@
/**
/**
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Revert.

return initPromise.then(() => {
expect(noContentSpy).to.be.calledWith(false);
expect(iframeHandler.iframe).to.be.null;
done();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This shouldn't be necessary since we're returning a Promise in the test.

ampdoc: 'fie',
runtimeOn: false,
},
xhrMock: false,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: How about mockFetch? Sounds more like an action/verb.

@dreamofabear
Copy link
Copy Markdown

@taymonbeal FYI, let us know if this works for you.

@googlebot
Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@dreamofabear
Copy link
Copy Markdown

Now that @Raphaeljunior has left, closing this and forking into #11001 since it's a huge pain to patch with conflicts and ~80 commits.

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.

5 participants