-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Expand file tree
/
Copy pathcrc-details-renderer-test.js
More file actions
109 lines (99 loc) · 3.57 KB
/
crc-details-renderer-test.js
File metadata and controls
109 lines (99 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* @license Copyright 2017 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 jest */
const assert = require('assert');
const fs = require('fs');
const jsdom = require('jsdom');
const URL = require('../../../../lib/url-shim.js');
const Util = require('../../../../report/html/renderer/util.js');
const DOM = require('../../../../report/html/renderer/dom.js');
const CriticalRequestChainRenderer =
require('../../../../report/html/renderer/crc-details-renderer.js');
const TEMPLATE_FILE = fs.readFileSync(__dirname +
'/../../../../report/html/templates.html', 'utf8');
const superLongURL =
'https://example.com/thisIsASuperLongURLThatWillTriggerFilenameTruncationWhichWeWantToTest.js';
const DETAILS = {
type: 'criticalrequestchain',
chains: {
0: {
request: {
endTime: 1,
responseReceivedTime: 5,
startTime: 0,
url: 'https://example.com/',
transferSize: 1000,
},
children: {
1: {
request: {
endTime: 16,
responseReceivedTime: 14,
startTime: 11,
url: 'https://example.com/b.js',
transferSize: 2000,
},
children: {},
},
2: {
request: {
endTime: 17.123456789,
responseReceivedTime: 15,
startTime: 12,
url: superLongURL,
transferSize: 3000,
},
children: {},
},
3: {
request: {
endTime: 18,
responseReceivedTime: 16,
startTime: 13,
url: 'about:blank',
transferSize: 4000,
},
children: {},
},
},
},
},
longestChain: {
duration: 7000,
length: 2,
transferSize: 1,
},
};
describe('DetailsRenderer', () => {
let dom;
beforeAll(() => {
global.URL = URL;
global.Util = Util;
const {document} = new jsdom.JSDOM(TEMPLATE_FILE).window;
dom = new DOM(document);
});
afterAll(() => {
global.URL = undefined;
global.Util = undefined;
});
it('renders tree structure', () => {
const el = CriticalRequestChainRenderer.render(dom, dom.document(), DETAILS);
const chains = el.querySelectorAll('.crc-node');
// Main request
assert.equal(chains.length, 4, 'generates correct number of chain nodes');
assert.equal(chains[0].querySelector('.lh-text__url-host').textContent, '(example.com)');
// Children
assert.ok(chains[1].querySelector('.crc-node__tree-marker .vert-right'));
assert.equal(chains[1].querySelectorAll('.crc-node__tree-marker .right').length, 2);
assert.equal(chains[1].querySelector('.lh-text__url a').textContent, '/b.js');
assert.equal(chains[1].querySelector('.lh-text__url-host').textContent, '(example.com)');
const durationNodes = chains[1].querySelectorAll('.crc-node__chain-duration');
assert.equal(durationNodes[0].textContent, ' - 5,000\xa0ms, ');
// Note: actual transferSize is 2000 bytes but formatter formats to KBs.
assert.equal(durationNodes[1].textContent, '1.95\xa0KB');
});
});