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

tests: use test-specific about:blank timer #1674

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ class GatherRunner {
* reload. We do not `waitForLoad` on about:blank since a page load event is
* never fired on it.
* @param {!Driver} driver
* @param {integer=} waitForLoadMs
* @return {!Promise}
*/
static loadBlank(driver) {
static loadBlank(driver, waitForLoadMs = 300) {
return driver.gotoURL('about:blank')
.then(_ => new Promise((resolve, reject) => setTimeout(resolve, 300)));
.then(_ => new Promise((resolve, reject) => setTimeout(resolve, waitForLoadMs)));
}

/**
Expand Down Expand Up @@ -153,7 +154,7 @@ class GatherRunner {
* @return {!Promise}
*/
static beforePass(options, gathererResults) {
const pass = GatherRunner.loadBlank(options.driver);
const pass = GatherRunner.loadBlank(options.driver, options._aboutBlankTimeout);

return options.config.gatherers.reduce((chain, gatherer) => {
return chain.then(_ => {
Expand Down Expand Up @@ -315,7 +316,7 @@ class GatherRunner {
const gathererResults = {};

return driver.connect()
.then(_ => GatherRunner.loadBlank(driver))
.then(_ => GatherRunner.loadBlank(driver, options._aboutBlankTimeout))
.then(_ => GatherRunner.setupDriver(driver, options))

// Run each pass
Expand Down
29 changes: 19 additions & 10 deletions lighthouse-core/test/gather/gather-runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('GatherRunner', function() {
const url = 'https://example.com';
const driver = fakeDriver;
const config = new Config({});
const options = {url, driver, config};
const options = {url, driver, config, _aboutBlankTimeout: 0};

return GatherRunner.run([], options).then(_ => {
assert.equal(typeof options.flags, 'object');
Expand Down Expand Up @@ -384,7 +384,8 @@ describe('GatherRunner', function() {
driver: fakeDriver,
url: 'https://example.com',
flags,
config
config,
_aboutBlankTimeout: 0
}).then(_ => {
assert.ok(t1.called);
assert.ok(t2.called);
Expand All @@ -403,7 +404,8 @@ describe('GatherRunner', function() {
passName: 'secondPass',
gatherers: [new TestGatherer()]
}];
const options = {driver: fakeDriver, url: 'https://example.com', flags: {}, config: {}};
const options = {driver: fakeDriver, url: 'https://example.com', flags: {}, config: {},
_aboutBlankTimeout: 0};

return GatherRunner.run(passes, options)
.then(artifacts => {
Expand Down Expand Up @@ -496,7 +498,8 @@ describe('GatherRunner', function() {
passName: 'firstPass',
gatherers: [new TestGatherer()]
}];
const options = {driver: fakeDriver, url: 'https://example.com', flags: {}, config: {}};
const options = {driver: fakeDriver, url: 'https://example.com', flags: {}, config: {},
_aboutBlankTimeout: 0};

return GatherRunner.run(passes, options)
.then(artifacts => {
Expand Down Expand Up @@ -581,7 +584,8 @@ describe('GatherRunner', function() {
driver: fakeDriver,
url: 'https://example.com',
flags: {},
config: new Config({})
config: new Config({}),
_aboutBlankTimeout: 0
}).then(artifacts => {
gathererNames.forEach(gathererName => {
assert.strictEqual(artifacts[gathererName], gathererName);
Expand Down Expand Up @@ -680,7 +684,8 @@ describe('GatherRunner', function() {
driver: fakeDriver,
url: 'https://example.com',
flags: {},
config: new Config({})
config: new Config({}),
_aboutBlankTimeout: 0
}).then(artifacts => {
gathererNames.forEach(gathererName => {
const errorArtifact = artifacts[gathererName];
Expand Down Expand Up @@ -715,7 +720,8 @@ describe('GatherRunner', function() {
driver: fakeDriver,
url: 'https://example.com',
flags: {},
config: new Config({})
config: new Config({}),
_aboutBlankTimeout: 0
}).then(
_ => assert.ok(false),
err => assert.strictEqual(err.message, errorMessage));
Expand All @@ -735,7 +741,8 @@ describe('GatherRunner', function() {
driver: fakeDriver,
url: 'https://example.com',
flags: {},
config: new Config({})
config: new Config({}),
_aboutBlankTimeout: 0
}).then(_ => assert.ok(false), _ => assert.ok(true));
});

Expand All @@ -759,7 +766,8 @@ describe('GatherRunner', function() {
driver: unresolvedDriver,
url: 'http://www.some-non-existing-domain.com/',
flags: {},
config: new Config({})
config: new Config({}),
_aboutBlankTimeout: 0
})
.then(_ => {
assert.ok(false);
Expand Down Expand Up @@ -789,7 +797,8 @@ describe('GatherRunner', function() {
driver: unresolvedDriver,
url: 'http://www.some-non-existing-domain.com/',
flags: {},
config: new Config({})
config: new Config({}),
_aboutBlankTimeout: 0
})
.then(_ => {
assert.ok(true);
Expand Down