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

Health: Break 'page.spec.js' to smaller files #2218

Merged
merged 15 commits into from Mar 20, 2018

Conversation

yanivefraim
Copy link
Contributor

Started breaking page.spec.js to some small files, by subject.

@yanivefraim yanivefraim changed the title Health: Break 'page.spec.js' to some files Health: Break 'page.spec.js' to smaller files Mar 17, 2018
*/

module.exports.addTests = function({
describe, xdescribe, fdescribe, it, fit, xit, beforeAll, beforeEach, afterAll, afterEach
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let's pass testrunner here and extract the DSL below. I think it'll look better.

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 (:

describe, xdescribe, fdescribe, it, fit, xit, beforeAll, beforeEach, afterAll, afterEach
}, expect, defaultBrowserOptions, puppeteer, PROJECT_ROOT) {

if (process.env.COVERAGE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd move this into the test.js; it's an infrastructure thing and tightly depends on helper.recordPublicAPICoverage() call.

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

describe, xdescribe, fdescribe, it, fit, xit, beforeAll, beforeEach, afterAll, afterEach
},
expect,
defaultBrowserOptions,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think defaultBrowserOptions and PROJECT_ROOT are not needed for page subtests? Not sure what's the use of puppeteer as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we do use some of them. I removed unnecessary params...

* @param {number=} eventCount
* @return {!Promise<!Object>}
*/
module.exports.waitForEvents = function(emitter, eventName, eventCount = 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

let's call this file utils.js and merge with frame-utils.js.

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. Side note: I like the name driver better than utils 😃

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. driver, and especially test-driver, raises very strong associations in my head with webdriver and chromedriver

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a long discussion 😄

We don't like the name utils, it reminds us of a place you put stuff that you don't know what to do with. On the other hand, we use drivers to put common test stuff + encapsulate test logic / selectors. This way our tests are much more readable (they are written in "english") + they are not aware of selectors / dom implementation. If we change dom implementation, we will change selectors only in one place (and not in all tests). WDYT?

@yanivefraim
Copy link
Contributor Author

yanivefraim commented Mar 19, 2018

@aslushnikov - thanks for the review!

All comments fixed. puppeteer, PROJECT_ROOT and defaultBrowserOptions were still needed in some of the tests. I changed addTests params to be an object, so we can consume only what is needed.

BTW - page.spec.js is now ~2400 lines, instead of ~4100 in old test.js. It is still way too much, but we are in the right direction, I think...

test/utils.js Outdated
@@ -1,5 +1,5 @@
/**
* Copyright 2017 Google Inc. All rights reserved.
* Copyright 2018 Google Inc. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

why's the change?

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 back to 2017

* @param {number=} eventCount
* @return {!Promise<!Object>}
*/
module.exports.waitForEvents = function(emitter, eventName, eventCount = 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. driver, and especially test-driver, raises very strong associations in my head with webdriver and chromedriver

@aslushnikov
Copy link
Contributor

All comments fixed. puppeteer, PROJECT_ROOT and defaultBrowserOptions were still needed in some of the tests. I changed addTests params to be an object, so we can consume only what is needed.

@yanivefraim These look nice

BTW - page.spec.js is now ~2400 lines, instead of ~4100 in old test.js. It is still way too much, but we are in the right direction, I think...

Definitely.

@aslushnikov aslushnikov merged commit 4748196 into puppeteer:master Mar 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants