|
6 | 6 | 'use strict'; |
7 | 7 |
|
8 | 8 | const FastPWAAudit = require('../../audits/load-fast-enough-for-pwa'); |
| 9 | +const Runner = require('../../runner.js'); |
9 | 10 | const Audit = require('../../audits/audit.js'); |
| 11 | +const mobile3GThrottling = require('../../config/constants').throttling.mobile3G; |
10 | 12 | const assert = require('assert'); |
11 | 13 |
|
12 | | -function generateArtifacts(firstInteractiveValue, networkRecords = []) { |
| 14 | +const trace = require('../fixtures/traces/progressive-app-m60.json'); |
| 15 | +const devtoolsLog = require('../fixtures/traces/progressive-app-m60.devtools.log.json'); |
| 16 | + |
| 17 | +function generateArtifacts(ttiValue) { |
13 | 18 | return { |
14 | 19 | devtoolsLogs: { |
15 | 20 | [Audit.DEFAULT_PASS]: [], |
16 | 21 | }, |
17 | | - requestNetworkRecords: () => { |
18 | | - return Promise.resolve(networkRecords); |
19 | | - }, |
20 | 22 | traces: { |
21 | 23 | [Audit.DEFAULT_PASS]: {traceEvents: []}, |
22 | 24 | }, |
23 | | - requestFirstInteractive: () => Promise.resolve({ |
24 | | - timeInMs: firstInteractiveValue, |
| 25 | + requestConsistentlyInteractive: () => Promise.resolve({ |
| 26 | + timing: ttiValue, |
25 | 27 | }), |
26 | 28 | }; |
27 | 29 | } |
28 | 30 |
|
29 | 31 | /* eslint-env mocha */ |
30 | 32 | describe('PWA: load-fast-enough-for-pwa audit', () => { |
31 | 33 | it('returns boolean based on TTI value', () => { |
32 | | - return FastPWAAudit.audit(generateArtifacts(5000)).then(result => { |
33 | | - assert.equal(result.rawValue, true, 'fixture trace is not passing audit'); |
| 34 | + const settings = {throttlingMethod: 'devtools', throttling: mobile3GThrottling}; |
| 35 | + return FastPWAAudit.audit(generateArtifacts(5000), {settings}).then(result => { |
| 36 | + assert.equal(result.score, true, 'fixture trace is not passing audit'); |
| 37 | + assert.equal(result.rawValue, 5000); |
34 | 38 | }); |
35 | 39 | }); |
36 | 40 |
|
37 | 41 | it('fails a bad TTI value', () => { |
38 | | - return FastPWAAudit.audit(generateArtifacts(15000)).then(result => { |
39 | | - assert.equal(result.rawValue, false, 'not failing a long TTI value'); |
| 42 | + const settings = {throttlingMethod: 'devtools', throttling: mobile3GThrottling}; |
| 43 | + return FastPWAAudit.audit(generateArtifacts(15000), {settings}).then(result => { |
| 44 | + assert.equal(result.score, false, 'not failing a long TTI value'); |
| 45 | + assert.equal(result.rawValue, 15000); |
40 | 46 | assert.ok(result.debugString); |
41 | 47 | }); |
42 | 48 | }); |
43 | 49 |
|
44 | | - it('warns on a good TTI value with no throttling', () => { |
45 | | - // latencies are very short |
46 | | - const mockNetworkRecords = [ |
47 | | - {_timing: {sendEnd: 0, receiveHeadersEnd: 50}, finished: true, _url: 'https://google.com/'}, |
48 | | - {_timing: {sendEnd: 0, receiveHeadersEnd: 75}, finished: true, _url: 'https://google.com/a'}, |
49 | | - { }, |
50 | | - {_timing: {sendEnd: 0, receiveHeadersEnd: 50}, finished: true, _url: 'https://google.com/b'}, |
51 | | - ]; |
52 | | - return FastPWAAudit.audit(generateArtifacts(5000, mockNetworkRecords)).then(result => { |
53 | | - assert.equal(result.rawValue, true); |
54 | | - assert.ok(result.debugString.includes('network request latencies')); |
55 | | - assert.ok(result.details, 'contains details when latencies were not realistic'); |
56 | | - }); |
57 | | - }); |
| 50 | + it('respects the observed result when throttling is preset', async () => { |
| 51 | + const artifacts = Object.assign({ |
| 52 | + traces: {defaultPass: trace}, |
| 53 | + devtoolsLogs: {defaultPass: devtoolsLog}, |
| 54 | + }, Runner.instantiateComputedArtifacts()); |
58 | 55 |
|
59 | | - it('ignores resources coming from cache', () => { |
60 | | - const mockNetworkRecords = [ |
61 | | - {_timing: {sendEnd: 0, receiveHeadersEnd: 50}, _fromDiskCache: true}, |
62 | | - ]; |
63 | | - return FastPWAAudit.audit(generateArtifacts(5000, mockNetworkRecords)).then(result => { |
64 | | - assert.equal(result.rawValue, true); |
65 | | - assert.strictEqual(result.debugString, undefined); |
66 | | - }); |
| 56 | + const settings = {throttlingMethod: 'devtools', throttling: mobile3GThrottling}; |
| 57 | + const result = await FastPWAAudit.audit(artifacts, {settings}); |
| 58 | + assert.equal(Math.round(result.rawValue), 1582); |
67 | 59 | }); |
68 | 60 |
|
69 | | - it('passes a good TTI value and WITH throttling', () => { |
70 | | - // latencies are very long |
71 | | - const urlA = 'https://google.com'; |
72 | | - const urlB = 'https://example.com'; |
73 | | - const urlC = 'https://example-c.com'; |
74 | | - const mockNetworkRecords = [ |
75 | | - {_timing: {sendEnd: 0, receiveHeadersEnd: 250}, finished: true, _url: urlA, _startTime: 0}, |
76 | | - {_timing: {sendEnd: 0, receiveHeadersEnd: 250}, finished: true, _url: urlB}, |
77 | | - // ignored for not having timing |
78 | | - { }, |
79 | | - // ignored for not being the first of the origin |
80 | | - {_timing: {sendEnd: 0, receiveHeadersEnd: 100}, finished: true, _url: urlA, _startTime: 100}, |
81 | | - // ignored for being redirected internally |
82 | | - {_timing: {sendEnd: 0, receiveHeadersEnd: 100}, finished: true, _url: urlC, _startTime: 0, |
83 | | - statusCode: 307}, |
84 | | - // ignored for not finishing |
85 | | - {_timing: {sendEnd: 0, receiveHeadersEnd: -1}, finished: false}, |
86 | | - ]; |
87 | | - return FastPWAAudit.audit(generateArtifacts(5000, mockNetworkRecords)).then(result => { |
88 | | - assert.equal(result.rawValue, true); |
89 | | - assert.strictEqual(result.debugString, undefined); |
90 | | - assert.ok(!result.details, 'does not contain details when latencies are realistic'); |
91 | | - }); |
| 61 | + it('overrides with simulated result when throttling is modified', async () => { |
| 62 | + const artifacts = Object.assign({ |
| 63 | + traces: {defaultPass: trace}, |
| 64 | + devtoolsLogs: {defaultPass: devtoolsLog}, |
| 65 | + }, Runner.instantiateComputedArtifacts()); |
| 66 | + |
| 67 | + const settings = {throttlingMethod: 'provided', throttling: {rttMs: 40, throughput: 100000}}; |
| 68 | + const result = await FastPWAAudit.audit(artifacts, {settings}); |
| 69 | + assert.equal(Math.round(result.rawValue), 5308); |
92 | 70 | }); |
93 | 71 | }); |
0 commit comments