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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃彈馃悰 Add a more robust mechanism for dynamically skipping tests #17265

Merged
merged 3 commits into from
Aug 3, 2018
Merged

馃彈馃悰 Add a more robust mechanism for dynamically skipping tests #17265

merged 3 commits into from
Aug 3, 2018

Conversation

rsimha
Copy link
Contributor

@rsimha rsimha commented Aug 2, 2018

There are two issues with mocha's this.skip():

  1. Using it within the body of a beforeEach() block or it() block will cause afterEach() to be skipped (this.skip() is also skipping teardown()/afterEach()聽mochajs/mocha#2148)
  2. It doesn't work when used within a nested describe block (skip doesn't work for nested describes聽mochajs/mocha#2683)

According to https://mochajs.org/#inclusive-tests, the recommended place in which to dynamically skip tests is within a before() block.

This PR does the following:

  • Introduces this.skipTest(), a more robust version of this.skip() that...
    • makes sure it is being used within a before() block
    • works within nested describe blocks
  • Forbids the use of this.skip() within tests, and recommends the use of this.skipTest() instead

With this, dirty global state due to inadvertent skipping of afterEach() should no longer be a problem.

Fixes #17245
Partial fix for #14360

@rsimha
Copy link
Contributor Author

rsimha commented Aug 2, 2018

@codecov-io
Copy link

codecov-io commented Aug 2, 2018

Codecov Report

Merging #17265 into master will decrease coverage by <.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master   #17265      +/-   ##
==========================================
- Coverage   77.73%   77.73%   -0.01%     
==========================================
  Files         564      564              
  Lines       41217    41217              
==========================================
- Hits        32041    32040       -1     
- Misses       9176     9177       +1
Flag Coverage 螖
#integration_tests 36.11% <酶> (酶) 猬嗭笍
#unit_tests 76.79% <酶> (-0.01%) 猬囷笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 128265d...45ea75d. Read the comment docs.

if (this._runnable.title != '"before all" hook') {
throw new Error('skipTest() can only be called from within before()');
}
this.test.parent.pending = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this?

Copy link
Contributor Author

@rsimha rsimha Aug 3, 2018

Choose a reason for hiding this comment

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

Workaround for mochajs/mocha#2683. Comment added.

doc.body.appendChild(container);
});
// Can only test when SD is supported.
describe.configure().ifChrome('shadow transfer', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is Safari, too. You can use generic if:

describe.configure().if(() => Element.prototype.attachShadow)

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.

@@ -438,293 +438,292 @@ describes.realWin('ViewportBindingIosEmbedWrapper', {ampCss: true}, env => {
});
});

describes.realWin('ViewportBindingIosEmbedShadowRoot_', {ampCss: true}, env => {
describes.realWin('ViewportBindingIos', {ampCss: true}, env => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use the old name. We have multiple iOS bindings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted.

return whenDocumentReady(win.document).then(() => {
expect(root).to.have.class('i-amphtml-ios-overscroll');
// Can only test when SD is supported.
describe.configure().ifChrome('EmbedShadowRoot_', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Safari also has attachShadow. Also, it's a Safari specific test suite. 馃槈

Copy link
Contributor Author

@rsimha rsimha Aug 3, 2018

Choose a reason for hiding this comment

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

Good catch. Fixed.

@rsimha
Copy link
Contributor Author

rsimha commented Aug 3, 2018

@jridgewell PTAL.

expect(root).to.have.class('i-amphtml-ios-overscroll');
// Can only test when SD is supported.
describe.configure().if(() => Element.prototype.attachShadow).run('Viewport' +
'BindingIosEmbedShadowRoot_', function() {

Choose a reason for hiding this comment

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

Nit: 'Shadow DOM available'

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.

doc.body.appendChild(container);
});
// Can only test when SD is supported.
describe.configure().if(() => Element.prototype.attachShadow).run('shadow ' +

Choose a reason for hiding this comment

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

Note that this now checks whether shadow DOM is supported in the test runner window rather than the "realWin".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given that this is a nested describe within a describes.realWin, will it not have the same effect? (From actually running the test, It seemed to me that we do have the desired skipping behavior.)

Choose a reason for hiding this comment

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

Most likely fine unless we want to do something weird in describes later.

'this\\.skip\\(\\)': {
message: 'Use of `this.skip()` is forbidden. Use `this.skipTest()` ' +
'from within a `before()` block instead. See #17245.',
checkInTestFolder: true,

Choose a reason for hiding this comment

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

Does this only match tests or also source files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It matches all files, but there are no instances of this.skip() in source files. I've updated the error message to be more clear.

@rsimha rsimha merged commit 179dd2e into ampproject:master Aug 3, 2018
@rsimha rsimha deleted the 2018-08-02-Skip branch August 3, 2018 18:12
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.

Fix usage of this.skip() within tests
5 participants