-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathindex.js
42 lines (29 loc) · 1.16 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
import { RequestLogger } from 'testcafe';
const url = 'http://localhost:3000/download-file';
const logger = RequestLogger({ url, method: 'GET' }, {
logResponseHeaders: true,
logResponseBody: true,
stringifyResponseBody: true
});
fixture `Download file`
.page('./index.html')
.requestHooks(logger);
test('Check file name and content', async t => {
const fileNameRegEx = /attachment; filename=.*.txt/;
await t
.click('#download-btn')
.expect(logger.contains(r => {
if (r.response.statusCode !== 200)
return false;
const requestInfo = logger.requests[0];
if (!requestInfo)
return false;
const downloadedFileName = requestInfo.response.headers['content-disposition'];
if (!downloadedFileName)
false;
if (!fileNameRegEx.test(downloadedFileName))
return false;
const downloadedFileContent = logger.requests[0].response.body;
return downloadedFileContent === 'Test content';
})).ok();
});