Skip to content

Commit 2fdde48

Browse files
authored
Faster smoketest. Fix Flaky works-offline gather (#506)
* faster smoketest using a custom config * Network.enable must be called before offline is simulated.
1 parent d960c79 commit 2fdde48

File tree

4 files changed

+68
-15
lines changed

4 files changed

+68
-15
lines changed

lighthouse-cli/scripts/run-smoke-tests.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,36 @@
33
cd lighthouse-cli/test/fixtures && python -m SimpleHTTPServer 9999 &
44

55
NODE=$([ $(node -v | grep -E "v4") ] && echo "node --harmony" || echo "node")
6-
offline200result="URL responds with a 200 when offline"
6+
config="$PWD/lighthouse-cli/test/fixtures/smoketest-config.json"
7+
flags="--config-path=$config"
78

9+
offline200result="URL responds with a 200 when offline"
810

9-
$NODE lighthouse-cli http://localhost:9999/online-only.html > results
11+
$NODE lighthouse-cli $flags http://localhost:9999/online-only.html > results
1012

1113
# test that we have results
1214
if ! grep -q "$offline200result" results; then
1315
echo "Fail! Lighthouse run didn't create a result file"
1416
exit 1
1517
fi
1618

17-
# test that we have a meta viewport defined in the static page
19+
# test that we have a meta viewport defined on a static page
1820
if ! grep -q "HTML has a viewport <meta>: true" results; then
1921
echo "Fail! Meta viewort not detected in the page"
2022
exit 1
2123
fi
2224

23-
# test static page which should fail the offline test
25+
# test a static page which should fail the offline test
2426
if ! grep -q "$offline200result: false" results; then
2527
echo "Fail! online only site worked while offline"
2628
cat results
2729
exit 1
2830
fi
2931

30-
sleep 5s
32+
sleep 1s
3133

3234
# test mojibrush which should pass the offline test
33-
$NODE lighthouse-cli https://www.moji-brush.com > results
35+
$NODE lighthouse-cli $flags https://www.moji-brush.com > results
3436

3537
if ! grep -q "$offline200result: true" results; then
3638
echo "Fail! offline ready site did not work while offline"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"passes": [{
3+
"loadPage": true,
4+
"gatherers": [
5+
"service-worker",
6+
"offline",
7+
"viewport"
8+
]
9+
}],
10+
11+
"audits": [
12+
"service-worker",
13+
"works-offline",
14+
"viewport"
15+
],
16+
17+
"aggregations": [{
18+
"name": "Progressive Web App",
19+
"description": "These audits validate the aspects of a Progressive Web App.",
20+
"scored": true,
21+
"categorizable": true,
22+
"items": [{
23+
"name": "App can load on offline/flaky connections",
24+
"description": "Ensuring your web app can respond when the network connection is unavailable or flaky is critical to providing your users a good experience. This is achieved through use of a <a href=\"https://developers.google.com/web/fundamentals/primers/service-worker/\">Service Worker</a>.",
25+
"criteria": {
26+
"service-worker": {
27+
"rawValue": true,
28+
"weight": 1
29+
},
30+
"works-offline": {
31+
"rawValue": true,
32+
"weight": 1
33+
}
34+
}
35+
}, {
36+
"name": "Design is mobile-friendly",
37+
"description": "Users increasingly experience your app on mobile devices, so it's important to ensure that the experience can adapt to smaller screens.",
38+
"criteria": {
39+
"viewport": {
40+
"rawValue": true,
41+
"weight": 1
42+
}
43+
}
44+
}
45+
]
46+
}]
47+
}

lighthouse-core/driver/gatherers/offline.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,25 @@ const requestPage = function() {
3838

3939
class Offline extends Gather {
4040

41-
static goOffline(driver) {
42-
return driver.sendCommand('Network.emulateNetworkConditions', {
43-
offline: true,
41+
static config(opts) {
42+
return {
43+
offline: opts.offline,
4444
// values of 0 remove any active throttling. crbug.com/456324#c9
4545
latency: 0,
4646
downloadThroughput: 0,
4747
uploadThroughput: 0
48+
};
49+
}
50+
51+
static goOffline(driver) {
52+
// Network.enable must be called for Network.emulateNetworkConditions to work
53+
return driver.sendCommand('Network.enable').then(_ => {
54+
driver.sendCommand('Network.emulateNetworkConditions', Offline.config({offline: true}));
4855
});
4956
}
5057

5158
static goOnline(driver) {
52-
return driver.sendCommand('Network.emulateNetworkConditions', {
53-
offline: false,
54-
latency: 0,
55-
downloadThroughput: 0,
56-
uploadThroughput: 0
57-
});
59+
return driver.sendCommand('Network.emulateNetworkConditions', Offline.config({offline: false}));
5860
}
5961

6062
afterPass(options) {

lighthouse-core/lib/emulation.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ function enableNexus5X(driver) {
7373

7474
return Promise.all([
7575
driver.sendCommand('Emulation.setDeviceMetricsOverride', NEXUS5X_EMULATION_METRICS),
76+
// Network.enable must be called for UA overriding to work
77+
driver.sendCommand('Network.enable'),
7678
driver.sendCommand('Network.setUserAgentOverride', NEXUS5X_USERAGENT),
7779
driver.sendCommand('Emulation.setTouchEmulationEnabled', {
7880
enabled: true,

0 commit comments

Comments
 (0)