-
Notifications
You must be signed in to change notification settings - Fork 659
/
index.js
79 lines (61 loc) · 2.32 KB
/
index.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
import { find } from 'lodash';
import moment from 'moment';
import Capturer from './capturer';
import PathPattern from '../utils/path-pattern';
import getCommonPath from '../utils/get-common-path';
const SCREENSHOT_EXTENSION = 'png';
export default class Screenshots {
constructor ({ enabled, path, pathPattern, fullPage }) {
this.enabled = enabled;
this.screenshotsPath = path;
this.screenshotsPattern = pathPattern;
this.fullPage = fullPage;
this.testEntries = [];
this.now = moment();
}
_addTestEntry (test) {
const testEntry = {
test: test,
testRuns: {},
screenshots: []
};
this.testEntries.push(testEntry);
return testEntry;
}
_getTestEntry (test) {
return find(this.testEntries, entry => entry.test === test);
}
_ensureTestEntry (test) {
let testEntry = this._getTestEntry(test);
if (!testEntry)
testEntry = this._addTestEntry(test);
return testEntry;
}
getScreenshotsInfo (test) {
return this._getTestEntry(test).screenshots;
}
hasCapturedFor (test) {
return this.getScreenshotsInfo(test).length > 0;
}
getPathFor (test) {
const testEntry = this._getTestEntry(test);
const screenshotPaths = testEntry.screenshots.map(screenshot => screenshot.screenshotPath);
return getCommonPath(screenshotPaths);
}
createCapturerFor (test, testIndex, quarantine, connection, warningLog) {
const testEntry = this._ensureTestEntry(test);
const pathPattern = new PathPattern(this.screenshotsPattern, SCREENSHOT_EXTENSION, {
testIndex,
quarantineAttempt: quarantine ? quarantine.getNextAttemptNumber() : null,
now: this.now,
fixture: test.fixture.name,
test: test.name,
parsedUserAgent: connection.browserInfo.parsedUserAgent,
});
return new Capturer(this.screenshotsPath, testEntry, connection, pathPattern, this.fullPage, warningLog);
}
addTestRun (test, testRun) {
const testEntry = this._getTestEntry(test);
testEntry.testRuns[testRun.browserConnection.id] = testRun;
}
}