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

🏗 ✅ Isolate tests by eliminating the use of the global sinon sandbox #25587

Merged
merged 6 commits into from Nov 20, 2019
Merged

🏗 ✅ Isolate tests by eliminating the use of the global sinon sandbox #25587

merged 6 commits into from Nov 20, 2019

Conversation

rsimha
Copy link
Contributor

@rsimha rsimha commented Nov 14, 2019

The majority of AMP's tests reuse a single global sandbox instance provided by the sinon package. From looking at test code, there's a fair amount of inconsistency in how different tests create (sometimes), use, and clean up (not always) their sandbox.

This PR picks up where #23726 left off, and does the following:

  • Upgrades sinon to v7.5.0
  • Makes it a lint error to use the globals sinon or sandbox in an AMP test
  • Fixes O(thousand) tests that currently reuse the global sandbox.
    • For legacy describe tests:
      • Resets window.sandbox to a new instance in the top-level beforeEach()
      • Cleans up window.sandbox in the top-level afterEach()
      • Modifies all tests to use window.sandbox instead of the global sinon object
    • For newer describes tests:
      • env.sandbox is already reset to a new instance in the setup() method of SandboxFixture
      • Modifies all tests to use env.sandbox instead of the global sinon object
  • Skips a few tests on Safari because atob and btoa cannot be found (Multiple runtime tests fail on Safari (Sauce Labs) because atob and btoa can't be found #25621)

Fixes #23842
Fixes #25371
Closes #23726
Closes #25588
Closes #25455
Related to #14360
Related to #23837
Related to #25621

@amp-owners-bot
Copy link

Hey @gmajoulet, these files were changed:

  • extensions/amp-story/0.1/test/test-amp-story-consent.js
  • extensions/amp-story/0.1/test/test-amp-story-hint.js
  • extensions/amp-story/0.1/test/test-amp-story-info-dialog.js
  • extensions/amp-story/0.1/test/test-amp-story-request-service.js
  • extensions/amp-story/0.1/test/test-amp-story-share-menu.js
  • extensions/amp-story/0.1/test/test-amp-story-store-service.js
  • extensions/amp-story/0.1/test/test-amp-story-system-layer.js
  • extensions/amp-story/0.1/test/test-amp-story.js
  • extensions/amp-story/0.1/test/test-analytics.js
  • extensions/amp-story/0.1/test/test-media-pool.js
  • extensions/amp-story/0.1/test/test-media-tasks.js
  • extensions/amp-story/0.1/test/test-navigation-state.js
  • extensions/amp-story/1.0/test/test-amp-story-bookend.js
  • extensions/amp-story/1.0/test/test-amp-story-consent.js
  • extensions/amp-story/1.0/test/test-amp-story-embedded-component.js
  • extensions/amp-story/1.0/test/test-amp-story-hint.js
  • extensions/amp-story/1.0/test/test-amp-story-info-dialog.js
  • extensions/amp-story/1.0/test/test-amp-story-media-query-service.js
  • extensions/amp-story/1.0/test/test-amp-story-page.js
  • extensions/amp-story/1.0/test/test-amp-story-request-service.js
  • extensions/amp-story/1.0/test/test-amp-story-share-menu.js
  • extensions/amp-story/1.0/test/test-amp-story-store-service.js
  • extensions/amp-story/1.0/test/test-amp-story-system-layer.js
  • extensions/amp-story/1.0/test/test-amp-story.js
  • extensions/amp-story/1.0/test/test-analytics.js
  • extensions/amp-story/1.0/test/test-full-bleed-animations.js
  • extensions/amp-story/1.0/test/test-live-story-manager.js
  • extensions/amp-story/1.0/test/test-media-performance-metrics-service.js
  • extensions/amp-story/1.0/test/test-media-pool.js
  • extensions/amp-story/1.0/test/test-media-tasks.js

Hey @newmuis, these files were changed:

  • extensions/amp-story/0.1/test/test-amp-story-consent.js
  • extensions/amp-story/0.1/test/test-amp-story-hint.js
  • extensions/amp-story/0.1/test/test-amp-story-info-dialog.js
  • extensions/amp-story/0.1/test/test-amp-story-request-service.js
  • extensions/amp-story/0.1/test/test-amp-story-share-menu.js
  • extensions/amp-story/0.1/test/test-amp-story-store-service.js
  • extensions/amp-story/0.1/test/test-amp-story-system-layer.js
  • extensions/amp-story/0.1/test/test-amp-story.js
  • extensions/amp-story/0.1/test/test-analytics.js
  • extensions/amp-story/0.1/test/test-media-pool.js
  • extensions/amp-story/0.1/test/test-media-tasks.js
  • extensions/amp-story/0.1/test/test-navigation-state.js
  • extensions/amp-story/1.0/test/test-amp-story-bookend.js
  • extensions/amp-story/1.0/test/test-amp-story-consent.js
  • extensions/amp-story/1.0/test/test-amp-story-embedded-component.js
  • extensions/amp-story/1.0/test/test-amp-story-hint.js
  • extensions/amp-story/1.0/test/test-amp-story-info-dialog.js
  • extensions/amp-story/1.0/test/test-amp-story-media-query-service.js
  • extensions/amp-story/1.0/test/test-amp-story-page.js
  • extensions/amp-story/1.0/test/test-amp-story-request-service.js
  • extensions/amp-story/1.0/test/test-amp-story-share-menu.js
  • extensions/amp-story/1.0/test/test-amp-story-store-service.js
  • extensions/amp-story/1.0/test/test-amp-story-system-layer.js
  • extensions/amp-story/1.0/test/test-amp-story.js
  • extensions/amp-story/1.0/test/test-analytics.js
  • extensions/amp-story/1.0/test/test-full-bleed-animations.js
  • extensions/amp-story/1.0/test/test-live-story-manager.js
  • extensions/amp-story/1.0/test/test-media-performance-metrics-service.js
  • extensions/amp-story/1.0/test/test-media-pool.js
  • extensions/amp-story/1.0/test/test-media-tasks.js

@rsimha
Copy link
Contributor Author

rsimha commented Nov 15, 2019

@lannka @jridgewell @choumx At long last, I've managed to get all 10,000+ unit tests to pass on Linux with an upgraded sinon package and zero use of the global sandbox.

While I go through the rest of the test runs to make sure nothing else is broken, can I get you folks to review this? (I'll rebase before merging to resolve any new conflicts.)

@rsimha
Copy link
Contributor Author

rsimha commented Nov 15, 2019

Friday EoD update: The only remaining failures have to do with atob and btoa not being found on Safari on Sauce Labs. I've logged #25621 for this, and got a rough idea of the root cause from @jridgewell. If solving this ends up being outside the scope of this PR, I'll punt and skip the handful of tests on Safari.

/cc @ampproject/wg-runtime

Copy link
Contributor

@lannka lannka left a comment

Choose a reason for hiding this comment

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

Wow, that's a big change. Thanks for handling this. Looked at the description, I think we're on the right route!

@rsimha
Copy link
Contributor Author

rsimha commented Nov 19, 2019

Still blocked by the atob / btoa problem (#25621). Changing atob to self.atob did not work. I've skipped all tests that fail due to this issue on Safari and attempt a separate fix.

@rsimha
Copy link
Contributor Author

rsimha commented Nov 20, 2019

@jridgewell I've managed to get this PR to pass all local and remote tests (modulo the atob / btoa mystery for which I've filed #25621).

Can you give this a once over and let me know if it's good to merge?

@rsimha rsimha merged commit 6b2c20d into ampproject:master Nov 20, 2019
@rsimha rsimha deleted the 2019-11-14-GlobalSinon branch November 20, 2019 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests are failing because they can't find sinon Don't use global sinon sandbox
4 participants