-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extension(popup): integration test for popup (#5412)
- Loading branch information
1 parent
8f23052
commit ac264c0
Showing
3 changed files
with
100 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* @license Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
/* eslint-env mocha */ | ||
|
||
const path = require('path'); | ||
const assert = require('assert'); | ||
const puppeteer = require('../../node_modules/puppeteer/index.js'); | ||
|
||
const lighthouseExtensionPath = path.resolve(__dirname, '../dist'); | ||
|
||
describe('Lighthouse chrome popup', function() { | ||
// eslint-disable-next-line no-console | ||
console.log('\n✨ Be sure to have recently run this: yarn build-extension'); | ||
|
||
let browser; | ||
let page; | ||
const pageErrors = []; | ||
|
||
before(async function() { | ||
// eslint-disable-next-line | ||
this.timeout(90 * 1000); | ||
|
||
// start puppeteer | ||
browser = await puppeteer.launch({ | ||
headless: false, | ||
executablePath: process.env.CHROME_PATH, | ||
}); | ||
|
||
page = await browser.newPage(); | ||
await page.evaluateOnNewDocument(() => { | ||
const backgroundMock = { | ||
isRunning: () => false, | ||
listenForStatus: () => {}, | ||
loadSettings: () => Promise.resolve({ | ||
selectedCategories: [], | ||
useDevTools: false, | ||
}), | ||
getDefaultCategories: () => [], | ||
}; | ||
|
||
Object.defineProperty(chrome, 'tabs', { | ||
get: () => ({ | ||
query: (args, cb) => { | ||
cb([{ | ||
url: 'http://example.com', | ||
}]); | ||
}, | ||
}), | ||
}); | ||
Object.defineProperty(chrome, 'runtime', { | ||
get: () => ({ | ||
getBackgroundPage: cb => { | ||
cb(backgroundMock); | ||
}, | ||
}), | ||
}); | ||
}); | ||
|
||
page.on('pageerror', err => { | ||
pageErrors.push(err); | ||
}); | ||
|
||
await page.goto('file://' + path.join(lighthouseExtensionPath, 'popup.html'), {waitUntil: 'networkidle2'}); | ||
}); | ||
|
||
after(async () => { | ||
if (browser) { | ||
await browser.close(); | ||
} | ||
}); | ||
|
||
it('should load without errors', async function() { | ||
assert.equal(pageErrors.length, 0); | ||
}); | ||
|
||
it('should load the popup with an url', async () => { | ||
const titleText = await page.evaluate(() => | ||
document.querySelector('.header-titles__main').textContent); | ||
const urlText = await page.evaluate(() => | ||
document.querySelector('.header-titles__url').textContent); | ||
|
||
// check if the popup is showing the lighthouse page | ||
const subPageIsVisible = await page.evaluate(() => | ||
document.querySelector('.status').classList.contains('subpage--visible')); | ||
|
||
assert.ok(!subPageIsVisible, 'Popup is stuck on the splash screen'); | ||
assert.equal(titleText, 'Lighthouse'); | ||
assert.equal(urlText, 'http://example.com'); | ||
}); | ||
}); |