/
capturer-test.js
107 lines (89 loc) · 3.24 KB
/
capturer-test.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
const { noop } = require('lodash');
const { nanoid } = require('nanoid');
const { expect } = require('chai');
const { resolve, dirname, join } = require('path');
const { statSync } = require('fs');
const Capturer = require('../../lib/screenshots/capturer');
const TestRunController = require('../../lib/runner/test-run-controller');
const Screenshots = require('../../lib/screenshots');
const filePath = resolve(process.cwd(), `temp${nanoid(7)}`, 'temp.png');
class CapturerMock extends Capturer {
constructor (provider) {
super(null, void 0, {
id: 'browserId', provider,
});
}
}
class ScreenshotsMock extends Screenshots {
constructor (options) {
super(options);
}
createCapturerFor (test, testIndex, quarantine, connection, warningLog) {
this.capturer = super.createCapturerFor(test, testIndex, quarantine, connection, warningLog);
this.capturer.pathPattern = {
data: {
parsedUserAgent: {
prettyUserAgent: 'user-agent',
},
quarantineAttempt: 1,
},
};
return this.capturer;
}
}
const emptyProvider = {
takeScreenshot: () => {
},
};
describe('Capturer', () => {
it('Taking screenshots does not create a directory if provider does not', async () => {
let errCode = null;
const capturer = new CapturerMock(emptyProvider);
await capturer._takeScreenshot({ filePath });
try {
statSync(dirname(filePath));
}
catch (err) {
errCode = err.code;
}
expect(errCode).eql('ENOENT');
});
it('Screenshot properties for reporter', async () => {
const screenshots = new ScreenshotsMock({
enabled: true,
path: process.cwd(),
pathPattern: '',
fullPage: false,
});
const testRunControllerMock = {
_screenshots: screenshots,
test: { fixture: {} },
emit: noop,
_testRunCtor: function ({ browserConnection }) {
this.id = 'test-run-id';
this.browserConnection = browserConnection;
this.initialize = noop;
},
};
await TestRunController.prototype._createTestRun.call(testRunControllerMock, {
id: 'browser-connection-id',
provider: emptyProvider,
browserInfo: {
parsedUserAgent: {
os: {
name: 'os-name',
},
},
},
});
await screenshots.capturer._capture(false, { customPath: 'screenshot.png' });
expect(screenshots.capturer.testEntry.screenshots[0]).eql({
testRunId: 'test-run-id',
screenshotPath: join(process.cwd(), 'screenshot.png'),
thumbnailPath: join(process.cwd(), 'thumbnails', 'screenshot.png'),
userAgent: 'user-agent',
quarantineAttempt: 1,
takenOnFail: false,
});
});
});