forked from web-platform-tests/wpt.fyi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-run.js
180 lines (162 loc) · 5.16 KB
/
test-run.js
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* Copyright 2018 The WPT Dashboard Project. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/*
`<test-run>` is a stateless component for displaying the details of a TestRun.
The schema for the testRun property is as follows:
{
"browser_name": "",
"browser_version": "",
"os_name": "",
"os_version": "",
"revision": "", // the first 10 characters of the SHA
"created_at": "", // the date the TestRun was uploaded
}
See models.go for more details.
*/
import '../node_modules/@polymer/paper-tooltip/paper-tooltip.js';
import '../node_modules/@polymer/polymer/lib/elements/dom-if.js';
import { html, PolymerElement } from '../node_modules/@polymer/polymer/polymer-element.js';
import './display-logo.js';
import { ProductInfo } from './product-info.js';
import { WPTFlags } from './wpt-flags.js';
class TestRun extends WPTFlags(ProductInfo(PolymerElement)) {
static get template() {
return html`
<style>
a {
text-decoration: none;
color: #0d5de6;
font-family: monospace;
}
a:hover {
cursor: pointer;
color: #226ff3;
}
.revision {
font-size: 14px;
}
.github {
display: flex;
align-items: center;
justify-content: center;
}
.github img {
margin-right: 8px;
width: 16px;
height: 16px;
}
</style>
<div>
<display-logo product="[[testRun]]"
show-source="[[showSource]]"
show-platform="[[showPlatform]]"
overlap="[[overlap]]"
small="[[small]]">
</display-logo>
<template is="dom-if" if="[[!small]]">
<div>{{displayName(testRun.browser_name)}} {{shortVersion(testRun.browser_name, testRun.browser_version)}}</div>
<template is="dom-if" if="{{ !isDiff(testRun.browser_name) }}">
<div>{{displayName(testRun.os_name)}} {{testRun.os_version}}</div>
<template is="dom-if" if="[[githubCommitLinks]]">
<a class="github" href="https://github.com/web-platform-tests/wpt/commit/[[testRun.revision]]">
<img src="/static/github.svg" alt="GitHub logo">
[[sevenCharSHA(testRun.revision)]]
</a>
</template>
<template is="dom-if" if="[[!githubCommitLinks]]">
<div class="revision">@<a href="?sha={{testRun.revision}}">{{testRun.revision}}</a></div>
</template>
<div>{{dateFormat(testRun.time_start)}}</div>
</template>
</template>
<paper-tooltip offset="0">
<template is="dom-if" if="[[ !isDiff(testRun.browser_name) ]]">
[[displayName(testRun.browser_name)]] [[testRun.browser_version]]<br>
Platform: [[displayName(testRun.os_name)]] [[displaySource(testRun)]]<br>
Labels: [[displayLabels(testRun.labels)]]<br>
Started [[timeFormat(testRun.time_start)]] [[timeTaken(testRun)]]<br>
[[moreTooltip(testRun)]]
</template>
<template is="dom-if" if="[[ isDiff(testRun.browser_name) ]]">
diff numbers are for:<br>
[newly passing] / [newly failing] / [total count delta]
</template>
</paper-tooltip>
</div>
`;
}
static get is() {
return 'test-run';
}
static get properties() {
return {
testRun: {
type: Object,
},
small: {
type: Boolean,
value: false,
},
showSource: {
type: Boolean,
value: false
},
showPlatform: {
type: Boolean,
value: false
},
// Whether to overlap the platform/browser/source icons a little.
overlap: Boolean,
};
}
dateFormat(isoDate) {
return new Date(isoDate).toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
});
}
timeFormat(isoDate) {
const date = new Date(isoDate).toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
});
const time = new Date(isoDate).toLocaleTimeString('en-US', {
hour: 'numeric',
minute: 'numeric',
});
return `${date} at ${time}`;
}
timeTaken(testRun) {
// NOTE: We don't always have a real start/end time.
const hour = 1000*60*60;
const elapsed = new Date(testRun.time_end) - new Date(testRun.time_start);
const oneDP = (elapsed / hour).toFixed(1);
return oneDP < 0.1 ? '' : `(took ${oneDP}h)`;
}
isDiff(browserName) {
return browserName.toLowerCase() === 'diff';
}
moreTooltip(testRun) {
const labels = testRun && testRun.labels || [];
if (testRun.browser_name.startsWith('chrome') && labels.includes('experimental')) {
return 'With --enable-experimental-web-platform-features';
}
if (testRun.browser_name.startsWith('firefox')) {
return 'Using prefs in /testing/profiles/; some experimental features enabled';
}
return '';
}
sevenCharSHA(sha) {
return sha && sha.substr(0, 7);
}
displaySource(testRun) {
const source = this.sourceName(testRun);
return source && `(run on ${source})`;
}
}
window.customElements.define(TestRun.is, TestRun);
export { TestRun };